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 Dec 9, 2024
1 parent f030ee1 commit a2198b8
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions pkg/symbolizer/symbolizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,33 +203,38 @@ 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()
targetPath := filepath.Join(s.tmpDir, buildID)
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)
}
defer func() {
f.Close()
os.Remove(f.Name())
}()
f, err := os.CreateTemp(s.tmpDir, "parca-symbolizer-*")

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

if err := f.Close(); err != nil {
return "", nil, nil, fmt.Errorf("close temp file: %w", err)
}
level.Debug(s.logger).Log("msg", fmt.Sprintf("Copying %s to tmp file %s\n", buildID, f.Name()))
defer func() {
f.Close()
os.Remove(f.Name())
}()

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 := 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)
Expand Down

0 comments on commit a2198b8

Please sign in to comment.