| 1 |
/* test-list-counters.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 |
static const GOptionEntry entries[] = { |
| 26 |
{ 0 } |
| 27 |
}; |
| 28 |
|
| 29 |
int |
| 30 |
main (int argc, |
| 31 |
char *argv[]) |
| 32 |
{ |
| 33 |
g_autoptr(GOptionContext) context = g_option_context_new ("- list cpu information from capture"); |
| 34 |
g_autoptr(SysprofDocumentLoader) loader = NULL; |
| 35 |
g_autoptr(SysprofDocument) document = NULL; |
| 36 |
g_autoptr(GListModel) model = NULL; |
| 37 |
g_autoptr(GError) error = NULL; |
| 38 |
guint n_items; |
| 39 |
|
| 40 |
g_option_context_add_main_entries (context, entries, NULL); |
| 41 |
|
| 42 |
if (!g_option_context_parse (context, &argc, &argv, &error)) |
| 43 |
{ |
| 44 |
g_printerr ("%s\n", error->message); |
| 45 |
return 1; |
| 46 |
} |
| 47 |
|
| 48 |
if (argc < 2) |
| 49 |
{ |
| 50 |
g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]); |
| 51 |
return 1; |
| 52 |
} |
| 53 |
|
| 54 |
loader = sysprof_document_loader_new (argv[1]); |
| 55 |
sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ()); |
| 56 |
|
| 57 |
if (!(document = sysprof_document_loader_load (loader, NULL, &error))) |
| 58 |
{ |
| 59 |
g_printerr ("Failed to open capture: %s\n", error->message); |
| 60 |
return 1; |
| 61 |
} |
| 62 |
|
| 63 |
model = sysprof_document_list_cpu_info (document); |
| 64 |
n_items = g_list_model_get_n_items (model); |
| 65 |
|
| 66 |
for (guint i = 0; i < n_items; i++) |
| 67 |
{ |
| 68 |
g_autoptr(SysprofCpuInfo) cpu_info = g_list_model_get_item (model, i); |
| 69 |
|
| 70 |
g_print ("processor %u: %s\n", |
| 71 |
sysprof_cpu_info_get_id (cpu_info), |
| 72 |
sysprof_cpu_info_get_model_name (cpu_info)); |
| 73 |
} |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |