tree: start on massive tree refactor

The big thing going on here is that we are going to split up the libraries
a bit better, and remove GObject from the capture library. The libsysprof
library will bring in the capture library statically, so we can export the
symbols we want.

Eventually, we will bump the version to sysprof-3, but not yet.
This commit is contained in:
Christian Hergert
2019-05-07 20:52:05 -07:00
parent 5323cffdb3
commit 1708ad1b48
193 changed files with 1400 additions and 1136 deletions

20
src/tools/meson.build Normal file
View File

@ -0,0 +1,20 @@
sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c',
dependencies: libsysprof_dep,
install_dir: get_option('bindir'),
install: true,
)
sysprof_cat = executable('sysprof-cat', 'sysprof-cat.c',
dependencies: libsysprof_capture_dep,
install_dir: get_option('bindir'),
install: true,
pie: true,
)
sysprof_dump = executable('sysprof-dump', 'sysprof-dump.c',
dependencies: libsysprof_capture_dep,
install_dir: get_option('bindir'),
install: true,
pie: true,
)

430
src/tools/sysprof-cat.c Normal file
View File

@ -0,0 +1,430 @@
/* sysprof-cat.c
*
* Copyright 2018-2019 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "sysprof-cat"
#include "config.h"
#include <glib/gstdio.h>
#include <stdlib.h>
#include <sysprof-capture.h>
#include <unistd.h>
typedef struct
{
guint64 src;
guint64 dst;
} TranslateItem;
enum {
TRANSLATE_ADDR,
TRANSLATE_CTR,
N_TRANSLATE
};
static GArray *translate_table[N_TRANSLATE];
static void
translate_table_clear (guint table)
{
g_clear_pointer (&translate_table[table], g_array_unref);
}
static gint
compare_by_src (gconstpointer a,
gconstpointer b)
{
const TranslateItem *itema = a;
const TranslateItem *itemb = a;
if (itema->src < itemb->src)
return -1;
else if (itema->src > itemb->src)
return 1;
else
return 0;
}
static void
translate_table_sort (guint table)
{
if (translate_table[table])
g_array_sort (translate_table[table], compare_by_src);
}
static void
translate_table_add (guint table,
guint64 src,
guint64 dst)
{
TranslateItem item = { src, dst };
if (translate_table[table] == NULL)
translate_table[table] = g_array_new (FALSE, FALSE, sizeof (TranslateItem));
g_array_append_val (translate_table[table], item);
}
static guint64
translate_table_translate (guint table,
guint64 src)
{
const TranslateItem *item;
TranslateItem key = { src, 0 };
if (!translate_table[table])
return src;
item = bsearch (&key,
translate_table[table]->data,
translate_table[table]->len,
sizeof (TranslateItem),
compare_by_src);
return item != NULL ? item->dst : src;
}
gint
main (gint argc,
gchar *argv[])
{
g_autoptr(SpCaptureWriter) writer = NULL;
g_autofree gchar *contents = NULL;
g_autofree gchar *tmpname = NULL;
gint64 first_start_time = G_MAXINT64;
gint64 end_time = -1;
gsize len;
gint fd;
if (argc == 1)
return 0;
if (isatty (STDOUT_FILENO))
{
g_printerr ("stdout is a TTY, refusing to write binary data to stdout.\n");
return EXIT_FAILURE;
}
for (guint i = 1; i < argc; i++)
{
if (!g_file_test (argv[i], G_FILE_TEST_IS_REGULAR))
{
g_printerr ("\"%s\" is not a regular file.\n", argv[i]);
return EXIT_FAILURE;
}
}
if (-1 == (fd = g_file_open_tmp (".sysprof-cat-XXXXXX", &tmpname, NULL)))
{
g_printerr ("Failed to create memfd for capture file.\n");
return EXIT_FAILURE;
}
writer = sp_capture_writer_new_from_fd (fd, 4096*4);
for (guint i = 1; i < argc; i++)
{
g_autoptr(GError) error = NULL;
g_autoptr(SpCaptureReader) reader = sp_capture_reader_new (argv[i], &error);
SpCaptureFrameType type;
gint64 start_time;
if (reader == NULL)
{
g_printerr ("Failed to create reader for \"%s\": %s\n",
argv[i], error->message);
return EXIT_FAILURE;
}
translate_table_clear (TRANSLATE_CTR);
translate_table_clear (TRANSLATE_ADDR);
start_time = sp_capture_reader_get_start_time (reader);
if (start_time < first_start_time)
first_start_time = start_time;
while (sp_capture_reader_peek_type (reader, &type))
{
SpCaptureFrame fr;
if (sp_capture_reader_peek_frame (reader, &fr))
{
if (fr.time > end_time)
end_time = fr.time;
}
switch (type)
{
case SP_CAPTURE_FRAME_TIMESTAMP:
{
const SpCaptureTimestamp *frame;
if (!(frame = sp_capture_reader_read_timestamp (reader)))
goto panic;
sp_capture_writer_add_timestamp (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid);
break;
}
case SP_CAPTURE_FRAME_MAP:
{
const SpCaptureMap *frame;
if (!(frame = sp_capture_reader_read_map (reader)))
goto panic;
sp_capture_writer_add_map (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid,
frame->start,
frame->end,
frame->offset,
frame->inode,
frame->filename);
break;
}
case SP_CAPTURE_FRAME_MARK:
{
const SpCaptureMark *frame;
if (!(frame = sp_capture_reader_read_mark (reader)))
goto panic;
sp_capture_writer_add_mark (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid,
frame->duration,
frame->group,
frame->name,
frame->message);
if (frame->frame.time + frame->duration > end_time)
end_time = frame->frame.time + frame->duration;
break;
}
case SP_CAPTURE_FRAME_PROCESS:
{
const SpCaptureProcess *frame;
if (!(frame = sp_capture_reader_read_process (reader)))
goto panic;
sp_capture_writer_add_process (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid,
frame->cmdline);
break;
}
case SP_CAPTURE_FRAME_FORK:
{
const SpCaptureFork *frame;
if (!(frame = sp_capture_reader_read_fork (reader)))
goto panic;
sp_capture_writer_add_fork (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid,
frame->child_pid);
break;
}
case SP_CAPTURE_FRAME_EXIT:
{
const SpCaptureExit *frame;
if (!(frame = sp_capture_reader_read_exit (reader)))
goto panic;
sp_capture_writer_add_exit (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid);
break;
}
case SP_CAPTURE_FRAME_JITMAP:
{
GHashTable *jitmap;
GHashTableIter iter;
const gchar *name;
guint64 addr;
if (!(jitmap = sp_capture_reader_read_jitmap (reader)))
goto panic;
g_hash_table_iter_init (&iter, jitmap);
while (g_hash_table_iter_next (&iter, (gpointer *)&addr, (gpointer *)&name))
{
guint64 replace = sp_capture_writer_add_jitmap (writer, name);
/* We need to keep a table of replacement addresses so that
* we can translate the samples into the destination address
* space that we synthesized for the address identifier.
*/
translate_table_add (TRANSLATE_ADDR, addr, replace);
}
translate_table_sort (TRANSLATE_ADDR);
g_hash_table_unref (jitmap);
break;
}
case SP_CAPTURE_FRAME_SAMPLE:
{
const SpCaptureSample *frame;
if (!(frame = sp_capture_reader_read_sample (reader)))
goto panic;
{
SpCaptureAddress addrs[frame->n_addrs];
for (guint z = 0; z < frame->n_addrs; z++)
addrs[z] = translate_table_translate (TRANSLATE_ADDR, frame->addrs[z]);
sp_capture_writer_add_sample (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid,
addrs,
frame->n_addrs);
}
break;
}
case SP_CAPTURE_FRAME_CTRDEF:
{
const SpCaptureFrameCounterDefine *frame;
if (!(frame = sp_capture_reader_read_counter_define (reader)))
goto panic;
{
g_autoptr(GArray) counter = g_array_new (FALSE, FALSE, sizeof (SpCaptureCounter));
for (guint z = 0; z < frame->n_counters; z++)
{
SpCaptureCounter c = frame->counters[z];
guint src = c.id;
c.id = sp_capture_writer_request_counter (writer, 1);
if (c.id != src)
translate_table_add (TRANSLATE_CTR, src, c.id);
g_array_append_val (counter, c);
}
sp_capture_writer_define_counters (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid,
(gpointer)counter->data,
counter->len);
translate_table_sort (TRANSLATE_CTR);
}
break;
}
case SP_CAPTURE_FRAME_CTRSET:
{
const SpCaptureFrameCounterSet *frame;
if (!(frame = sp_capture_reader_read_counter_set (reader)))
goto panic;
{
g_autoptr(GArray) ids = g_array_new (FALSE, FALSE, sizeof (guint));
g_autoptr(GArray) values = g_array_new (FALSE, FALSE, sizeof (SpCaptureCounterValue));
for (guint z = 0; z < frame->n_values; z++)
{
const SpCaptureCounterValues *v = &frame->values[z];
for (guint y = 0; y < G_N_ELEMENTS (v->ids); y++)
{
if (v->ids[y])
{
guint dst = translate_table_translate (TRANSLATE_CTR, v->ids[y]);
SpCaptureCounterValue value = v->values[y];
g_array_append_val (ids, dst);
g_array_append_val (values, value);
}
}
}
g_assert (ids->len == values->len);
sp_capture_writer_set_counters (writer,
frame->frame.time,
frame->frame.cpu,
frame->frame.pid,
(const guint *)(gpointer)ids->data,
(const SpCaptureCounterValue *)(gpointer)values->data,
ids->len);
}
break;
}
default:
break;
}
}
}
sp_capture_writer_flush (writer);
/* do this after flushing as it uses pwrite() to replace data */
_sp_capture_writer_set_time_range (writer, first_start_time, end_time);
if (g_file_get_contents (tmpname, &contents, &len, NULL))
write (STDOUT_FILENO, contents, len);
g_unlink (tmpname);
return EXIT_SUCCESS;
panic:
g_printerr ("There was a failure to read the stream.\n");
if (tmpname)
g_unlink (tmpname);
return EXIT_FAILURE;
}

