From 7ed461728f3596bb98e89331c3f71560a833bb57 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Tue, 11 Jun 2024 14:09:40 +0000 Subject: [PATCH] wip --- libpf/pfelf/file.go | 5 +++++ processmanager/processinfo.go | 6 +++++- reporter/datadog_reporter.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libpf/pfelf/file.go b/libpf/pfelf/file.go index 30ab927..946e6bf 100644 --- a/libpf/pfelf/file.go +++ b/libpf/pfelf/file.go @@ -486,6 +486,11 @@ func (f *File) GetGoBuildID() (string, error) { return getGoBuildIDFromNotes(data) } +// IsExecutable returns whether the ELF is executable +func (f *File) IsExecutable() bool { + return elf.Type(f.elfHeader.Type) == elf.ET_EXEC +} + // GetBuildID returns the ELF BuildID if present func (f *File) GetBuildID() (string, error) { s := f.Section(".note.gnu.build-id") diff --git a/processmanager/processinfo.go b/processmanager/processinfo.go index db3aab0..a2d810e 100644 --- a/processmanager/processinfo.go +++ b/processmanager/processinfo.go @@ -319,7 +319,11 @@ func (pm *ProcessManager) getELFInfo(pr process.Process, mapping *process.Mappin buildID, _ = ef.GetGoBuildID() } - pm.reporter.ExecutableMetadata(context.TODO(), fileID, baseName, mapping.Path, buildID) + execPath := "" + if ef.IsExecutable() { + execPath = mapping.Path + } + pm.reporter.ExecutableMetadata(context.TODO(), fileID, baseName, execPath, buildID) return info } diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index b8ab9d2..cb06784 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -512,7 +512,7 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile, loc.Mapping = getDummyMapping(fileIDtoMapping, profile, trace.files[i]) } execInfo, exists := r.executables.Get(trace.files[i]) - if exists { + if exists && execInfo.filePath != "" { lastExecPath = execInfo.filePath } sample.Location = append(sample.Location, loc)