mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-profile: create writer and test record
This commit is contained in:
@ -20,18 +20,36 @@
|
|||||||
|
|
||||||
#include <sysprof-profile.h>
|
#include <sysprof-profile.h>
|
||||||
|
|
||||||
|
static GMainLoop *main_loop;
|
||||||
static char *capture_file;
|
static char *capture_file;
|
||||||
static const GOptionEntry entries[] = {
|
static const GOptionEntry entries[] = {
|
||||||
{ "capture", 'c', 0, G_OPTION_ARG_FILENAME, &capture_file, "The file to capture into", "CAPTURE" },
|
{ "capture", 'c', 0, G_OPTION_ARG_FILENAME, &capture_file, "The file to capture into", "CAPTURE" },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
record_cb (GObject *object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_autoptr(GError) error = NULL;
|
||||||
|
g_autoptr(SysprofRecording) recording = sysprof_profiler_record_finish (SYSPROF_PROFILER (object), result, &error);
|
||||||
|
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert_nonnull (recording);
|
||||||
|
g_assert_true (SYSPROF_IS_RECORDING (recording));
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
g_autoptr(GOptionContext) context = g_option_context_new ("- Tests the SysprofProfiler");
|
g_autoptr(GOptionContext) context = g_option_context_new ("- Tests the SysprofProfiler");
|
||||||
|
g_autoptr(SysprofProfiler) profiler = NULL;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
SysprofCaptureWriter *writer = NULL;
|
||||||
|
|
||||||
|
main_loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
g_option_context_add_main_entries (context, entries, NULL);
|
g_option_context_add_main_entries (context, entries, NULL);
|
||||||
|
|
||||||
@ -41,5 +59,18 @@ main (int argc,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (capture_file == NULL)
|
||||||
|
writer = sysprof_capture_writer_new ("capture.syscap", 0);
|
||||||
|
else
|
||||||
|
writer = sysprof_capture_writer_new (capture_file, 0);
|
||||||
|
|
||||||
|
profiler = sysprof_profiler_new ();
|
||||||
|
|
||||||
|
sysprof_profiler_record_async (profiler, writer, NULL, record_cb, NULL);
|
||||||
|
|
||||||
|
g_main_loop_run (main_loop);
|
||||||
|
|
||||||
|
g_clear_pointer (&writer, sysprof_capture_writer_unref);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user