Skip to content

Commit

Permalink
symbolizer: reduce the number of debuginfo copies
Browse files Browse the repository at this point in the history
  • Loading branch information
danipozo committed Nov 27, 2024
1 parent f030ee1 commit 4762250
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions pkg/symbolizer/symbolizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,34 +203,39 @@ func (s *Symbolizer) getDebuginfo(ctx context.Context, buildID string) (string,
return "", nil, nil, debuginfo.ErrUnknownDebuginfoSource
}

// Fetch the debug info for the build ID.
rc, err := s.debuginfo.FetchDebuginfo(ctx, dbginfo)
if err != nil {
return "", nil, nil, fmt.Errorf("fetch debuginfo (BuildID: %q): %w", buildID, err)
}
defer rc.Close()

f, err := os.CreateTemp(s.tmpDir, "parca-symbolizer-*")
if err != nil {
return "", nil, nil, fmt.Errorf("create temp file: %w", err)
}
defer func() {
f.Close()
os.Remove(f.Name())
}()

if _, err := io.Copy(f, rc); err != nil {
return "", nil, nil, fmt.Errorf("copy debuginfo to temp file: %w", err)
}

if err := f.Close(); err != nil {
return "", nil, nil, fmt.Errorf("close temp file: %w", err)
}

targetPath := filepath.Join(s.tmpDir, buildID)
if err := os.Rename(f.Name(), targetPath); err != nil {
return "", nil, nil, fmt.Errorf("rename temp file: %w", err)
}
if _, err := os.Stat(targetPath); errors.Is(err, os.ErrNotExist) {
// Fetch the debug info for the build ID.
rc, err := s.debuginfo.FetchDebuginfo(ctx, dbginfo)
if err != nil {
return "", nil, nil, fmt.Errorf("fetch debuginfo (BuildID: %q): %w", buildID, err)
}
defer rc.Close()

f, err := os.CreateTemp(s.tmpDir, "parca-symbolizer-*")

if err != nil {
return "", nil, nil, fmt.Errorf("create temp file: %w", err)
}

fmt.Printf("Copying %s to tmp file %s\n", buildID, f.Name())
defer func() {
f.Close()
os.Remove(f.Name())
}()

if _, err := io.Copy(f, rc); err != nil {
return "", nil, nil, fmt.Errorf("copy debuginfo to temp file: %w", err)
}

if err := f.Close(); err != nil {
return "", nil, nil, fmt.Errorf("close temp file: %w", err)
}

if err := os.Rename(f.Name(), targetPath); err != nil {
return "", nil, nil, fmt.Errorf("rename temp file: %w", err)
}
}

e, err := elf.Open(targetPath)
if err != nil {
Expand Down

0 comments on commit 4762250

Please sign in to comment.