diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c index 936291ed3..5b3418a5a 100644 --- a/clutter/cogl/cogl/cogl-context.c +++ b/clutter/cogl/cogl/cogl-context.c @@ -27,6 +27,7 @@ #include "cogl.h" #include "cogl-internal.h" +#include "cogl-profile.h" #include "cogl-util.h" #include "cogl-context.h" #include "cogl-journal-private.h" @@ -68,6 +69,22 @@ cogl_create_context (void) if (_context != NULL) return FALSE; +#ifdef CLUTTER_ENABLE_PROFILE + /* We need to be absolutely sure that uprof has been initialized + * before calling _cogl_uprof_init. uprof_init (NULL, NULL) + * will be a NOP if it has been initialized but it will also + * mean subsequent parsing of the UProf GOptionGroup will have no + * affect. + * + * Sadly GOptionGroup based library initialization is extremely + * fragile by design because GOptionGroups have no notion of + * dependencies and so the order things are initialized isn't + * currently under tight control. + */ + uprof_init (NULL, NULL); + _cogl_uprof_init (); +#endif + /* Allocate context memory */ _context = (CoglContext*) g_malloc (sizeof (CoglContext)); diff --git a/clutter/cogl/cogl/cogl-profile.c b/clutter/cogl/cogl/cogl-profile.c index c8d11dd76..8f01d2c1d 100644 --- a/clutter/cogl/cogl/cogl-profile.c +++ b/clutter/cogl/cogl/cogl-profile.c @@ -26,8 +26,21 @@ debug_option_setter (gboolean value, void *user_data) cogl_debug_flags &= ~(1 << shift); } -static void __attribute__ ((constructor)) -cogl_uprof_constructor (void) +static void +print_exit_report (void) +{ + if (getenv ("COGL_PROFILE_OUTPUT_REPORT")) + { + UProfReport *report = uprof_report_new ("Cogl report"); + uprof_report_add_context (report, _cogl_uprof_context); + uprof_report_print (report); + uprof_report_unref (report); + } + uprof_context_unref (_cogl_uprof_context); +} + +void +_cogl_uprof_init (void) { _cogl_uprof_context = uprof_context_new ("Cogl"); #define OPT(MASK_NAME, GROUP, NAME, NAME_FORMATTED, DESCRIPTION) \ @@ -47,19 +60,8 @@ cogl_uprof_constructor (void) #include "cogl-debug-options.h" #undef OPT -} -static void __attribute__ ((destructor)) -cogl_uprof_destructor (void) -{ - if (getenv ("COGL_PROFILE_OUTPUT_REPORT")) - { - UProfReport *report = uprof_report_new ("Cogl report"); - uprof_report_add_context (report, _cogl_uprof_context); - uprof_report_print (report); - uprof_report_unref (report); - } - uprof_context_unref (_cogl_uprof_context); + g_atexit (print_exit_report); } void diff --git a/clutter/cogl/cogl/cogl-profile.h b/clutter/cogl/cogl/cogl-profile.h index 5473dd67a..1d058f796 100644 --- a/clutter/cogl/cogl/cogl-profile.h +++ b/clutter/cogl/cogl/cogl-profile.h @@ -38,6 +38,9 @@ extern UProfContext *_cogl_uprof_context; #define COGL_TIMER_START UPROF_TIMER_START #define COGL_TIMER_STOP UPROF_TIMER_STOP +void +_cogl_uprof_init (void); + void _cogl_profile_trace_message (const char *format, ...);