static gboolean _clutter_uprof_report_prepare (UProfReport *report, void **closure_ret, void *user_data) { UProfContext *mainloop_context; UProfTimerResult *mainloop_timer; UProfTimerResult *stage_paint_timer; UProfTimerResult *do_pick_timer; ClutterUProfReportState *state; /* NB: uprof provides a shared context for mainloop statistics which allows * this to work even if the application and not Clutter owns the mainloop. * * This is the case when running Mutter for example but because Mutter will * follow the same convention of using the shared context then we can always * be sure of where to look for the mainloop results. */ 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) return FALSE; state = g_new0 (ClutterUProfReportState, 1); *closure_ret = state; stage_paint_timer = uprof_context_get_timer_result (_clutter_uprof_context, "Redrawing"); if (stage_paint_timer) { state->n_frames = uprof_timer_result_get_start_count (stage_paint_timer); uprof_report_add_statistic (report, "Frames", "Frame count information"); uprof_report_add_statistic_attribute (report, "Frames", "Count", "Count", "The total number of frames", UPROF_ATTRIBUTE_TYPE_INT, get_n_frames_cb, state); state->fps = (float) state->n_frames / (uprof_timer_result_get_total_msecs (mainloop_timer) / 1000.0); uprof_report_add_statistic_attribute (report, "Frames", "Average FPS", "Average\nFPS", "The average frames per second", UPROF_ATTRIBUTE_TYPE_FLOAT, get_fps_cb, state); } do_pick_timer = uprof_context_get_timer_result (_clutter_uprof_context, "Picking"); if (do_pick_timer) { state->n_picks = uprof_timer_result_get_start_count (do_pick_timer); state->msecs_picking = uprof_timer_result_get_total_msecs (do_pick_timer); uprof_report_add_statistic (report, "Picks", "Picking information"); uprof_report_add_statistic_attribute (report, "Picks", "Count", "Count", "The total number of picks", UPROF_ATTRIBUTE_TYPE_INT, get_n_picks_cb, state); uprof_report_add_statistic_attribute (report, "Picks", "Picks Per Frame", "Picks\nPer Frame", "The average number of picks " "per frame", UPROF_ATTRIBUTE_TYPE_FLOAT, get_picks_per_frame_cb, state); uprof_report_add_statistic_attribute (report, "Picks", "Msecs Per Pick", "Msecs\nPer Pick", "The average number of " "milliseconds per pick", UPROF_ATTRIBUTE_TYPE_FLOAT, get_msecs_per_pick_cb, state); } uprof_report_add_counters_attribute (clutter_uprof_report, "Per Frame", "Per Frame", "The number of counts per frame", UPROF_ATTRIBUTE_TYPE_INT, counter_per_frame_cb, state); uprof_report_add_timers_attribute (clutter_uprof_report, "Per Frame\nmsecs", "Per Frame", "The time spent in the timer per frame", UPROF_ATTRIBUTE_TYPE_FLOAT, timer_per_frame_cb, state); return TRUE; }
int main (int argc, char **argv) { UProfContext *context; UProfReport *report; int i; uprof_init (&argc, &argv); context = uprof_context_new ("Simple context"); DBG_PRINTF ("start full timer (rdtsc = %" G_GUINT64_FORMAT ")\n", uprof_get_system_counter ()); UPROF_TIMER_START (context, full_timer); for (i = 0; i < 2; i ++) { struct timespec delay; UPROF_COUNTER_INC (context, loop0_counter); DBG_PRINTF ("start simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n", uprof_get_system_counter ()); UPROF_TIMER_START (context, loop0_timer); DBG_PRINTF (" <delay: 1/2 sec>\n"); delay.tv_sec = 0; delay.tv_nsec = 1000000000/2; nanosleep (&delay, NULL); UPROF_TIMER_START (context, loop0_sub_timer); DBG_PRINTF (" <timing sub delay: 1/4 sec>\n"); delay.tv_sec = 0; delay.tv_nsec = 1000000000/4; nanosleep (&delay, NULL); UPROF_TIMER_STOP (context, loop0_sub_timer); UPROF_TIMER_STOP (context, loop0_timer); DBG_PRINTF ("stop simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n", uprof_get_system_counter ()); } for (i = 0; i < 4; i ++) { struct timespec delay; UPROF_COUNTER_INC (context, loop1_counter); DBG_PRINTF ("start simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n", uprof_get_system_counter ()); UPROF_TIMER_START (context, loop1_timer); DBG_PRINTF (" <delay: 1/4 sec>\n"); delay.tv_sec = 0; delay.tv_nsec = 1000000000/4; nanosleep (&delay, NULL); UPROF_TIMER_START (context, loop1_sub_timer); DBG_PRINTF (" <timing sub delay: 1/2 sec>\n"); delay.tv_sec = 0; delay.tv_nsec = 1000000000/2; nanosleep (&delay, NULL); UPROF_TIMER_STOP (context, loop1_sub_timer); UPROF_TIMER_STOP (context, loop1_timer); DBG_PRINTF ("stop simple timer (rdtsc = %" G_GUINT64_FORMAT ")\n", uprof_get_system_counter ()); } DBG_PRINTF ("stop full timer (rdtsc = %" G_GUINT64_FORMAT ")\n", uprof_get_system_counter ()); UPROF_TIMER_STOP (context, full_timer); report = uprof_report_new ("Simple report"); uprof_report_add_statistic (report, "Special thingy", "This is a particularly interesting thingy"); uprof_report_add_statistic_attribute (report, "Special thingy", "Thingy A value", "Thingy A\nvalue", "The real A value of thingys", UPROF_ATTRIBUTE_TYPE_WORD, a_values_cb, NULL); uprof_report_add_statistic_attribute (report, "Special thingy", "Thingy B value", "Thingy B\nvalue", "The real B value of thingys", UPROF_ATTRIBUTE_TYPE_WORD, b_values_cb, NULL); uprof_report_add_statistic (report, "Special dobble", "This is a particularly interesting dobble"); uprof_report_add_statistic_attribute (report, "Special dobble", "Dobble value", "Dobble\nvalue", "The real value of dobbles", UPROF_ATTRIBUTE_TYPE_FLOAT, dobbles_cb, NULL); uprof_report_add_timers_attribute (report, "Time in seconds", "Time in\nseconds", "The time elapsed in seconds", UPROF_ATTRIBUTE_TYPE_INT, seconds_column_cb, NULL); uprof_report_add_counters_attribute (report, "Double count", "Double\ncount", "The count doubled", UPROF_ATTRIBUTE_TYPE_INT, double_count_cb, NULL); uprof_report_add_counters_attribute (report, "Tripple count", "Tripple\ncount", "The count trippled", UPROF_ATTRIBUTE_TYPE_INT, tripple_count_cb, NULL); uprof_report_add_context (report, context); uprof_report_print (report); uprof_report_unref (report); uprof_context_unref (context); return 0; }