Debian Codegraph @

src/libsysprof/tests/test-mark-catalog.c

raw
1 /* test-mark-catalog.c
2 *
3 * Copyright 2023 Christian Hergert <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include <sysprof.h>
22
23 #include "sysprof-document-private.h"
24
25 int
26 main (int argc,
27 char *argv[])
28 {
29 g_autoptr(SysprofDocumentLoader) loader = NULL;
30 g_autoptr(SysprofDocument) document = NULL;
31 g_autoptr(GListModel) groups = NULL;
32 g_autoptr(GError) error = NULL;
33 guint n_groups;
34
35 if (argc < 2)
36 {
37 g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]);
38 return 1;
39 }
40
41 loader = sysprof_document_loader_new (argv[1]);
42 sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ());
43
44 if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
45 {
46 g_printerr ("Failed to open capture: %s\n", error->message);
47 return 1;
48 }
49
50 groups = sysprof_document_catalog_marks (document);
51 n_groups = g_list_model_get_n_items (groups);
52
53 for (guint i = 0; i < n_groups; i++)
54 {
55 g_autoptr(GListModel) catalogs = g_list_model_get_item (groups, i);
56 guint n_catalogs = g_list_model_get_n_items (catalogs);
57
58 for (guint j = 0; j < n_catalogs; j++)
59 {
60 g_autoptr(SysprofMarkCatalog) catalog = g_list_model_get_item (catalogs, j);
61 const char *group = sysprof_mark_catalog_get_group (catalog);
62 const char *name = sysprof_mark_catalog_get_name (catalog);
63
64 if (j == 0)
65 g_print ("%s\n", group);
66
67 g_print (" %s\n", name);
68 }
69 }
70
71 return 0;
72 }