mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
tests: add decode-only test
Useful to test that we can decode symbols from a capture properly.
This commit is contained in:
@ -23,6 +23,11 @@ test_addr_map = executable('test-addr-map',
|
|||||||
dependencies: test_deps,
|
dependencies: test_deps,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
test_addr_decode = executable('test-addr-decode', 'test-addr-decode.c',
|
||||||
|
c_args: test_cflags,
|
||||||
|
dependencies: test_deps,
|
||||||
|
)
|
||||||
|
|
||||||
test_capture = executable('test-capture', 'test-capture.c',
|
test_capture = executable('test-capture', 'test-capture.c',
|
||||||
c_args: test_cflags,
|
c_args: test_cflags,
|
||||||
dependencies: test_deps,
|
dependencies: test_deps,
|
||||||
|
|||||||
78
src/tests/test-addr-decode.c
Normal file
78
src/tests/test-addr-decode.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include <fcntl.h>
|
||||||
|
#include <sysprof.h>
|
||||||
|
|
||||||
|
#include "sysprof-platform.h"
|
||||||
|
#include "sysprof-capture-symbol-resolver.h"
|
||||||
|
|
||||||
|
gint
|
||||||
|
main (gint argc,
|
||||||
|
gchar *argv[])
|
||||||
|
{
|
||||||
|
g_autoptr(SysprofCaptureReader) reader = NULL;
|
||||||
|
g_autoptr(SysprofSymbolResolver) resolver = NULL;
|
||||||
|
g_autoptr(GError) error = NULL;
|
||||||
|
SysprofCaptureFrameType type;
|
||||||
|
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(reader = sysprof_capture_reader_new (argv[1], &error)))
|
||||||
|
{
|
||||||
|
g_printerr ("%s\n", error->message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolver = sysprof_capture_symbol_resolver_new ();
|
||||||
|
sysprof_symbol_resolver_load (resolver, reader);
|
||||||
|
|
||||||
|
sysprof_capture_reader_reset (reader);
|
||||||
|
|
||||||
|
while (sysprof_capture_reader_peek_type (reader, &type))
|
||||||
|
{
|
||||||
|
if (type == SYSPROF_CAPTURE_FRAME_SAMPLE)
|
||||||
|
{
|
||||||
|
const SysprofCaptureSample *sample;
|
||||||
|
SysprofAddressContext last_context = SYSPROF_ADDRESS_CONTEXT_NONE;
|
||||||
|
|
||||||
|
if ((sample = sysprof_capture_reader_read_sample (reader)))
|
||||||
|
{
|
||||||
|
for (guint i = 0; i < sample->n_addrs; i++)
|
||||||
|
{
|
||||||
|
g_autofree gchar *name = NULL;
|
||||||
|
SysprofAddressContext context;
|
||||||
|
GQuark tag = 0;
|
||||||
|
|
||||||
|
if (sysprof_address_is_context_switch (sample->addrs[i], &context))
|
||||||
|
{
|
||||||
|
last_context = context;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = sysprof_symbol_resolver_resolve_with_context (resolver,
|
||||||
|
sample->frame.time,
|
||||||
|
sample->frame.pid,
|
||||||
|
last_context,
|
||||||
|
sample->addrs[i],
|
||||||
|
&tag);
|
||||||
|
|
||||||
|
g_print ("%u: %s [%s]\n",
|
||||||
|
i,
|
||||||
|
name ? name : "-- missing --",
|
||||||
|
tag ? g_quark_to_string (tag) : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
g_print ("======\n");
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sysprof_capture_reader_skip (reader))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user