mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +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:
@ -24,3 +24,10 @@ libsysprof_speedtrack_preload = shared_library('sysprof-speedtrack-@0@'.format(l
|
||||
install: true,
|
||||
install_dir: get_option('libdir'),
|
||||
)
|
||||
|
||||
libsysprof_tracer_preload = shared_library('sysprof-tracer-@0@'.format(libsysprof_api_version),
|
||||
['sysprof-tracer-collector.c'],
|
||||
dependencies: preload_deps,
|
||||
install: true,
|
||||
install_dir: get_option('libdir'),
|
||||
)
|
||||
|
||||
@ -28,6 +28,15 @@
|
||||
|
||||
#include "gconstructor.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define GNUC_CHECK_VERSION(major, minor) \
|
||||
((__GNUC__ > (major)) || \
|
||||
((__GNUC__ == (major)) && \
|
||||
(__GNUC_MINOR__ >= (minor))))
|
||||
#else
|
||||
# define GNUC_CHECK_VERSION(major, minor) 0
|
||||
#endif
|
||||
|
||||
#if defined (G_HAS_CONSTRUCTORS)
|
||||
# ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
||||
# pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(collector_init_ctor)
|
||||
@ -49,24 +58,30 @@ collector_init_ctor (void)
|
||||
sysprof_collector_init ();
|
||||
}
|
||||
|
||||
/* TODO:
|
||||
*
|
||||
* This is just an example.
|
||||
*
|
||||
/*
|
||||
* What we would really want to do is to have a new frame type for enter/exit
|
||||
* tracing so that we can only push/pop the new address to the sample. Then
|
||||
* when decoding it can recreate stack traces if necessary.
|
||||
* when decoding it can recreate stack traces if necessary. But for now, we
|
||||
* can emulate that by just adding a sample when we enter a function and
|
||||
* leave a function. The rest could be done in post-processing.
|
||||
*/
|
||||
|
||||
#if GNUC_CHECK_VERSION(3,0)
|
||||
__attribute__((no_instrument_function))
|
||||
#endif
|
||||
void
|
||||
profile_func_enter (void *func,
|
||||
void *call_site)
|
||||
{
|
||||
sysprof_collector_sample (backtrace_func, NULL);
|
||||
sysprof_collector_trace (backtrace_func, NULL, TRUE);
|
||||
}
|
||||
|
||||
#if GNUC_CHECK_VERSION(3,0)
|
||||
__attribute__((no_instrument_function))
|
||||
#endif
|
||||
void
|
||||
profile_func_exit (void *func,
|
||||
void *call_site)
|
||||
{
|
||||
sysprof_collector_trace (backtrace_func, NULL, FALSE);
|
||||
}
|
||||
Reference in New Issue
Block a user