diff --git a/src/libsysprof-analyze/sysprof-document.c b/src/libsysprof-analyze/sysprof-document.c index 35c0f8aa..aab61967 100644 --- a/src/libsysprof-analyze/sysprof-document.c +++ b/src/libsysprof-analyze/sysprof-document.c @@ -740,6 +740,37 @@ sysprof_document_load_worker (GTask *task, g_strdup (file_chunk->path), GUINT_TO_POINTER (self->frames->len)); } + else if (tainted->type == SYSPROF_CAPTURE_FRAME_MARK) + { + const SysprofCaptureMark *mark = (const SysprofCaptureMark *)tainted; + const char *endptr = (const char *)tainted + frame_len; + + if (has_null_byte (mark->group, endptr) && + has_null_byte (mark->name, endptr)) + { + const char *group = mark->group; + const char *name = mark->name; + GHashTable *names; + EggBitset *bitset; + + if (!(names = g_hash_table_lookup (self->mark_groups, group))) + { + names = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + (GDestroyNotify)egg_bitset_unref); + g_hash_table_insert (self->mark_groups, g_strdup (group), names); + } + + if (!(bitset = g_hash_table_lookup (names, name))) + { + bitset = egg_bitset_new_empty (); + g_hash_table_insert (names, g_strdup (name), bitset); + } + + egg_bitset_add (bitset, self->frames->len); + } + } pos += frame_len; diff --git a/src/libsysprof-analyze/tests/meson.build b/src/libsysprof-analyze/tests/meson.build index 152ba494..a96a5e59 100644 --- a/src/libsysprof-analyze/tests/meson.build +++ b/src/libsysprof-analyze/tests/meson.build @@ -19,6 +19,7 @@ libsysprof_analyze_testsuite = { 'test-list-files' : {'skip': true}, 'test-list-jitmap' : {'skip': true}, 'test-list-overlays' : {'skip': true}, + 'test-mark-catalog' : {'skip': true}, 'test-print-file' : {'skip': true}, 'test-list-processes' : {'skip': true}, 'test-list-address-layout' : {'skip': true}, diff --git a/src/libsysprof-analyze/tests/test-mark-catalog.c b/src/libsysprof-analyze/tests/test-mark-catalog.c new file mode 100644 index 00000000..ed57c2e4 --- /dev/null +++ b/src/libsysprof-analyze/tests/test-mark-catalog.c @@ -0,0 +1,90 @@ +/* test-mark-catalog.c + * + * Copyright 2023 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 + +#include "sysprof-document-private.h" + +int +main (int argc, + char *argv[]) +{ + g_autoptr(SysprofDocumentLoader) loader = NULL; + g_autoptr(SysprofDocument) document = NULL; + g_autoptr(GListModel) marks = NULL; + g_autoptr(GError) error = NULL; + guint n_groups; + + if (argc < 2) + { + g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]); + return 1; + } + + loader = sysprof_document_loader_new (argv[1]); + sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ()); + + if (!(document = sysprof_document_loader_load (loader, NULL, &error))) + { + g_printerr ("Failed to open capture: %s\n", error->message); + return 1; + } + + marks = sysprof_document_catalog_marks (document); + n_groups = g_list_model_get_n_items (marks); + + for (guint i = 0; i < n_groups; i++) + { + g_autoptr(SysprofMarkCatalog) catalog = g_list_model_get_item (marks, i); + const char *group = sysprof_mark_catalog_get_name (catalog); + guint n_names = g_list_model_get_n_items (G_LIST_MODEL (catalog)); + + g_assert (SYSPROF_IS_MARK_CATALOG (catalog)); + g_assert (G_IS_LIST_MODEL (catalog)); + + g_print ("%s\n", group); + + for (guint j = 0; j < n_names; j++) + { + g_autoptr(SysprofMarkCatalog) name_catalog = g_list_model_get_item (G_LIST_MODEL (catalog), j); + const char *name = sysprof_mark_catalog_get_name (name_catalog); + guint n_marks = g_list_model_get_n_items (G_LIST_MODEL (name_catalog)); + + g_assert (SYSPROF_IS_MARK_CATALOG (catalog)); + g_assert (G_IS_LIST_MODEL (catalog)); + + g_print (" %s\n", name); + + for (guint k = 0; k < n_marks; k++) + { + g_autoptr(SysprofDocumentMark) mark = g_list_model_get_item (G_LIST_MODEL (name_catalog), k); + + g_assert (SYSPROF_IS_DOCUMENT_MARK (mark)); + + g_assert_cmpstr (sysprof_document_mark_get_group (mark), ==, group); + g_assert_cmpstr (sysprof_document_mark_get_name (mark), ==, name); + + g_print (" %s\n", sysprof_document_mark_get_message (mark)); + } + } + } + + return 0; +}