diff --git a/src/libsysprof/preload/sysprof-tracer.c b/src/libsysprof/preload/sysprof-tracer.c new file mode 100644 index 00000000..95937b0f --- /dev/null +++ b/src/libsysprof/preload/sysprof-tracer.c @@ -0,0 +1,72 @@ +/* sysprof-tracer.c + * + * Copyright 2022 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include +#include +#include + +#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) +{ +}