libsysprof-analyze: add some common tags

It's nice to have various labels on subsystems used on the desktop, so add
some common ones here that are part of the platform.
This commit is contained in:
Christian Hergert
2023-05-19 16:18:06 -07:00
parent 167255be45
commit d7f6e4b922
3 changed files with 95 additions and 1 deletions

View File

@ -35,6 +35,7 @@ SysprofElf *sysprof_elf_new (const char *filename,
gboolean sysprof_elf_matches (SysprofElf *self, gboolean sysprof_elf_matches (SysprofElf *self,
guint64 file_inode, guint64 file_inode,
const char *build_id); const char *build_id);
const char *sysprof_elf_get_nick (SysprofElf *self);
const char *sysprof_elf_get_file (SysprofElf *self); const char *sysprof_elf_get_file (SysprofElf *self);
const char *sysprof_elf_get_build_id (SysprofElf *self); const char *sysprof_elf_get_build_id (SysprofElf *self);
const char *sysprof_elf_get_debug_link (SysprofElf *self); const char *sysprof_elf_get_debug_link (SysprofElf *self);

View File

@ -100,7 +100,7 @@ sysprof_elf_symbolizer_symbolize (SysprofSymbolizer *symbolizer,
goto fallback; goto fallback;
return _sysprof_symbol_new (sysprof_strings_get (strings, name), return _sysprof_symbol_new (sysprof_strings_get (strings, name),
NULL, sysprof_strings_get (strings, sysprof_elf_get_nick (elf)),
sysprof_strings_get (strings, path), sysprof_strings_get (strings, path),
start_address + (begin_address - file_offset), start_address + (begin_address - file_offset),
start_address + (end_address - file_offset)); start_address + (end_address - file_offset));

View File

@ -27,6 +27,7 @@
struct _SysprofElf struct _SysprofElf
{ {
GObject parent_instance; GObject parent_instance;
const char *nick;
char *build_id; char *build_id;
char *file; char *file;
SysprofElf *debug_link_elf; SysprofElf *debug_link_elf;
@ -46,6 +47,51 @@ enum {
G_DEFINE_FINAL_TYPE (SysprofElf, sysprof_elf, G_TYPE_OBJECT) G_DEFINE_FINAL_TYPE (SysprofElf, sysprof_elf, G_TYPE_OBJECT)
static GParamSpec *properties [N_PROPS]; static GParamSpec *properties [N_PROPS];
static GHashTable *nicks;
static const struct {
const char *library;
const char *nick;
} nick_table[] = {
{ "libEGL.so", "EGL" },
{ "libEGL_mesa.so", "Mesa EGL" },
{ "libGL.so", "GL" },
{ "libX11-xcb.so", "X11" },
{ "libX11.so", "X11" },
{ "libc.so", "libc" },
{ "libcairo-gobject.so", "Cairo" },
{ "libcairo.so", "Cairo" },
{ "libclutter-1.0.so", "Clutter" },
{ "libclutter-glx-1.0.so", "Clutter" },
{ "libffi.so", "libffi" },
{ "libgdk-3.so", "GDK 3" },
{ "libgio-2.0.so", "Gio" },
{ "libgirepository-1.0.so", "Introspection" },
{ "libgjs.so", "GJS" },
{ "libglib-2.0.so", "GLib" },
{ "libgobject-2.0.so", "GObject" },
{ "libgstreamer-1-0.so", "GStreamer" },
{ "libgtk-3.so", "GTK 3" },
{ "libgtk-4.so", "GTK 4" },
{ "libgtksourceview-3.0.so", "GtkSourceView 3" },
{ "libgtksourceview-4.so", "GtkSourceView 4" },
{ "libgtksourceview-5.so", "GtkSourceView 5" },
{ "libharfbuzz-cairo.so", "Harfbuzz" },
{ "libharfbuzz-gobject.so", "Harfbuzz" },
{ "libharfbuzz-icu.so", "Harfbuzz" },
{ "libharfbuzz-subset.so", "Harfbuzz" },
{ "libharfbuzz.so", "Harfbuzz" },
{ "libinput.so", "Mutter" },
{ "libmutter-12.so", "Mutter" },
{ "libpango-1.0.so", "Pango" },
{ "libpangocairo-1.0.so", "Pango" },
{ "libpipewire-0.3.so", "Pipewire" },
{ "libpixman-1.so", "Pixman" },
{ "libstdc++.so", "libc" },
{ "libwayland-client.so", "Wayland Client" },
{ "libwayland-cursor.so", "Wayland Cursor" },
{ "libwayland-egl.so", "Wayland EGL" },
{ "libwayland-server.so", "Wayland Server" },
};
static void static void
sysprof_elf_finalize (GObject *object) sysprof_elf_finalize (GObject *object)
@ -140,6 +186,12 @@ sysprof_elf_class_init (SysprofElfClass *klass)
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);
nicks = g_hash_table_new (g_str_hash, g_str_equal);
for (guint i = 0; i < G_N_ELEMENTS (nick_table); i++)
g_hash_table_insert (nicks,
(char *)nick_table[i].library,
(char *)nick_table[i].nick);
} }
static void static void
@ -147,6 +199,25 @@ sysprof_elf_init (SysprofElf *self)
{ {
} }
static void
guess_nick (SysprofElf *self,
const char *name,
const char *endptr)
{
char key[32];
if (endptr <= name)
return;
if (endptr - name >= sizeof key)
return;
memcpy (key, name, endptr-name);
key[endptr-name] = 0;
self->nick = g_hash_table_lookup (nicks, key);
}
SysprofElf * SysprofElf *
sysprof_elf_new (const char *filename, sysprof_elf_new (const char *filename,
GMappedFile *mapped_file, GMappedFile *mapped_file,
@ -166,6 +237,20 @@ sysprof_elf_new (const char *filename,
self->parser = g_steal_pointer (&parser); self->parser = g_steal_pointer (&parser);
self->file_inode = file_inode; self->file_inode = file_inode;
if (filename != NULL)
{
const char *base;
const char *endptr;
if ((base = strrchr (filename, '/')))
{
endptr = strstr (++base, ".so");
if (endptr != NULL && (endptr[3] == 0 || endptr[3] == '.'))
guess_nick (self, base, &endptr[3]);
}
}
return self; return self;
} }
@ -284,3 +369,11 @@ sysprof_elf_matches (SysprofElf *self,
return TRUE; return TRUE;
} }
const char *
sysprof_elf_get_nick (SysprofElf *self)
{
g_return_val_if_fail (SYSPROF_IS_ELF (self), NULL);
return self->nick;
}