Debian Codegraph @

src/libsysprof/tests/test-list-overlays.c

raw
1 /* test-list-overlays.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) processes = NULL;
32 g_autoptr(GError) error = NULL;
33 guint n_items;
34 int pid = -1;
35
36 if (argc < 2)
37 {
38 g_printerr ("usage: %s CAPTURE_FILE [PID]\n", argv[0]);
39 return 1;
40 }
41
42 if (argc == 3)
43 pid = atoi (argv[2]);
44
45 loader = sysprof_document_loader_new (argv[1]);
46 sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ());
47
48 if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
49 {
50 g_printerr ("Failed to open capture: %s\n", error->message);
51 return 1;
52 }
53
54 processes = sysprof_document_list_processes (document);
55 n_items = g_list_model_get_n_items (processes);
56
57 for (guint i = 0; i < n_items; i++)
58 {
59 g_autoptr(SysprofDocumentProcess) process = g_list_model_get_item (processes, i);
60 g_autoptr(GListModel) mounts = sysprof_document_process_list_mounts (process);
61 g_autoptr(GString) str = g_string_new (NULL);
62 guint n_mounts;
63
64 if (pid != -1 && pid != sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process)))
65 continue;
66
67 n_mounts = g_list_model_get_n_items (mounts);
68 for (guint j = 0; j < n_mounts; j++)
69 {
70 g_autoptr(SysprofMount) mount = g_list_model_get_item (mounts, j);
71 const char *fs_type = sysprof_mount_get_filesystem_type (mount);
72 const char *value;
73
74 if (g_strcmp0 (fs_type, "overlay") == 0)
75 g_string_append_printf (str,
76 " @ID(%d) @ROOT(%s) @MOUNT_POINT(%s) @MOUNT_SOURCE(%s) @FS_TYPE(%s) @OPTIONS(%s)\n",
77 sysprof_mount_get_mount_id (mount),
78 sysprof_mount_get_root (mount),
79 sysprof_mount_get_mount_point (mount),
80 sysprof_mount_get_mount_source (mount),
81 sysprof_mount_get_filesystem_type (mount),
82 sysprof_mount_get_superblock_options (mount));
83
84 if ((value = sysprof_mount_get_superblock_option (mount, "lowerdir")))
85 {
86 g_auto(GStrv) split = g_strsplit (value, ":", 0);
87
88 g_string_append_printf (str, " LOWER: %s\n", value);
89 for (guint k = 0; split[k]; k++)
90 g_string_append_printf (str, " [%d]: %s\n", k, split[k]);
91 }
92
93 if ((value = sysprof_mount_get_superblock_option (mount, "upperdir")))
94 g_string_append_printf (str, " UPPER: %s\n", value);
95
96 if ((value = sysprof_mount_get_superblock_option (mount, "workdir")))
97 g_string_append_printf (str, " WORKDIR: %s\n", value);
98 }
99
100 if (str->len > 0)
101 g_print ("%d:\n%s",
102 sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process)),
103 str->str);
104 }
105
106 return 0;
107 }