Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/libdocument/ev-debug.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2008-07-27 15:42:03 (GMT)
committer Carlos Garcia Campos <carlosgc@src.gnome.org>2008-07-27 15:42:03 (GMT)
commit597433bc874ff2cf5cb9f9de4e053db47837e042 (patch)
tree2143de602b6a0bbd81de36b7b1bca721f4ed67d5 /libdocument/ev-debug.c
parentdc42eeb3da3878a8698c2358658f821819d3d070 (diff)
Add a profile mode available when debug is enabled. Add profilers in
2008-07-27 Carlos Garcia Campos <carlosgc@gnome.org> * libdocument/ev-debug.[ch]: (ev_profiler_start), (ev_profiler_stop): * shell/ev-jobs.c: (ev_job_finished), (ev_job_links_run), (notify_page_ready), (ev_job_render_run), (ev_job_thumbnail_run), (ev_job_fonts_run), (ev_job_load_run), (ev_job_save_run), (ev_job_print_run): * shell/main.c: (main): Add a profile mode available when debug is enabled. Add profilers in ev-jobs. svn path=/trunk/; revision=3086
Diffstat (limited to 'libdocument/ev-debug.c')
-rw-r--r--libdocument/ev-debug.c97
1 files changed, 95 insertions, 2 deletions
diff --git a/libdocument/ev-debug.c b/libdocument/ev-debug.c
index 3806fd4..911521b 100644
--- a/libdocument/ev-debug.c
+++ b/libdocument/ev-debug.c
@@ -42,9 +42,12 @@
#ifdef EV_ENABLE_DEBUG
static EvDebugSection ev_debug = EV_NO_DEBUG;
+static EvProfileSection ev_profile = EV_NO_PROFILE;
-void
-ev_debug_init ()
+static GHashTable *timers = NULL;
+
+static void
+debug_init ()
{
if (g_getenv ("EV_DEBUG") != NULL) {
/* enable all debugging */
@@ -56,6 +59,42 @@ ev_debug_init ()
ev_debug |= EV_DEBUG_JOBS;
}
+static void
+profile_init ()
+{
+ if (g_getenv ("EV_PROFILE") != NULL) {
+ /* enable all profiling */
+ ev_profile = ~EV_NO_PROFILE;
+ return;
+ }
+
+ if (g_getenv ("EV_PROFILE_JOBS") != NULL)
+ ev_profile |= EV_PROFILE_JOBS;
+
+ if (ev_profile) {
+ timers = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_timer_destroy);
+ }
+}
+
+void
+ev_debug_init ()
+{
+ debug_init ();
+ profile_init ();
+}
+
+void
+ev_debug_shutdown ()
+{
+ if (timers) {
+ g_hash_table_destroy (timers);
+ timers = NULL;
+ }
+}
+
void
ev_debug_message (EvDebugSection section,
const gchar *file,
@@ -82,4 +121,58 @@ ev_debug_message (EvDebugSection section,
}
}
+void
+ev_profiler_start (EvProfileSection section,
+ const gchar *format, ...)
+{
+ if (G_UNLIKELY (ev_profile & section)) {
+ GTimer *timer;
+ gchar *name;
+ va_list args;
+
+ if (!format)
+ return;
+
+ va_start (args, format);
+ name = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ timer = g_hash_table_lookup (timers, name);
+ if (!timer) {
+ timer = g_timer_new ();
+ g_hash_table_insert (timers, g_strdup (name), timer);
+ } else {
+ g_timer_start (timer);
+ }
+ }
+}
+
+void
+ev_profiler_stop (EvProfileSection section,
+ const gchar *format, ...)
+{
+ if (G_UNLIKELY (ev_profile & section)) {
+ GTimer *timer;
+ gchar *name;
+ va_list args;
+ gdouble seconds;
+
+ if (!format)
+ return;
+
+ va_start (args, format);
+ name = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ timer = g_hash_table_lookup (timers, name);
+ if (!timer)
+ return;
+
+ g_timer_stop (timer);
+ seconds = g_timer_elapsed (timer, NULL);
+ g_print ("[ %s ] %f s elapsed\n", name, seconds);
+ fflush (stdout);
+ }
+}
+
#endif /* EV_ENABLE_DEBUG */