Skip to content

Commit

Permalink
properly apply changes from open-telemetry#256
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Nov 29, 2024
1 parent 8210f2c commit 13e046c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions reporter/internal/pdata/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/rand"
"slices"
"strconv"
"time"

log "github.com/sirupsen/logrus"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand All @@ -17,6 +18,11 @@ import (
"go.opentelemetry.io/ebpf-profiler/reporter/internal/samples"
)

const (
ExecutableCacheLifetime = 1 * time.Hour
FramesCacheLifetime = 1 * time.Hour
)

// Generate generates a pdata request out of internal profiles data, to be
// exported.
func (p Pdata) Generate(events map[samples.TraceAndMetaKey]*samples.TraceEvents) pprofile.Profiles {
Expand Down Expand Up @@ -111,7 +117,8 @@ func (p *Pdata) setProfile(
fileIDtoMapping[traceInfo.Files[i]] = idx
locationMappingIndex = idx

ei, exists := p.Executables.GetAndRefresh(traceInfo.Files[i], ...)
ei, exists := p.Executables.GetAndRefresh(traceInfo.Files[i],
ExecutableCacheLifetime)

// Next step: Select a proper default value,
// if the name of the executable is not known yet.
Expand Down Expand Up @@ -150,7 +157,8 @@ func (p *Pdata) setProfile(
// Store interpreted frame information as a Line message:
line := loc.Line().AppendEmpty()

fileIDInfoLock, exists := p.Frames.GetAndRefresh(traceInfo.Files[i], ...)
fileIDInfoLock, exists := p.Frames.GetAndRefresh(traceInfo.Files[i],
FramesCacheLifetime)
if !exists {
// At this point, we do not have enough information for the frame.
// Therefore, we report a dummy entry and use the interpreter as filename.
Expand Down
8 changes: 5 additions & 3 deletions reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (r *OTLPReporter) ReportCountForTrace(_ libpf.TraceHash, _ uint16, _ *Trace
// ExecutableKnown returns true if the metadata of the Executable specified by fileID is
// cached in the reporter.
func (r *OTLPReporter) ExecutableKnown(fileID libpf.FileID) bool {
_, known := r.pdata.Executables.GetAndRefresh(fileID, ...)
_, known := r.pdata.Executables.GetAndRefresh(fileID, pdata.ExecutableCacheLifetime)
return known
}

Expand All @@ -201,7 +201,8 @@ func (r *OTLPReporter) ExecutableMetadata(args *ExecutableMetadataArgs) {
// cached in the reporter.
func (r *OTLPReporter) FrameKnown(frameID libpf.FrameID) bool {
known := false
if frameMapLock, exists := r.pdata.Frames.GetAndRefresh(frameID.FileID(), ...); exists {
if frameMapLock, exists := r.pdata.Frames.GetAndRefresh(frameID.FileID(),
pdata.FramesCacheLifetime); exists {
frameMap := frameMapLock.RLock()
defer frameMapLock.RUnlock(&frameMap)
_, known = (*frameMap)[frameID.AddressOrLine()]
Expand All @@ -218,7 +219,8 @@ func (r *OTLPReporter) FrameMetadata(args *FrameMetadataArgs) {
fileID, args.FunctionName, args.FunctionOffset,
args.SourceFile, args.SourceLine)

if frameMapLock, exists := r.pdata.Frames.Get(fileID); exists {
if frameMapLock, exists := r.pdata.Frames.GetAndRefresh(fileID,
pdata.FramesCacheLifetime); exists {
frameMap := frameMapLock.WLock()
defer frameMapLock.WUnlock(&frameMap)

Expand Down

0 comments on commit 13e046c

Please sign in to comment.