]> www.fi.muni.cz Git - evince.git/blobdiff - libdocument/ev-debug.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / libdocument / ev-debug.c
index 3806fd45d87cb963db001b789423db39b8cb8b42..4750c9d377d827c3b85574749c020c2000ebf0f2 100644 (file)
@@ -18,8 +18,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, 
- * Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
  
 /*
 
 #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,41 @@ 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;
+       } else {
+               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 +120,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 */