2
#ifdef CLUTTER_ENABLE_PROFILE
4
#include "clutter-profile.h"
8
UProfContext *_clutter_uprof_context;
9
#define REPORT_COLUMN0_WIDTH 40
11
static gboolean searched_for_gl_uprof_context = FALSE;
12
static UProfContext *gl_uprof_context = NULL;
14
typedef struct _ClutterUProfReportState
17
} ClutterUProfReportState;
20
print_counter (UProfCounterResult *counter,
23
ClutterUProfReportState *state = data;
24
gulong count = uprof_counter_result_get_count (counter);
28
g_print (" %-*s %-5ld %-5ld\n", REPORT_COLUMN0_WIDTH - 2,
29
uprof_counter_result_get_name (counter),
30
uprof_counter_result_get_count (counter),
31
uprof_counter_result_get_count (counter) / state->n_frames);
35
print_timer_fields (UProfTimerResult *timer,
39
ClutterUProfReportState *state = data;
40
/* Print the field titles when timer == NULL */
42
return g_strdup_printf ("Per Frame");
44
return g_strdup_printf ("%-10.2f",
45
uprof_timer_result_get_total_msecs (timer) /
46
(float)state->n_frames);
50
print_report (UProfReport *report, UProfContext *context)
54
UProfTimerResult *stage_paint_timer;
55
UProfTimerResult *mainloop_timer;
56
UProfTimerResult *do_pick_timer;
58
ClutterUProfReportState state;
60
/* FIXME: We need to fix the way Clutter initializes the uprof library
61
* (we don't currently call uprof_init()) and add a mechanism to know
62
* if uprof_init hasn't been called so we can simply bail out of report
63
* generation and not print spurious warning about missing timers.
64
* Probably we can just have uprof_report_print bail out if uprof wasn't
65
* initialized, so we don't have to care here.
67
mainloop_timer = uprof_context_get_timer_result (context, "Mainloop");
70
stage_paint_timer = uprof_context_get_timer_result (context, "Redrawing");
71
if (!stage_paint_timer)
73
do_pick_timer = uprof_context_get_timer_result (context, "Do pick");
79
state.n_frames = uprof_timer_result_get_start_count (stage_paint_timer);
80
g_print ("Frame count = %lu\n", state.n_frames);
82
fps = (float)state.n_frames / (uprof_timer_result_get_total_msecs (mainloop_timer)
84
g_print ("Average fps = %5.2f\n", fps);
88
int n_picks = uprof_timer_result_get_start_count (do_pick_timer);
90
g_print ("Pick Stats:\n");
91
g_print ("Pick count = %d\n", n_picks);
92
g_print ("Average picks per frame = %3.2f\n",
93
(float)n_picks / (float)state.n_frames);
94
g_print ("Average Msecs per pick = %3.2f\n",
95
(float)uprof_timer_result_get_total_msecs (do_pick_timer)
101
/* XXX: UProfs default reporting code now supports dynamic sizing for the Name
102
* column, the only thing it's missing is support for adding custom columns but
103
* when that's added we should switch away from manual report generation. */
104
g_print ("Counters:\n");
105
g_print (" %-*s %5s %s\n", REPORT_COLUMN0_WIDTH - 2, "Name", "Total", "Per Frame");
106
g_print (" %-*s %5s %s\n", REPORT_COLUMN0_WIDTH - 2, "----", "-----", "---------");
107
uprof_context_foreach_counter (context,
108
UPROF_COUNTER_SORT_COUNT_INC,
113
g_print ("Timers:\n");
114
root_timers = uprof_context_get_root_timer_results (context);
115
for (l = root_timers; l != NULL; l = l->next)
116
uprof_timer_result_print_and_children ((UProfTimerResult *)l->data,
123
/* FIXME: we should be able to deal with creating the uprof context in
124
* clutter_init instead. I think the only reason I did it this way originally
125
* was as a quick hack.
127
static void __attribute__ ((constructor))
128
clutter_uprof_constructor (void)
130
_clutter_uprof_context = uprof_context_new ("Clutter");
135
print_timers (UProfContext *context)
140
root_timers = uprof_context_get_root_timer_results ();
143
g_list_sort_with_data (context->root_timers,
144
(GCompareDataFunc)_uprof_timer_compare_total_times,
146
for (l = context->timers; l != NULL; l = l->next)
148
UProfTimerState *timer = l->data;
150
g_list_sort_with_data (timer->children,
152
_uprof_timer_compare_total_times,
158
static void __attribute__ ((destructor))
159
clutter_uprof_destructor (void)
161
if (!(clutter_profile_flags & CLUTTER_PROFILE_DISABLE_REPORT))
163
UProfReport *report = uprof_report_new ("Clutter report");
164
uprof_report_add_context (report, _clutter_uprof_context);
165
uprof_report_add_context_callback (report, print_report);
166
uprof_report_print (report);
167
uprof_report_unref (report);
169
uprof_context_unref (_clutter_uprof_context);
173
_clutter_profile_suspend (void)
175
if (G_UNLIKELY (!searched_for_gl_uprof_context))
177
gl_uprof_context = uprof_find_context ("OpenGL");
178
searched_for_gl_uprof_context = TRUE;
181
if (gl_uprof_context)
182
uprof_context_suspend (gl_uprof_context);
184
/* NB: The Cogl context is linked to this so it will also be suspended... */
185
uprof_context_suspend (_clutter_uprof_context);
189
_clutter_profile_resume (void)
191
if (gl_uprof_context)
192
uprof_context_resume (gl_uprof_context);
194
/* NB: The Cogl context is linked to this so it will also be resumed... */
195
uprof_context_resume (_clutter_uprof_context);