261
src/tools/sysprof-cli.c Normal file
View File

@ -0,0 +1,261 @@
/* sysprof-cli.c
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "config.h"
#include <fcntl.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/eventfd.h>
#include <sys/types.h>
#include <signal.h>
#include <sysprof.h>
static GMainLoop *main_loop;
static SpProfiler *profiler;
static int efd = -1;
static int exit_code = EXIT_SUCCESS;
static void
signal_handler (int signum)
{
gint64 val = 1;
write (efd, &val, sizeof val);
}
static gboolean
dispatch (GSource *source,
GSourceFunc callback,
gpointer callback_data)
{
sp_profiler_stop (profiler);
g_main_loop_quit (main_loop);
return G_SOURCE_REMOVE;
}
static GSourceFuncs source_funcs = {
NULL, NULL, dispatch, NULL
};
static void
profiler_stopped (SpProfiler *profiler_,
GMainLoop *main_loop_)
{
g_main_loop_quit (main_loop_);
}
static void
profiler_failed (SpProfiler *profiler_,
const GError *reason,
GMainLoop *main_loop_)
{
g_assert (SP_IS_PROFILER (profiler_));
g_assert (reason != NULL);
g_printerr ("Failure: %s\n", reason->message);
exit_code = EXIT_FAILURE;
}
gint
main (gint argc,
gchar *argv[])
{
SpCaptureWriter *writer;
SpSource *source;
GMainContext *main_context;
GOptionContext *context;
const gchar *filename = "capture.syscap";
GError *error = NULL;
GSource *gsource;
gchar *command = NULL;
gboolean no_memory = FALSE;
gboolean no_cpu = FALSE;
gboolean version = FALSE;
gboolean force = FALSE;
int pid = -1;
int fd;
int flags;
GOptionEntry entries[] = {
{ "pid", 'p', 0, G_OPTION_ARG_INT, &pid, N_("Make sysprof specific to a task"), N_("PID") },
{ "command", 'c', 0, G_OPTION_ARG_STRING, &command, N_("Run a command and profile the process"), N_("COMMAND") },
{ "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Force overwrite the capture file") },
{ "no-cpu", 0, 0, G_OPTION_ARG_NONE, &no_cpu, N_("Disable recording of CPU statistics") },
{ "no-memory", 0, 0, G_OPTION_ARG_NONE, &no_memory, N_("Disable recording of memory statistics") },
{ "version", 0, 0, G_OPTION_ARG_NONE, &version, N_("Print the sysprof-cli version and exit") },
{ NULL }
};
sp_clock_init ();
context = g_option_context_new (_("[CAPTURE_FILE] — Sysprof"));
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
if (!g_option_context_parse (context, &argc, &argv, &error))
{
g_printerr ("%s\n", error->message);
return EXIT_FAILURE;
}
if (version)
{
g_print ("Sysprof "PACKAGE_VERSION"\n");
return EXIT_SUCCESS;
}
if (argc > 2)
{
gint i;
g_printerr (_("Too many arguments were passed to sysprof-cli:"));
for (i = 2; i < argc; i++)
g_printerr (" %s", argv [i]);
g_printerr ("\n");
return EXIT_FAILURE;
}
efd = eventfd (0, O_CLOEXEC);
main_loop = g_main_loop_new (NULL, FALSE);
gsource = g_source_new (&source_funcs, sizeof (GSource));
g_source_add_unix_fd (gsource, efd, G_IO_IN);
g_source_attach (gsource, NULL);
profiler = sp_local_profiler_new ();
g_signal_connect (profiler,
"failed",
G_CALLBACK (profiler_failed),
main_loop);
g_signal_connect (profiler,
"stopped",
G_CALLBACK (profiler_stopped),
main_loop);
if (argc == 2)
filename = argv[1];
flags = O_CREAT | O_RDWR | O_CLOEXEC;
if (!force)
{
/* if we don't force overwrite we want to ensure the file doesn't exist
* and never overwrite it. O_EXCL will prevent opening in that case */
flags |= O_EXCL;
if (g_file_test (filename, G_FILE_TEST_EXISTS))
{
/* Translators: %s is a file name. */
g_printerr (_("%s exists. Use --force to overwrite\n"), filename);
return EXIT_FAILURE;
}
}
if (-1 == (fd = g_open (filename, flags, 0640)))
{
g_printerr ("Failed to open %s\n", filename);
return EXIT_FAILURE;
}
if (command != NULL)
{
g_auto(GStrv) child_argv = NULL;
gint child_argc;
if (!g_shell_parse_argv (command, &child_argc, &child_argv, &error))
{
g_printerr ("Invalid command: %s\n", error->message);
return EXIT_FAILURE;
}
if (!g_spawn_async (NULL, child_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &error))
{
g_printerr ("Invalid command: %s\n", error->message);
return EXIT_FAILURE;
}
/* Stop the process until we are setup */
if (0 != kill (pid, SIGSTOP))
{
g_printerr ("Failed to pause inferior during setup\n");
return EXIT_FAILURE;
}
}
writer = sp_capture_writer_new_from_fd (fd, 0);
sp_profiler_set_writer (profiler, writer);
source = sp_proc_source_new ();
sp_profiler_add_source (profiler, source);
g_object_unref (source);
source = sp_perf_source_new ();
sp_profiler_add_source (profiler, source);
g_object_unref (source);
if (!no_cpu)
{
source = sp_hostinfo_source_new ();
sp_profiler_add_source (profiler, source);
g_object_unref (source);
}
if (!no_memory)
{
source = sp_memory_source_new ();
sp_profiler_add_source (profiler, source);
g_object_unref (source);
}
if (pid != -1)
{
sp_profiler_set_whole_system (profiler, FALSE);
sp_profiler_add_pid (profiler, pid);
}
signal (SIGINT, signal_handler);
signal (SIGTERM, signal_handler);
sp_profiler_start (profiler);
/* Restore the process if we stopped it */
if (command)
kill (pid, SIGCONT);
g_printerr ("Recording, press ^C to exit\n");
g_main_loop_run (main_loop);
main_context = g_main_loop_get_context (main_loop);
while (g_main_context_pending (main_context))
g_main_context_iteration (main_context, FALSE);
close (efd);
g_clear_pointer (&writer, sp_capture_writer_unref);
g_clear_object (&profiler);
g_clear_pointer (&main_loop, g_main_loop_unref);
g_clear_pointer (&context, g_option_context_free);
return EXIT_SUCCESS;
}

