mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof/preload: add example for tracing with -finstrument-functions
If we have tooling that can toggle -finstrument-functions, Builder for example, then we'd be able to use an LD_PRELOAD to inject the various function callbacks to record samples. I dont think we want to use the sample frame type for this though. We really want something focused on tracing instead and visualize it a bit differently than the stack trace visualizer.
This commit is contained in:
72
src/libsysprof/preload/sysprof-tracer.c
Normal file
72
src/libsysprof/preload/sysprof-tracer.c
Normal file
@ -0,0 +1,72 @@
|
||||
/* sysprof-tracer.c
|
||||
*
|
||||
* Copyright 2022 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <sysprof-capture.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "backtrace-helper.h"
|
||||
|
||||
#include "gconstructor.h"
|
||||
|
||||
#if defined (G_HAS_CONSTRUCTORS)
|
||||
# ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
||||
# pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(collector_init_ctor)
|
||||
# endif
|
||||
G_DEFINE_CONSTRUCTOR(collector_init_ctor)
|
||||
#else
|
||||
# error Your platform/compiler is missing constructor support
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
# define profile_func_enter __cyg_profile_func_enter
|
||||
# define profile_func_exit __cyg_profile_func_exit
|
||||
#endif
|
||||
|
||||
static void
|
||||
collector_init_ctor (void)
|
||||
{
|
||||
backtrace_init ();
|
||||
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.
|
||||
*/
|
||||
|
||||
void
|
||||
profile_func_enter (void *func,
|
||||
void *call_site)
|
||||
{
|
||||
sysprof_collector_sample (backtrace_func, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
profile_func_exit (void *func,
|
||||
void *call_site)
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user