[sysprof/wip/chergert/mem-preload] memprof: more plumbing for loading and such
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/chergert/mem-preload] memprof: more plumbing for loading and such
- Date: Tue, 4 Feb 2020 23:09:49 +0000 (UTC)
commit 974989fa70ac756f1822725011caf19c0a4141af
Author: Christian Hergert <chergert redhat com>
Date: Tue Feb 4 15:09:33 2020 -0800
memprof: more plumbing for loading and such
meson.build | 1 +
src/libsysprof-ui/sysprof-display.c | 2 +
src/libsysprof-ui/sysprof-memprof-aid.c | 5 +--
src/libsysprof/meson.build | 2 +
src/libsysprof/sysprof-memprof-source.c | 76 +++++++++++++++++++++++++++++++++
src/libsysprof/sysprof-memprof-source.h | 35 +++++++++++++++
src/libsysprof/sysprof.h | 1 +
src/tools/sysprof-cli.c | 9 ++++
8 files changed, 128 insertions(+), 3 deletions(-)
---
diff --git a/meson.build b/meson.build
index b5937eb..80f0e49 100644
--- a/meson.build
+++ b/meson.build
@@ -27,6 +27,7 @@ cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
config_h = configuration_data()
+config_h.set_quoted('API_VERSION_S', '@0@'.format(libsysprof_api_version))
config_h.set_quoted('PACKAGE_NAME', 'sysprof')
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
config_h.set_quoted('PACKAGE_STRING', 'sysprof-' + meson.project_version())
diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c
index 6d082a2..7bd8f89 100644
--- a/src/libsysprof-ui/sysprof-display.c
+++ b/src/libsysprof-ui/sysprof-display.c
@@ -43,6 +43,7 @@
#include "sysprof-logs-aid.h"
#include "sysprof-marks-aid.h"
#include "sysprof-memory-aid.h"
+#include "sysprof-memprof-aid.h"
#include "sysprof-netdev-aid.h"
#include "sysprof-rapl-aid.h"
@@ -656,6 +657,7 @@ sysprof_display_present_async (SysprofDisplay *self,
g_ptr_array_add (aids, sysprof_logs_aid_new ());
g_ptr_array_add (aids, sysprof_marks_aid_new ());
g_ptr_array_add (aids, sysprof_memory_aid_new ());
+ g_ptr_array_add (aids, sysprof_memprof_aid_new ());
g_ptr_array_add (aids, sysprof_netdev_aid_new ());
g_ptr_array_add (aids, sysprof_rapl_aid_new ());
diff --git a/src/libsysprof-ui/sysprof-memprof-aid.c b/src/libsysprof-ui/sysprof-memprof-aid.c
index 1224002..a0f9866 100644
--- a/src/libsysprof-ui/sysprof-memprof-aid.c
+++ b/src/libsysprof-ui/sysprof-memprof-aid.c
@@ -26,6 +26,7 @@
#include "sysprof-memprof-aid.h"
#include "sysprof-memprof-page.h"
+#include "sysprof-memprof-source.h"
struct _SysprofMemprofAid
{
@@ -80,9 +81,7 @@ sysprof_memprof_aid_prepare (SysprofAid *self,
g_assert (SYSPROF_IS_MEMPROF_AID (self));
g_assert (SYSPROF_IS_PROFILER (profiler));
- source = g_object_new (SYSPROF_TYPE_TRACEFD_SOURCE,
- "envvar", "MEMPROF_TRACE_FD",
- NULL);
+ source = sysprof_memprof_source_new ();
sysprof_profiler_add_source (profiler, source);
#endif
}
diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build
index b887248..1e5430e 100644
--- a/src/libsysprof/meson.build
+++ b/src/libsysprof/meson.build
@@ -17,6 +17,7 @@ libsysprof_public_sources = [
'sysprof-kernel-symbol-resolver.c',
'sysprof-local-profiler.c',
'sysprof-memory-profile.c',
+ 'sysprof-memprof-source.c',
'sysprof-netdev-source.c',
'sysprof-process-model.c',
'sysprof-process-model-item.c',
@@ -47,6 +48,7 @@ libsysprof_public_headers = [
'sysprof-kernel-symbol-resolver.h',
'sysprof-local-profiler.h',
'sysprof-memory-profile.h',
+ 'sysprof-memprof-source.h',
'sysprof-process-model.h',
'sysprof-process-model-item.h',
'sysprof-profile.h',
diff --git a/src/libsysprof/sysprof-memprof-source.c b/src/libsysprof/sysprof-memprof-source.c
new file mode 100644
index 0000000..0de8bff
--- /dev/null
+++ b/src/libsysprof/sysprof-memprof-source.c
@@ -0,0 +1,76 @@
+/* sysprof-memprof-source.c
+ *
+ * Copyright 2020 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
+ */
+
+#define G_LOG_DOMAIN "sysprof-memprof-source"
+
+#include "config.h"
+
+#include "sysprof-memprof-source.h"
+
+struct _SysprofMemprofSource
+{
+ SysprofTracefdSource parent_instance;
+};
+
+static SysprofSourceInterface *parent_iface;
+
+static void
+sysprof_memprof_source_modify_spawn (SysprofSource *source,
+ SysprofSpawnable *spawnable)
+{
+ g_assert (SYSPROF_IS_SOURCE (source));
+ g_assert (SYSPROF_IS_SPAWNABLE (spawnable));
+
+ parent_iface->modify_spawn (source, spawnable);
+
+#ifdef __linux__
+ sysprof_spawnable_setenv (spawnable,
+ "LD_PRELOAD",
+ PACKAGE_LIBEXECDIR"/libsysprof-memory-"API_VERSION_S".so");
+#endif
+}
+
+static void
+source_iface_init (SysprofSourceInterface *iface)
+{
+ parent_iface = g_type_interface_peek_parent (iface);
+
+ iface->modify_spawn = sysprof_memprof_source_modify_spawn;
+}
+
+G_DEFINE_TYPE_WITH_CODE (SysprofMemprofSource, sysprof_memprof_source, SYSPROF_TYPE_TRACEFD_SOURCE,
+ G_IMPLEMENT_INTERFACE (SYSPROF_TYPE_SOURCE, source_iface_init))
+
+static void
+sysprof_memprof_source_class_init (SysprofMemprofSourceClass *klass)
+{
+}
+
+static void
+sysprof_memprof_source_init (SysprofMemprofSource *self)
+{
+ sysprof_tracefd_source_set_envvar (SYSPROF_TRACEFD_SOURCE (self), "MEMPROF_TRACE_FD");
+}
+
+SysprofSource *
+sysprof_memprof_source_new (void)
+{
+ return g_object_new (SYSPROF_TYPE_MEMPROF_SOURCE, NULL);
+}
diff --git a/src/libsysprof/sysprof-memprof-source.h b/src/libsysprof/sysprof-memprof-source.h
new file mode 100644
index 0000000..9188a89
--- /dev/null
+++ b/src/libsysprof/sysprof-memprof-source.h
@@ -0,0 +1,35 @@
+/* sysprof-memprof-source.h
+ *
+ * Copyright 2020 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
+ */
+
+#pragma once
+
+#include "sysprof-tracefd-source.h"
+
+G_BEGIN_DECLS
+
+#define SYSPROF_TYPE_MEMPROF_SOURCE (sysprof_memprof_source_get_type())
+
+SYSPROF_AVAILABLE_IN_3_36
+G_DECLARE_FINAL_TYPE (SysprofMemprofSource, sysprof_memprof_source, SYSPROF, MEMPROF_SOURCE,
SysprofTracefdSource)
+
+SYSPROF_AVAILABLE_IN_3_36
+SysprofSource *sysprof_memprof_source_new (void);
+
+G_END_DECLS
diff --git a/src/libsysprof/sysprof.h b/src/libsysprof/sysprof.h
index 0485ec0..f25fdc1 100644
--- a/src/libsysprof/sysprof.h
+++ b/src/libsysprof/sysprof.h
@@ -37,6 +37,7 @@ G_BEGIN_DECLS
# include "sysprof-kernel-symbol.h"
# include "sysprof-local-profiler.h"
# include "sysprof-memory-profile.h"
+# include "sysprof-memprof-source.h"
# include "sysprof-netdev-source.h"
# include "sysprof-process-model-item.h"
# include "sysprof-process-model.h"
diff --git a/src/tools/sysprof-cli.c b/src/tools/sysprof-cli.c
index 78ff2b0..72b94e7 100644
--- a/src/tools/sysprof-cli.c
+++ b/src/tools/sysprof-cli.c
@@ -189,6 +189,7 @@ main (gint argc,
gboolean use_trace_fd = FALSE;
gboolean gnome_shell = FALSE;
gboolean rapl = FALSE;
+ gboolean memprof = FALSE;
gboolean merge = FALSE;
int pid = -1;
int fd;
@@ -208,6 +209,7 @@ main (gint argc,
{ "gjs", 0, 0, G_OPTION_ARG_NONE, &gjs, N_("Set GJS_TRACE_FD environment to trace GJS processes") },
{ "gtk", 0, 0, G_OPTION_ARG_NONE, >k, N_("Set GTK_TRACE_FD environment to trace a GTK application") },
{ "rapl", 0, 0, G_OPTION_ARG_NONE, &rapl, N_("Include RAPL energy statistics") },
+ { "memprof", 0, 0, G_OPTION_ARG_NONE, &memprof, N_("Profile memory allocations and frees") },
{ "gnome-shell", 0, 0, G_OPTION_ARG_NONE, &gnome_shell, N_("Connect to org.gnome.Shell for profiler
statistics") },
{ "merge", 0, 0, G_OPTION_ARG_NONE, &merge, N_("Merge all provided *.syscap files and write to stdout")
},
{ "version", 0, 0, G_OPTION_ARG_NONE, &version, N_("Print the sysprof-cli version and exit") },
@@ -471,6 +473,13 @@ Examples:\n\
g_object_unref (source);
}
+ if (memprof)
+ {
+ source = sysprof_memprof_source_new ();
+ sysprof_profiler_add_source (profiler, source);
+ g_object_unref (source);
+ }
+
if (pid != -1)
{
sysprof_profiler_set_whole_system (profiler, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]