241
src/tools/sysprof-dump.c Normal file
View File

@ -0,0 +1,241 @@
/* sysprof-dump.c
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <stdio.h>
#include <stdlib.h>
#include <sysprof-capture.h>
#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
gint
main (gint argc,
gchar *argv[])
{
SpCaptureReader *reader;
SpCaptureFrameType type;
GHashTable *ctrtypes;
GError *error = NULL;
gint64 begin_time;
gint64 end_time;
if (argc != 2)
{
g_printerr ("usage: %s FILENAME\n", argv[0]);
return EXIT_FAILURE;
}
reader = sp_capture_reader_new (argv[1], &error);
ctrtypes = g_hash_table_new (NULL, NULL);
begin_time = sp_capture_reader_get_start_time (reader);
#define SET_CTR_TYPE(i,t) g_hash_table_insert(ctrtypes, GINT_TO_POINTER(i), GINT_TO_POINTER(t))
#define GET_CTR_TYPE(i) GPOINTER_TO_INT(g_hash_table_lookup(ctrtypes, GINT_TO_POINTER(i)))
if (reader == NULL)
{
g_printerr ("%s\n", error->message);
return EXIT_FAILURE;
}
begin_time = sp_capture_reader_get_start_time (reader);
end_time = sp_capture_reader_get_end_time (reader);
g_print ("Capture Time Range: %"G_GUINT64_FORMAT" to %"G_GUINT64_FORMAT" (%lf)\n",
begin_time, end_time, (end_time - begin_time) / (gdouble)NSEC_PER_SEC);
while (sp_capture_reader_peek_type (reader, &type))
{
switch (type)
{
case SP_CAPTURE_FRAME_EXIT:
{
const SpCaptureExit *ex = sp_capture_reader_read_exit (reader);
if (ex == NULL)
return EXIT_FAILURE;
g_print ("EXIT: pid=%d\n", ex->frame.pid);
break;
}
case SP_CAPTURE_FRAME_FORK:
{
const SpCaptureFork *fk = sp_capture_reader_read_fork (reader);
if (fk == NULL)
return EXIT_FAILURE;
g_print ("FORK: pid=%d child_pid=%d\n", fk->frame.pid, fk->child_pid);
break;
}
case SP_CAPTURE_FRAME_JITMAP:
{
g_autoptr(GHashTable) ret = sp_capture_reader_read_jitmap (reader);
GHashTableIter iter;
SpCaptureAddress addr;
const gchar *str;
if (ret == NULL)
return EXIT_FAILURE;
g_print ("JITMAP:\n");
g_hash_table_iter_init (&iter, ret);
while (g_hash_table_iter_next (&iter, (gpointer *)&addr, (gpointer *)&str))
g_print (" "SP_CAPTURE_ADDRESS_FORMAT" : %s\n", addr, str);
break;
}
case SP_CAPTURE_FRAME_MAP:
{
const SpCaptureMap *map = sp_capture_reader_read_map (reader);
g_print ("MAP: pid=%d time=%"G_GINT64_FORMAT"\n"
" start = %"G_GUINT64_FORMAT"\n"
" end = %"G_GUINT64_FORMAT"\n"
" offset = %"G_GUINT64_FORMAT"\n"
" inode = %"G_GUINT64_FORMAT"\n"
" filename = %s\n",
map->frame.pid, map->frame.time,
map->start, map->end, map->offset, map->inode, map->filename);
break;
}
case SP_CAPTURE_FRAME_MARK:
{
const SpCaptureMark *mark = sp_capture_reader_read_mark (reader);
gdouble ptime = (mark->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
g_print ("MARK: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n"
" group = %s\n"
" name = %s\n"
" duration = %"G_GUINT64_FORMAT"\n"
" message = %s\n",
mark->frame.pid, mark->frame.time, ptime,
mark->group, mark->name, mark->duration, mark->message);
break;
}
case SP_CAPTURE_FRAME_PROCESS:
{
const SpCaptureProcess *pr = sp_capture_reader_read_process (reader);
if (pr == NULL)
perror ("Failed to read process");
g_print ("PROCESS: pid=%d cmdline=%s time=%"G_GINT64_FORMAT"\n", pr->frame.pid, pr->cmdline, pr->frame.time);
break;
}
case SP_CAPTURE_FRAME_SAMPLE:
{
const SpCaptureSample *s = sp_capture_reader_read_sample (reader);
gdouble ptime = (s->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
guint i;
g_print ("SAMPLE: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n", s->frame.pid, s->frame.time, ptime);
for (i = 0; i < s->n_addrs; i++)
g_print (" "SP_CAPTURE_ADDRESS_FORMAT"\n", s->addrs[i]);
break;
}
case SP_CAPTURE_FRAME_TIMESTAMP:
{
const SpCaptureTimestamp *ts = sp_capture_reader_read_timestamp (reader);
g_print ("TIMESTAMP: pid=%d time=%"G_GINT64_FORMAT"\n", ts->frame.pid, ts->frame.time);
break;
}
case SP_CAPTURE_FRAME_CTRDEF:
{
const SpCaptureFrameCounterDefine *def = sp_capture_reader_read_counter_define (reader);
guint i;
g_print ("NEW COUNTERS: pid=%d time=%"G_GINT64_FORMAT"\n", def->frame.pid, def->frame.time);
for (i = 0; i < def->n_counters; i++)
{
const SpCaptureCounter *ctr = &def->counters[i];
SET_CTR_TYPE (ctr->id, ctr->type);
g_print (" COUNTER(%d): %s\n %s\n %s\n\n",
ctr->id,
ctr->category,
ctr->name,
ctr->description);
}
}
break;
case SP_CAPTURE_FRAME_CTRSET:
{
const SpCaptureFrameCounterSet *set = sp_capture_reader_read_counter_set (reader);
guint i;
g_print ("SET COUNTERS: pid=%d time=%"G_GINT64_FORMAT"\n", set->frame.pid, set->frame.time);
for (i = 0; i < set->n_values; i++)
{
const SpCaptureCounterValues *values = &set->values[i];
guint j;
for (j = 0; j < G_N_ELEMENTS (values->ids); j++)
{
if (values->ids[j])
{
if (GET_CTR_TYPE (values->ids[j]) == SP_CAPTURE_COUNTER_INT64)
g_print (" COUNTER(%d): %"G_GINT64_FORMAT"\n",
values->ids[j],
values->values[j].v64);
else if (GET_CTR_TYPE (values->ids[j]) == SP_CAPTURE_COUNTER_DOUBLE)
g_print (" COUNTER(%d): %lf\n",
values->ids[j],
values->values[j].vdbl);
}
}
}
}
break;
default:
g_print ("Skipping unknown frame type: (%d): ", type);
if (!sp_capture_reader_skip (reader))
{
g_print ("Failed\n");
return EXIT_FAILURE;
}
g_print ("Success\n");
break;
}
}
return EXIT_SUCCESS;
}