Skip to content

Commit

Permalink
reporter: extend lifetime for cached elements
Browse files Browse the repository at this point in the history
Similar to the reported issue #248 around lifetime of executables, the same issue happens for frames.
So keep cached frame information alive.

Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl committed Dec 2, 2024
1 parent cd3963c commit 8b75ada
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

const (
executableCacheLifetime = 1 * time.Hour
framesCacheLifetime = 1 * time.Hour
)

// Assert that we implement the full Reporter interface.
Expand Down Expand Up @@ -159,7 +160,7 @@ func NewOTLP(cfg *Config) (*OTLPReporter, error) {
if err != nil {
return nil, err
}
frames.SetLifetime(1 * time.Hour) // Allow GC to clean stale items.
frames.SetLifetime(framesCacheLifetime) // Allow GC to clean stale items.

cgroupv2ID, err := lru.NewSynced[libpf.PID, string](cfg.CGroupCacheElements,
func(pid libpf.PID) uint32 { return uint32(pid) })
Expand Down Expand Up @@ -255,7 +256,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.executables.Get(fileID)
_, known := r.executables.GetAndRefresh(fileID, executableCacheLifetime)
return known
}

Expand All @@ -272,7 +273,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.frames.Get(frameID.FileID()); exists {
if frameMapLock, exists := r.frames.GetAndRefresh(frameID.FileID(),
framesCacheLifetime); exists {
frameMap := frameMapLock.RLock()
defer frameMapLock.RUnlock(&frameMap)
_, known = (*frameMap)[frameID.AddressOrLine()]
Expand Down Expand Up @@ -621,7 +623,8 @@ func (r *OTLPReporter) getProfile() (profile *profiles.Profile, startTS, endTS u
// Store interpreted frame information as a Line message:
line := &profiles.Line{}

fileIDInfoLock, exists := r.frames.Get(traceInfo.files[i])
fileIDInfoLock, exists := r.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

0 comments on commit 8b75ada

Please sign in to comment.