mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
This is a major redesign a modernization of Sysprof. The core data structures and design are largely the same, but it has been ported to Gtk3 and has lots of additions that should make your profiling experience smoother. Especially for those that are new to profiling. There are some very simple help docs added, but we really need the experts to come in and write some documentation here.
154 lines
4.2 KiB
C
154 lines
4.2 KiB
C
/* sysprof-dump.c
|
|
*
|
|
* Copyright (C) 2016 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/>.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "sp-capture-reader.h"
|
|
|
|
gint
|
|
main (gint argc,
|
|
gchar *argv[])
|
|
{
|
|
SpCaptureReader *reader;
|
|
SpCaptureFrameType type;
|
|
GError *error = NULL;
|
|
|
|
if (argc != 2)
|
|
{
|
|
g_printerr ("usage: %s FILENAME\n", argv[0]);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
reader = sp_capture_reader_new (argv[1], &error);
|
|
|
|
if (reader == NULL)
|
|
{
|
|
g_printerr ("%s\n", error->message);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
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\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->start, map->end, map->offset, map->inode, map->filename);
|
|
|
|
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\n", pr->frame.pid, pr->cmdline);
|
|
break;
|
|
}
|
|
|
|
case SP_CAPTURE_FRAME_SAMPLE:
|
|
{
|
|
const SpCaptureSample *s = sp_capture_reader_read_sample (reader);
|
|
guint i;
|
|
|
|
g_print ("SAMPLE: pid=%d\n", s->frame.pid);
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|