2011-09-10 08:52:48 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2009-07-03 15:22:35 +00:00
|
|
|
|
|
|
|
#ifdef COGL_ENABLE_PROFILE
|
|
|
|
|
|
|
|
#include "cogl-profile.h"
|
2010-06-21 14:36:46 +00:00
|
|
|
#include "cogl-debug.h"
|
2009-07-03 15:22:35 +00:00
|
|
|
|
2011-09-10 08:52:48 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2009-07-03 15:22:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
UProfContext *_cogl_uprof_context;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-06-21 14:36:46 +00:00
|
|
|
debug_option_getter (void *user_data)
|
|
|
|
{
|
|
|
|
unsigned int shift = GPOINTER_TO_UINT (user_data);
|
2011-01-24 14:28:00 +00:00
|
|
|
return COGL_DEBUG_ENABLED (shift);
|
2010-06-21 14:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
debug_option_setter (CoglBool value, void *user_data)
|
2010-06-21 14:36:46 +00:00
|
|
|
{
|
|
|
|
unsigned int shift = GPOINTER_TO_UINT (user_data);
|
|
|
|
|
|
|
|
if (value)
|
2011-01-24 14:28:00 +00:00
|
|
|
COGL_DEBUG_SET_FLAG (shift);
|
2010-06-21 14:36:46 +00:00
|
|
|
else
|
2011-01-24 14:28:00 +00:00
|
|
|
COGL_DEBUG_CLEAR_FLAG (shift);
|
2010-06-21 14:36:46 +00:00
|
|
|
}
|
2009-07-03 15:22:35 +00:00
|
|
|
|
2010-08-16 20:11:42 +00:00
|
|
|
static void
|
|
|
|
print_exit_report (void)
|
|
|
|
{
|
|
|
|
if (getenv ("COGL_PROFILE_OUTPUT_REPORT"))
|
|
|
|
{
|
2012-08-27 18:54:37 +00:00
|
|
|
UProfContext *mainloop_context;
|
|
|
|
UProfTimerResult *mainloop_timer;
|
|
|
|
UProfReport *report;
|
|
|
|
|
|
|
|
/* NB: uprof provides a shared context for mainloop statistics
|
|
|
|
* which needs to be setup by the application which controls the
|
|
|
|
* mainloop.
|
|
|
|
*
|
|
|
|
* If no "Mainloop" timer has been setup then we print a warning
|
|
|
|
* since we can't provide a meaningful Cogl report without one.
|
|
|
|
*/
|
|
|
|
mainloop_context = uprof_get_mainloop_context ();
|
|
|
|
mainloop_timer = uprof_context_get_timer_result (mainloop_context,
|
|
|
|
"Mainloop");
|
|
|
|
/* just bail out if the mainloop timer wasn't hit */
|
|
|
|
if (!mainloop_timer)
|
|
|
|
{
|
|
|
|
g_warning ("\n\n"
|
|
|
|
"No UProf \"Mainloop\" timer was setup by the "
|
|
|
|
"application therefore we\ncan't provide a meaningful "
|
|
|
|
"profile report.\n"
|
|
|
|
"\n"
|
|
|
|
"This should be done automatically if you are using Clutter "
|
|
|
|
"(if\nbuilt with --enable-profile)\n"
|
|
|
|
"\n"
|
|
|
|
"If you aren't using Clutter then you can declare a "
|
|
|
|
"\"Mainloop\" UProf\ntimer in your application like this:\n\n"
|
|
|
|
" UPROF_STATIC_TIMER (mainloop_timer, \n"
|
|
|
|
" NULL,\n"
|
|
|
|
" \"Mainloop\",\n"
|
|
|
|
" \"Time in glib mainloop\",\n"
|
|
|
|
" 0);\n"
|
|
|
|
"\n"
|
|
|
|
"And start/stop it around your mainloop like this:\n"
|
|
|
|
"\n"
|
|
|
|
" UPROF_TIMER_START (uprof_get_mainloop_context (), mainloop_timer);\n"
|
|
|
|
" g_main_loop_run (loop);\n"
|
|
|
|
" UPROF_TIMER_STOP (uprof_get_mainloop_context (), mainloop_timer);\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
report = uprof_report_new ("Cogl report");
|
2010-08-16 20:11:42 +00:00
|
|
|
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)
|
2009-07-03 15:22:35 +00:00
|
|
|
{
|
|
|
|
_cogl_uprof_context = uprof_context_new ("Cogl");
|
2012-08-27 18:54:37 +00:00
|
|
|
uprof_context_link (_cogl_uprof_context, uprof_get_mainloop_context ());
|
2010-06-21 14:36:46 +00:00
|
|
|
#define OPT(MASK_NAME, GROUP, NAME, NAME_FORMATTED, DESCRIPTION) \
|
|
|
|
G_STMT_START { \
|
2011-01-24 14:28:00 +00:00
|
|
|
int shift = COGL_DEBUG_ ## MASK_NAME; \
|
2010-06-21 14:36:46 +00:00
|
|
|
uprof_context_add_boolean_option (_cogl_uprof_context, \
|
2011-09-10 08:52:48 +00:00
|
|
|
g_dgettext (GETTEXT_PACKAGE, GROUP), \
|
2010-06-21 14:36:46 +00:00
|
|
|
NAME, \
|
2011-09-10 08:52:48 +00:00
|
|
|
g_dgettext (GETTEXT_PACKAGE, \
|
|
|
|
NAME_FORMATTED), \
|
|
|
|
g_dgettext (GETTEXT_PACKAGE, \
|
|
|
|
DESCRIPTION), \
|
2010-06-21 14:36:46 +00:00
|
|
|
debug_option_getter, \
|
|
|
|
debug_option_setter, \
|
|
|
|
GUINT_TO_POINTER (shift)); \
|
|
|
|
} G_STMT_END;
|
|
|
|
|
|
|
|
#include "cogl-debug-options.h"
|
|
|
|
#undef OPT
|
2009-07-03 15:22:35 +00:00
|
|
|
|
2012-01-16 20:52:50 +00:00
|
|
|
atexit (print_exit_report);
|
2009-07-03 15:22:35 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 14:36:46 +00:00
|
|
|
void
|
|
|
|
_cogl_profile_trace_message (const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, format);
|
|
|
|
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
if (_cogl_uprof_context)
|
|
|
|
uprof_context_vtrace_message (_cogl_uprof_context, format, ap);
|
|
|
|
}
|
|
|
|
|
2009-07-03 15:22:35 +00:00
|
|
|
#endif
|