-
Notifications
You must be signed in to change notification settings - Fork 288
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
Off CPU profiling #196
Off CPU profiling #196
Changes from all commits
6ebd2fa
92ec605
3f1d14a
dd6ace0
6cb92da
ca08c03
591415e
ddec328
75c387a
39f576e
939d051
979df97
027c6b9
7f987da
1c7724a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"go.opentelemetry.io/ebpf-profiler/libpf/xsync" | ||
"go.opentelemetry.io/ebpf-profiler/reporter/internal/pdata" | ||
"go.opentelemetry.io/ebpf-profiler/reporter/internal/samples" | ||
"go.opentelemetry.io/ebpf-profiler/support" | ||
) | ||
|
||
// baseReporter encapsulates shared behavior between all the available reporters. | ||
|
@@ -35,7 +36,7 @@ type baseReporter struct { | |
cgroupv2ID *lru.SyncedLRU[libpf.PID, string] | ||
|
||
// traceEvents stores reported trace events (trace metadata with frames and counts) | ||
traceEvents xsync.RWMutex[map[samples.TraceAndMetaKey]*samples.TraceEvents] | ||
traceEvents xsync.RWMutex[map[libpf.Origin]samples.KeyToEventMapping] | ||
|
||
// hostmetadata stores metadata that is sent out with every request. | ||
hostmetadata *lru.SyncedLRU[string, string] | ||
|
@@ -97,8 +98,11 @@ func (*baseReporter) ReportMetrics(_ uint32, _ []uint32, _ []int64) {} | |
func (*baseReporter) SupportsReportTraceEvent() bool { return true } | ||
|
||
func (b *baseReporter) ReportTraceEvent(trace *libpf.Trace, meta *TraceEventMeta) { | ||
traceEventsMap := b.traceEvents.WLock() | ||
defer b.traceEvents.WUnlock(&traceEventsMap) | ||
if meta.Origin != support.TraceOriginSampling && meta.Origin != support.TraceOriginOffCPU { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to propagate a trace that we're going to reject all the way here, but should instead fast-fail as early as possible (e.g. in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a check in |
||
// At the moment only on-CPU and off-CPU traces are reported. | ||
log.Errorf("Skip reporting trace for unexpected %d origin", meta.Origin) | ||
return | ||
} | ||
|
||
var extraMeta any | ||
if b.cfg.ExtraSampleAttrProd != nil { | ||
|
@@ -122,20 +126,25 @@ func (b *baseReporter) ReportTraceEvent(trace *libpf.Trace, meta *TraceEventMeta | |
ExtraMeta: extraMeta, | ||
} | ||
|
||
if events, exists := (*traceEventsMap)[key]; exists { | ||
traceEventsMap := b.traceEvents.WLock() | ||
defer b.traceEvents.WUnlock(&traceEventsMap) | ||
|
||
if events, exists := (*traceEventsMap)[meta.Origin][key]; exists { | ||
events.Timestamps = append(events.Timestamps, uint64(meta.Timestamp)) | ||
(*traceEventsMap)[key] = events | ||
events.OffTimes = append(events.OffTimes, meta.OffTime) | ||
(*traceEventsMap)[meta.Origin][key] = events | ||
return | ||
} | ||
|
||
(*traceEventsMap)[key] = &samples.TraceEvents{ | ||
(*traceEventsMap)[meta.Origin][key] = &samples.TraceEvents{ | ||
Files: trace.Files, | ||
Linenos: trace.Linenos, | ||
FrameTypes: trace.FrameTypes, | ||
MappingStarts: trace.MappingStart, | ||
MappingEnds: trace.MappingEnd, | ||
MappingFileOffsets: trace.MappingFileOffsets, | ||
Timestamps: []uint64{uint64(meta.Timestamp)}, | ||
OffTimes: []int64{meta.OffTime}, | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe more informative to be more specific:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this implementation detail around
sched_switch
should be part of a help message. As users can not changesched_switch
to something different as entry point, I think, this implementation detail should not matter.