[sysprof] libsysprof/preload: add example for tracing with -finstrument-functions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] libsysprof/preload: add example for tracing with -finstrument-functions
- Date: Tue, 26 Jul 2022 06:37:51 +0000 (UTC)
commit 51e9123f6fd0c8b8f1335f0425f5dde5915e0a52
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 25 23:36:45 2022 -0700
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.
src/libsysprof/preload/sysprof-tracer.c | 72 +++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
---
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 <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)
+{
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]