[sysprof/wip/chergert/sysprof-3] libsysprof: add symbol resolver that can resolve from capture file
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/chergert/sysprof-3] libsysprof: add symbol resolver that can resolve from capture file
- Date: Wed, 29 May 2019 03:10:01 +0000 (UTC)
commit f3bf286a75ace60ec58a9501af2c961b567fd79e
Author: Christian Hergert <chergert redhat com>
Date: Tue May 28 19:06:54 2019 -0700
libsysprof: add symbol resolver that can resolve from capture file
If the capture file has an embedded __symbols__ file within it, we can
try to resolve the function names from the data embedded within that
virtual file.
src/libsysprof/meson.build | 2 +
src/libsysprof/sysprof-capture-symbol-resolver.c | 135 +++++++++++++++++++++++
src/libsysprof/sysprof-capture-symbol-resolver.h | 33 ++++++
src/libsysprof/sysprof.h | 1 +
4 files changed, 171 insertions(+)
---
diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build
index 09aed85..3b9679c 100644
--- a/src/libsysprof/meson.build
+++ b/src/libsysprof/meson.build
@@ -3,6 +3,7 @@ libsysprof_c_args = [ '-DSYSPROF_COMPILATION' ]
libsysprof_public_sources = [
'sysprof-callgraph-profile.c',
'sysprof-capture-gobject.c',
+ 'sysprof-capture-symbol-resolver.c',
'sysprof-elf-symbol-resolver.c',
'sysprof-hostinfo-source.c',
'sysprof-jitmap-symbol-resolver.c',
@@ -25,6 +26,7 @@ libsysprof_public_sources = [
libsysprof_public_headers = [
'sysprof-callgraph-profile.h',
'sysprof-capture-gobject.h',
+ 'sysprof-capture-symbol-resolver.h',
'sysprof-elf-symbol-resolver.h',
'sysprof-hostinfo-source.h',
'sysprof-jitmap-symbol-resolver.h',
diff --git a/src/libsysprof/sysprof-capture-symbol-resolver.c
b/src/libsysprof/sysprof-capture-symbol-resolver.c
new file mode 100644
index 0000000..d4e4512
--- /dev/null
+++ b/src/libsysprof/sysprof-capture-symbol-resolver.c
@@ -0,0 +1,135 @@
+/* sysprof-capture-symbol-resolver.c
+ *
+ * Copyright 2019 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-capture-symbol-resolver"
+
+#include "config.h"
+
+#include <unistd.h>
+
+#include "sysprof-capture-symbol-resolver.h"
+#include "sysprof-platform.h"
+#include "sysprof-private.h"
+#include "sysprof-symbol-map.h"
+
+/**
+ * SECTION:sysprof-capture-symbol-resolver:
+ * @title: SysprofCaptureSymbolResolver
+ * @short_description: resolve symbols from embedded data within the capture
+ *
+ * This looks for an embedded file "__symbols__" in the capture and tries to
+ * decode them using the data stored within that file.
+ *
+ * This is useful when moving capture files between machines as it will allow
+ * the viewer machine to get access to the symbols without having to copy them
+ * to the local system.
+ *
+ * Since: 3.34
+ */
+
+struct _SysprofCaptureSymbolResolver
+{
+ GObject parent_instance;
+ SysprofSymbolMap *map;
+};
+
+static void symbol_resolver_iface_init (SysprofSymbolResolverInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (SysprofCaptureSymbolResolver, sysprof_capture_symbol_resolver, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (SYSPROF_TYPE_SYMBOL_RESOLVER, symbol_resolver_iface_init))
+
+static void
+sysprof_capture_symbol_resolver_finalize (GObject *object)
+{
+ SysprofCaptureSymbolResolver *self = (SysprofCaptureSymbolResolver *)object;
+
+ g_clear_pointer (&self->map, sysprof_symbol_map_free);
+
+ G_OBJECT_CLASS (sysprof_capture_symbol_resolver_parent_class)->finalize (object);
+}
+
+static void
+sysprof_capture_symbol_resolver_class_init (SysprofCaptureSymbolResolverClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = sysprof_capture_symbol_resolver_finalize;
+}
+
+static void
+sysprof_capture_symbol_resolver_init (SysprofCaptureSymbolResolver *self)
+{
+ self->map = sysprof_symbol_map_new ();
+}
+
+SysprofSymbolResolver *
+sysprof_capture_symbol_resolver_new (void)
+{
+ return g_object_new (SYSPROF_TYPE_CAPTURE_SYMBOL_RESOLVER, NULL);
+}
+
+static void
+sysprof_capture_symbol_resolver_load (SysprofSymbolResolver *resolver,
+ SysprofCaptureReader *reader)
+{
+ SysprofCaptureSymbolResolver *self = (SysprofCaptureSymbolResolver *)resolver;
+ g_autoptr(GError) error = NULL;
+ gint byte_order;
+ gint fd;
+
+ g_assert (SYSPROF_IS_CAPTURE_SYMBOL_RESOLVER (self));
+ g_assert (reader != NULL);
+
+ byte_order = sysprof_capture_reader_get_byte_order (reader);
+
+ if (-1 == (fd = sysprof_memfd_create ("[symbol-decoder]")))
+ return;
+
+ if (sysprof_capture_reader_read_file_fd (reader, "__symbols__", fd))
+ sysprof_symbol_map_deserialize (self->map, byte_order, fd);
+
+ close (fd);
+}
+
+gchar *
+sysprof_capture_symbol_resolver_resolve_with_context (SysprofSymbolResolver *resolver,
+ guint64 time,
+ GPid pid,
+ SysprofAddressContext context,
+ SysprofCaptureAddress address,
+ GQuark *tag)
+{
+ SysprofCaptureSymbolResolver *self = (SysprofCaptureSymbolResolver *)resolver;
+ const gchar *name;
+
+ g_assert (SYSPROF_IS_CAPTURE_SYMBOL_RESOLVER (self));
+
+ if ((name = sysprof_symbol_map_lookup (self->map, time, pid, address, tag)))
+ return g_strdup (name);
+
+ return NULL;
+}
+
+static void
+symbol_resolver_iface_init (SysprofSymbolResolverInterface *iface)
+{
+ iface->load = sysprof_capture_symbol_resolver_load;
+ iface->resolve_with_context = sysprof_capture_symbol_resolver_resolve_with_context;
+}
diff --git a/src/libsysprof/sysprof-capture-symbol-resolver.h
b/src/libsysprof/sysprof-capture-symbol-resolver.h
new file mode 100644
index 0000000..2f6583a
--- /dev/null
+++ b/src/libsysprof/sysprof-capture-symbol-resolver.h
@@ -0,0 +1,33 @@
+/* sysprof-capture-symbol-resolver.h
+ *
+ * Copyright 2019 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-symbol-resolver.h"
+
+G_BEGIN_DECLS
+
+#define SYSPROF_TYPE_CAPTURE_SYMBOL_RESOLVER (sysprof_capture_symbol_resolver_get_type())
+
+G_DECLARE_FINAL_TYPE (SysprofCaptureSymbolResolver, sysprof_capture_symbol_resolver, SYSPROF,
CAPTURE_SYMBOL_RESOLVER, GObject)
+
+SysprofSymbolResolver *sysprof_capture_symbol_resolver_new (void);
+
+G_END_DECLS
diff --git a/src/libsysprof/sysprof.h b/src/libsysprof/sysprof.h
index a124707..669b6e3 100644
--- a/src/libsysprof/sysprof.h
+++ b/src/libsysprof/sysprof.h
@@ -26,6 +26,7 @@ G_BEGIN_DECLS
# include "sysprof-callgraph-profile.h"
# include "sysprof-capture-gobject.h"
+# include "sysprof-capture-symbol-resolver.h"
# include "sysprof-elf-symbol-resolver.h"
# include "sysprof-jitmap-symbol-resolver.h"
# include "sysprof-kernel-symbol-resolver.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]