mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-09 14:40:54 +00:00
libsysprof-capture: add frame type for tracing
This is like sample but has an "enter/exit" flag with it. This can be useful when you want to provide tracing instead of sampling. We use a different frame type so that we can denote that this isn't traditional sampling, and the flag can be used to find the next exit for the current enter for calculating durations. The entire stack trace is provided to make things easier on tools which may want to deal with indirect functions that were not instrumented but can be unwound. That may allow for tooling to give the user some insight that it's not *just* this function entering, but some functions before it were entered too. This also adds a SysprofTracer instrument which will preload a libsysprof-tracer-6.so into the process providing the __cyg_profile_func_enter() and __cyg_profile_func_leave() hooks.
This commit is contained in:
@ -576,6 +576,43 @@ sysprof_collector_sample (SysprofBacktraceFunc backtrace_func,
|
||||
} COLLECTOR_END;
|
||||
}
|
||||
|
||||
void
|
||||
sysprof_collector_trace (SysprofBacktraceFunc backtrace_func,
|
||||
void *backtrace_data,
|
||||
bool entering)
|
||||
{
|
||||
COLLECTOR_BEGIN {
|
||||
SysprofCaptureTrace *ev;
|
||||
size_t len;
|
||||
|
||||
len = sizeof *ev + (sizeof (SysprofCaptureTrace) * MAX_UNWIND_DEPTH);
|
||||
|
||||
if ((ev = mapped_ring_buffer_allocate (collector->buffer, len)))
|
||||
{
|
||||
int n_addrs;
|
||||
|
||||
/* See comment from sysprof_collector_allocate(). */
|
||||
if (backtrace_func)
|
||||
n_addrs = backtrace_func (ev->addrs, MAX_UNWIND_DEPTH, backtrace_data);
|
||||
else
|
||||
n_addrs = 0;
|
||||
|
||||
ev->n_addrs = ((n_addrs < 0) ? 0 : (n_addrs > MAX_UNWIND_DEPTH) ? MAX_UNWIND_DEPTH : n_addrs);
|
||||
ev->frame.len = sizeof *ev + sizeof (SysprofCaptureAddress) * ev->n_addrs;
|
||||
ev->frame.type = SYSPROF_CAPTURE_FRAME_TRACE;
|
||||
ev->frame.cpu = _do_getcpu ();
|
||||
ev->frame.pid = collector->pid;
|
||||
ev->frame.time = SYSPROF_CAPTURE_CURRENT_TIME;
|
||||
ev->tid = collector->tid;
|
||||
ev->entering = !!entering;
|
||||
ev->padding1 = 0;
|
||||
|
||||
mapped_ring_buffer_advance (collector->buffer, ev->frame.len);
|
||||
}
|
||||
|
||||
} COLLECTOR_END;
|
||||
}
|
||||
|
||||
void
|
||||
sysprof_collector_mark (int64_t time,
|
||||
int64_t duration,
|
||||
|
||||
Reference in New Issue
Block a user