Initialize the cogl uprof state in cogl_create_context

This avoids the use of of gcc constructor and destructor attributes to
initialize the cogl uprof context and optionally print a cogl uprof
report at app exit. We now initialize the uprof context in
cogl_context_create instead.
This commit is contained in:
Robert Bragg 2010-08-16 21:11:42 +01:00
parent d9ee3be835
commit 88023d438d
3 changed files with 36 additions and 14 deletions

View File

@ -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));

View File

@ -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

View File

@ -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, ...);