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

reporter: extend lifetime for cached elements #260

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
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