diff --git a/cogl/cogl/cogl-trace.c b/cogl/cogl/cogl-trace.c index cc724c984..3d47b2e92 100644 --- a/cogl/cogl/cogl-trace.c +++ b/cogl/cogl/cogl-trace.c @@ -338,6 +338,38 @@ cogl_trace_end (CoglTraceHead *head) g_free (head->description); } +void +cogl_trace_mark (const char *name, + const char *description) +{ + SysprofTimeStamp time; + CoglTraceContext *trace_context; + CoglTraceThreadContext *trace_thread_context; + + time = g_get_monotonic_time () * 1000; + trace_thread_context = g_private_get (&cogl_trace_thread_data); + trace_context = trace_thread_context->trace_context; + + g_mutex_lock (&cogl_trace_mutex); + if (!sysprof_capture_writer_add_mark (trace_context->writer, + time, + trace_thread_context->cpu_id, + trace_thread_context->pid, + 0, + trace_thread_context->group, + name, + description)) + { + /* XXX: g_main_context_get_thread_default() might be wrong, it probably + * needs to store the GMainContext in CoglTraceThreadContext when creating + * and use it here. + */ + if (errno == EPIPE) + cogl_set_tracing_disabled_on_thread (g_main_context_get_thread_default ()); + } + g_mutex_unlock (&cogl_trace_mutex); +} + void cogl_trace_describe (CoglTraceHead *head, const char *description) diff --git a/cogl/cogl/cogl-trace.h b/cogl/cogl/cogl-trace.h index 32935b56f..d0d1efc6f 100644 --- a/cogl/cogl/cogl-trace.h +++ b/cogl/cogl/cogl-trace.h @@ -86,6 +86,10 @@ COGL_EXPORT void cogl_trace_describe (CoglTraceHead *head, const char *description); +COGL_EXPORT void +cogl_trace_mark (const char *name, + const char *description); + static inline void cogl_auto_trace_end_helper (CoglTraceHead **head) { @@ -132,6 +136,17 @@ cogl_is_tracing_enabled (void) ScopedCoglTrace##Name = &CoglTrace##Name; \ } +#define COGL_TRACE_MESSAGE(name, ...) \ + G_STMT_START \ + { \ + if (cogl_is_tracing_enabled ()) \ + { \ + g_autofree char *CoglTraceMessage = g_strdup_printf (__VA_ARGS__); \ + cogl_trace_mark (name, CoglTraceMessage); \ + } \ + } \ + G_STMT_END + #else /* HAVE_PROFILER */ #include @@ -141,6 +156,7 @@ cogl_is_tracing_enabled (void) #define COGL_TRACE_DESCRIBE(Name, description) (void) 0 #define COGL_TRACE_SCOPED_ANCHOR(Name) (void) 0 #define COGL_TRACE_BEGIN_ANCHORED(Name, name) (void) 0 +#define COGL_TRACE_MESSAGE(name, ...) (void) 0 COGL_EXPORT gboolean cogl_start_tracing_with_path (const char *filename,