| 1 |
/* test-list-processes.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) memory_maps = sysprof_document_process_list_memory_maps (process); |
| 61 |
g_autoptr(GListModel) mounts = sysprof_document_process_list_mounts (process); |
| 62 |
g_autoptr(GListModel) threads = sysprof_document_process_list_threads (process); |
| 63 |
guint n_maps; |
| 64 |
guint n_mounts; |
| 65 |
guint n_threads; |
| 66 |
|
| 67 |
if (pid != -1 && pid != sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process))) |
| 68 |
continue; |
| 69 |
|
| 70 |
g_print ("%d: %s (Duration %lf seconds)\n", |
| 71 |
sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process)), |
| 72 |
sysprof_document_process_get_command_line (process), |
| 73 |
sysprof_document_process_get_duration (process) / (double)SYSPROF_NSEC_PER_SEC); |
| 74 |
|
| 75 |
g_print (" Address Layout:\n"); |
| 76 |
n_maps = g_list_model_get_n_items (memory_maps); |
| 77 |
for (guint j = 0; j < n_maps; j++) |
| 78 |
{ |
| 79 |
g_autoptr(SysprofDocumentMmap) map = g_list_model_get_item (memory_maps, j); |
| 80 |
|
| 81 |
g_print (" [0x%"G_GINT64_MODIFIER"x:0x%"G_GINT64_MODIFIER"x] %s\n", |
| 82 |
sysprof_document_mmap_get_start_address (map), |
| 83 |
sysprof_document_mmap_get_end_address (map), |
| 84 |
sysprof_document_mmap_get_file (map)); |
| 85 |
} |
| 86 |
|
| 87 |
g_print (" Mounts:\n"); |
| 88 |
n_mounts = g_list_model_get_n_items (mounts); |
| 89 |
for (guint j = 0; j < n_mounts; j++) |
| 90 |
{ |
| 91 |
g_autoptr(SysprofMount) mount = g_list_model_get_item (mounts, j); |
| 92 |
g_autofree char *subvol = sysprof_mount_get_superblock_option (mount, "subvol"); |
| 93 |
|
| 94 |
g_print (" %d %d %d:%d %s %s %s %s %s\n", |
| 95 |
sysprof_mount_get_mount_id (mount), |
| 96 |
sysprof_mount_get_parent_mount_id (mount), |
| 97 |
sysprof_mount_get_device_major (mount), |
| 98 |
sysprof_mount_get_device_minor (mount), |
| 99 |
sysprof_mount_get_root (mount), |
| 100 |
sysprof_mount_get_mount_point (mount), |
| 101 |
sysprof_mount_get_mount_source (mount), |
| 102 |
sysprof_mount_get_filesystem_type (mount), |
| 103 |
sysprof_mount_get_superblock_options (mount)); |
| 104 |
|
| 105 |
if (subvol != NULL) |
| 106 |
g_print (" Had subvol superblock option: %s\n", subvol); |
| 107 |
} |
| 108 |
|
| 109 |
g_print (" Threads:\n"); |
| 110 |
n_threads = g_list_model_get_n_items (threads); |
| 111 |
for (guint j = 0; j < n_threads; j++) |
| 112 |
{ |
| 113 |
g_autoptr(SysprofThreadInfo) thread = g_list_model_get_item (threads, j); |
| 114 |
|
| 115 |
g_print (" Thread-Id: %i%s\n", |
| 116 |
sysprof_thread_info_get_thread_id (thread), |
| 117 |
sysprof_thread_info_is_main_thread (thread) ? " [Main Thread]" : ""); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
return 0; |
| 122 |
} |