Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symbolizer: reduce the number of debuginfo copies #5330

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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