Skip to content

Commit

Permalink
Add additional frame with executable path when available
Browse files Browse the repository at this point in the history
  • Loading branch information
Gandem committed Jun 11, 2024
1 parent 714a34c commit 7ee4e58
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion processmanager/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (pm *ProcessManager) getELFInfo(pr process.Process, mapping *process.Mappin
buildID, _ = ef.GetGoBuildID()
}

pm.reporter.ExecutableMetadata(context.TODO(), fileID, baseName, buildID)
pm.reporter.ExecutableMetadata(context.TODO(), fileID, baseName, mapping.Path, buildID)

return info
}
Expand Down
17 changes: 16 additions & 1 deletion reporter/datadog_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ func (r *DatadogReporter) ReportFallbackSymbol(frameID libpf.FrameID, symbol str
// ExecutableMetadata accepts a fileID with the corresponding filename
// and caches this information.
func (r *DatadogReporter) ExecutableMetadata(_ context.Context,
fileID libpf.FileID, fileName, buildID string) {
fileID libpf.FileID, fileName, filePath string, buildID string) {
r.executables.Add(fileID, execInfo{
fileName: fileName,
filePath: filePath,
buildID: buildID,
})
}
Expand Down Expand Up @@ -414,6 +415,8 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile,
}
}

var lastExecPath string

// Walk every frame of the trace.
for i := range trace.frameTypes {
loc := createPProfLocation(profile, uint64(trace.linenos[i]))
Expand Down Expand Up @@ -508,6 +511,18 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile,
// To be compliant with the protocol generate a dummy mapping entry.
loc.Mapping = getDummyMapping(fileIDtoMapping, profile, trace.files[i])
}
execInfo, exists := r.executables.Get(trace.files[i])

Check failure on line 514 in reporter/datadog_reporter.go

View workflow job for this annotation

GitHub Actions / Lint (stable)

shadow: declaration of "execInfo" shadows declaration at line 53 (govet)
if exists {
lastExecPath = execInfo.filePath
}
sample.Location = append(sample.Location, loc)
}

if lastExecPath != "" {
lastLocation := sample.Location[len(sample.Location)-1]
loc := createPProfLocation(profile, lastLocation.Address)
m := createPprofFunctionEntry(funcMap, profile, lastExecPath, lastExecPath)
loc.Line = append(loc.Line, pprofile.Line{Function: m})
sample.Location = append(sample.Location, loc)
}

Expand Down
2 changes: 1 addition & 1 deletion reporter/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type SymbolReporter interface {

// ExecutableMetadata accepts a fileID with the corresponding filename
// and caches this information before a periodic reporting to the backend.
ExecutableMetadata(ctx context.Context, fileID libpf.FileID, fileName, buildID string)
ExecutableMetadata(ctx context.Context, fileID libpf.FileID, fileName, filePath, buildID string)

// FrameMetadata accepts metadata associated with a frame and caches this information before
// a periodic reporting to the backend.
Expand Down
4 changes: 3 additions & 1 deletion reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type sample struct {
// execInfo enriches an executable with additional metadata.
type execInfo struct {
fileName string
filePath string
buildID string
}

Expand Down Expand Up @@ -179,9 +180,10 @@ func (r *OTLPReporter) ReportFallbackSymbol(frameID libpf.FrameID, symbol string
// ExecutableMetadata accepts a fileID with the corresponding filename
// and caches this information.
func (r *OTLPReporter) ExecutableMetadata(_ context.Context,
fileID libpf.FileID, fileName, buildID string) {
fileID libpf.FileID, fileName, filePath, buildID string) {
r.executables.Add(fileID, execInfo{
fileName: fileName,
filePath: filePath,
buildID: buildID,
})
}
Expand Down
2 changes: 1 addition & 1 deletion reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type executableMetadata struct {

// ExecutableMetadata implements the SymbolReporter interface.
func (r *GRPCReporter) ExecutableMetadata(ctx context.Context, fileID libpf.FileID,
fileName, buildID string) {
fileName, filePath, buildID string) {

Check failure on line 114 in reporter/reporter.go

View workflow job for this annotation

GitHub Actions / Lint (stable)

unused-parameter: parameter 'filePath' seems to be unused, consider removing or renaming it as _ (revive)
select {
case <-ctx.Done():
return
Expand Down
2 changes: 1 addition & 1 deletion tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func processKernelModulesMetadata(ctx context.Context,
if err == nil && len(buildID) >= 16 {
fileID = pfelf.CalculateKernelFileID(buildID)
result[nameStr] = fileID
rep.ExecutableMetadata(ctx, fileID, nameStr, buildID)
rep.ExecutableMetadata(ctx, fileID, nameStr, "kernel", buildID)
} else {
log.Errorf("Failed to get GNU BuildID for kernel module %s: '%s' (%v)",
nameStr, buildID, err)
Expand Down

0 comments on commit 7ee4e58

Please sign in to comment.