| 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 gboolean show_values; |
| 26 |
static const GOptionEntry entries[] = { |
| 27 |
{ "values", 'v', 0, G_OPTION_ARG_NONE, &show_values, "Show values along with counter information" }, |
| 28 |
{ 0 } |
| 29 |
}; |
| 30 |
|
| 31 |
int |
| 32 |
main (int argc, |
| 33 |
char *argv[]) |
| 34 |
{ |
| 35 |
g_autoptr(GOptionContext) context = g_option_context_new ("- list counter information from capture"); |
| 36 |
g_autoptr(SysprofDocumentLoader) loader = NULL; |
| 37 |
g_autoptr(SysprofDocument) document = NULL; |
| 38 |
g_autoptr(GListModel) model = NULL; |
| 39 |
g_autoptr(GError) error = NULL; |
| 40 |
guint n_items; |
| 41 |
|
| 42 |
g_option_context_add_main_entries (context, entries, NULL); |
| 43 |
|
| 44 |
if (!g_option_context_parse (context, &argc, &argv, &error)) |
| 45 |
{ |
| 46 |
g_printerr ("%s\n", error->message); |
| 47 |
return 1; |
| 48 |
} |
| 49 |
|
| 50 |
if (argc < 2) |
| 51 |
{ |
| 52 |
g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]); |
| 53 |
return 1; |
| 54 |
} |
| 55 |
|
| 56 |
loader = sysprof_document_loader_new (argv[1]); |
| 57 |
sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ()); |
| 58 |
|
| 59 |
if (!(document = sysprof_document_loader_load (loader, NULL, &error))) |
| 60 |
{ |
| 61 |
g_printerr ("Failed to open capture: %s\n", error->message); |
| 62 |
return 1; |
| 63 |
} |
| 64 |
|
| 65 |
model = sysprof_document_list_counters (document); |
| 66 |
n_items = g_list_model_get_n_items (model); |
| 67 |
|
| 68 |
for (guint i = 0; i < n_items; i++) |
| 69 |
{ |
| 70 |
g_autoptr(SysprofDocumentCounter) counter = g_list_model_get_item (model, i); |
| 71 |
|
| 72 |
g_print ("%d<%s> %s.%s: %s (%u values)\n", |
| 73 |
sysprof_document_counter_get_id (counter), |
| 74 |
sysprof_document_counter_get_value_type (counter) == G_TYPE_INT64 ? "i64" : "f64", |
| 75 |
sysprof_document_counter_get_category (counter), |
| 76 |
sysprof_document_counter_get_name (counter), |
| 77 |
sysprof_document_counter_get_description (counter), |
| 78 |
sysprof_document_counter_get_n_values (counter)); |
| 79 |
|
| 80 |
if (show_values) |
| 81 |
{ |
| 82 |
guint n_values = sysprof_document_counter_get_n_values (counter); |
| 83 |
|
| 84 |
if (sysprof_document_counter_get_value_type (counter) == G_TYPE_INT64) |
| 85 |
{ |
| 86 |
for (guint j = 0; j < n_values; j++) |
| 87 |
{ |
| 88 |
gint64 t; |
| 89 |
gint64 v = sysprof_document_counter_get_value_int64 (counter, j, &t); |
| 90 |
|
| 91 |
g_print (" %03u: %"G_GINT64_FORMAT": %"G_GINT64_FORMAT"\n", j, t, v); |
| 92 |
} |
| 93 |
} |
| 94 |
else if (sysprof_document_counter_get_value_type (counter) == G_TYPE_DOUBLE) |
| 95 |
{ |
| 96 |
for (guint j = 0; j < n_values; j++) |
| 97 |
{ |
| 98 |
gint64 t; |
| 99 |
double v = sysprof_document_counter_get_value_double (counter, j, &t); |
| 100 |
|
| 101 |
g_print (" %03u: %"G_GINT64_FORMAT": %lf\n", j, t, v); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
return 0; |
| 108 |
} |