mirror of
https://github.com/brl/mutter.git
synced 2024-11-21 23:50:41 -05:00
profiler: Support setting output filename
So we can have some control over where the file will be saved. https://gitlab.gnome.org/GNOME/mutter/merge_requests/197
This commit is contained in:
parent
53748e3da7
commit
e741cab3f4
@ -30,6 +30,22 @@
|
||||
#define COGL_TRACE_OUTPUT_FILE "cogl-trace-sp-capture.syscap"
|
||||
#define BUFFER_LENGTH (4096 * 4)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fd;
|
||||
char *filename;
|
||||
} TraceData;
|
||||
|
||||
static void
|
||||
trace_data_free (gpointer user_data)
|
||||
{
|
||||
TraceData *data = user_data;
|
||||
|
||||
data->fd = -1;
|
||||
g_clear_pointer (&data->filename, g_free);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static void cogl_trace_thread_context_free (gpointer data);
|
||||
|
||||
GPrivate cogl_trace_thread_data = G_PRIVATE_INIT (cogl_trace_thread_context_free);
|
||||
@ -37,21 +53,26 @@ CoglTraceContext *cogl_trace_context;
|
||||
GMutex cogl_trace_mutex;
|
||||
|
||||
static CoglTraceContext *
|
||||
cogl_trace_context_new (int fd)
|
||||
cogl_trace_context_new (int fd,
|
||||
const char *filename)
|
||||
{
|
||||
CoglTraceContext *context;
|
||||
SysprofCaptureWriter *writer;
|
||||
|
||||
g_debug ("Initializing trace context with fd=%d", fd);
|
||||
|
||||
if (fd == -1)
|
||||
if (fd != -1)
|
||||
{
|
||||
writer = sysprof_capture_writer_new (COGL_TRACE_OUTPUT_FILE,
|
||||
BUFFER_LENGTH);
|
||||
g_debug ("Initializing trace context with fd=%d", fd);
|
||||
writer = sysprof_capture_writer_new_from_fd (fd, BUFFER_LENGTH);
|
||||
}
|
||||
else if (filename != NULL)
|
||||
{
|
||||
g_debug ("Initializing trace context with filename='%s'", filename);
|
||||
writer = sysprof_capture_writer_new (filename, BUFFER_LENGTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer = sysprof_capture_writer_new_from_fd (fd, BUFFER_LENGTH);
|
||||
g_debug ("Initializing trace context with default dilename");
|
||||
writer = sysprof_capture_writer_new (COGL_TRACE_OUTPUT_FILE, BUFFER_LENGTH);
|
||||
}
|
||||
|
||||
context = g_new0 (CoglTraceContext, 1);
|
||||
@ -67,11 +88,11 @@ cogl_trace_context_free (CoglTraceContext *trace_context)
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_trace_context (int fd)
|
||||
ensure_trace_context (TraceData *data)
|
||||
{
|
||||
g_mutex_lock (&cogl_trace_mutex);
|
||||
if (!cogl_trace_context)
|
||||
cogl_trace_context = cogl_trace_context_new (fd);
|
||||
cogl_trace_context = cogl_trace_context_new (data->fd, data->filename);
|
||||
g_mutex_unlock (&cogl_trace_mutex);
|
||||
}
|
||||
|
||||
@ -96,9 +117,9 @@ enable_tracing_idle_callback (gpointer user_data)
|
||||
{
|
||||
CoglTraceThreadContext *thread_context =
|
||||
g_private_get (&cogl_trace_thread_data);
|
||||
int fd = GPOINTER_TO_INT (user_data);
|
||||
TraceData *data = user_data;
|
||||
|
||||
ensure_trace_context (fd);
|
||||
ensure_trace_context (data);
|
||||
|
||||
if (thread_context)
|
||||
{
|
||||
@ -150,20 +171,43 @@ disable_tracing_idle_callback (gpointer user_data)
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
|
||||
int fd)
|
||||
static void
|
||||
set_tracing_enabled_on_thread (GMainContext *main_context,
|
||||
int fd,
|
||||
const char *filename)
|
||||
{
|
||||
TraceData *data;
|
||||
GSource *source;
|
||||
|
||||
data = g_new0 (TraceData, 1);
|
||||
data->fd = fd;
|
||||
data->filename = filename ? strdup (filename) : NULL;
|
||||
|
||||
source = g_idle_source_new ();
|
||||
|
||||
g_source_set_callback (source, enable_tracing_idle_callback, GINT_TO_POINTER (fd), NULL);
|
||||
g_source_set_callback (source,
|
||||
enable_tracing_idle_callback,
|
||||
data,
|
||||
trace_data_free);
|
||||
|
||||
g_source_attach (source, main_context);
|
||||
g_source_unref (source);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_set_tracing_enabled_on_thread_with_fd (GMainContext *main_context,
|
||||
int fd)
|
||||
{
|
||||
set_tracing_enabled_on_thread (main_context, fd, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
|
||||
const char *filename)
|
||||
{
|
||||
set_tracing_enabled_on_thread (main_context, -1, filename);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_set_tracing_disabled_on_thread (GMainContext *main_context)
|
||||
{
|
||||
@ -183,8 +227,15 @@ cogl_set_tracing_disabled_on_thread (GMainContext *main_context)
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
cogl_set_tracing_enabled_on_thread (void *data,
|
||||
int fd)
|
||||
cogl_set_tracing_enabled_on_thread_with_fd (void *data,
|
||||
int fd)
|
||||
{
|
||||
fprintf (stderr, "Tracing not enabled");
|
||||
}
|
||||
|
||||
void
|
||||
cogl_set_tracing_enabled_on_thread (void *data,
|
||||
const char *filename)
|
||||
{
|
||||
fprintf (stderr, "Tracing not enabled");
|
||||
}
|
||||
|
@ -51,8 +51,11 @@ extern GPrivate cogl_trace_thread_data;
|
||||
extern CoglTraceContext *cogl_trace_context;
|
||||
extern GMutex cogl_trace_mutex;
|
||||
|
||||
void cogl_set_tracing_enabled_on_thread_with_fd (GMainContext *main_context,
|
||||
int fd);
|
||||
|
||||
void cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
|
||||
int fd);
|
||||
const char *filename);
|
||||
|
||||
void cogl_set_tracing_disabled_on_thread (GMainContext *main_context);
|
||||
|
||||
@ -129,8 +132,10 @@ cogl_auto_trace_end_helper (CoglTraceHead **head)
|
||||
#define COGL_TRACE_END(Name) (void) 0
|
||||
#define COGL_TRACE_BEGIN_SCOPED(Name) (void) 0
|
||||
|
||||
void cogl_set_tracing_enabled_on_thread (void *data, int fd);
|
||||
|
||||
void cogl_set_tracing_enabled_on_thread_with_fd (void *data,
|
||||
int fd);
|
||||
void cogl_set_tracing_enabled_on_thread (void *data,
|
||||
const char *filename);
|
||||
void cogl_set_tracing_disabled_on_thread (void *data);
|
||||
|
||||
#endif /* HAVE_TRACING */
|
||||
|
Loading…
Reference in New Issue
Block a user