From 8146d8d08deafd6cf86238a4a8c2fa6149e5c691 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Fri, 26 Feb 2010 09:44:29 +0000 Subject: [PATCH] profile: avoid segfault generating reports with no stats The clutter-profile.c print_report() code would crash if no stats had been gathered because uprof would return NULL for the "Redrawing" timer which we then dereferenced. This changes the code to start by checking for the "Mainloop", "Redrawing" and "Do Pick" timers and if none are present it returns immediately without generating any report. --- clutter/clutter-profile.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/clutter/clutter-profile.c b/clutter/clutter-profile.c index aa84f43..aa8b715 100644 --- a/clutter/clutter-profile.c +++ b/clutter/clutter-profile.c @@ -57,8 +57,6 @@ print_report (UProfReport *report, UProfContext *context) float fps; ClutterUProfReportState state; - g_print ("\n"); - /* FIXME: We need to fix the way Clutter initializes the uprof library * (we don't currently call uprof_init()) and add a mechanism to know * if uprof_init hasn't been called so we can simply bail out of report @@ -66,23 +64,25 @@ print_report (UProfReport *report, UProfContext *context) * Probably we can just have uprof_report_print bail out if uprof wasn't * initialized, so we don't have to care here. */ - + mainloop_timer = uprof_context_get_timer_result (context, "Mainloop"); + if (!mainloop_timer) + return; stage_paint_timer = uprof_context_get_timer_result (context, "Redrawing"); -#if 0 if (!stage_paint_timer) - g_critical ("Failed to find \"Redrawing\" timer " - "(you need to update print_report code if you rename it)\n"); -#endif + return; + do_pick_timer = uprof_context_get_timer_result (context, "Do pick"); + if (!do_pick_timer) + return; + + g_print ("\n"); state.n_frames = uprof_timer_result_get_start_count (stage_paint_timer); g_print ("Frame count = %lu\n", state.n_frames); - mainloop_timer = uprof_context_get_timer_result (context, "Mainloop"); fps = (float)state.n_frames / (uprof_timer_result_get_total_msecs (mainloop_timer) / 1000.0); g_print ("Average fps = %5.2f\n", fps); - do_pick_timer = uprof_context_get_timer_result (context, "Do pick"); if (do_pick_timer) { int n_picks = uprof_timer_result_get_start_count (do_pick_timer); -- 2.7.4