gnome-games r8449 - trunk/libgames-support



Author: chpe
Date: Tue Jan  6 18:19:01 2009
New Revision: 8449
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8449&view=rev

Log:
Use the new profiling code instead of the old #ifdef mess.

Modified:
   trunk/libgames-support/games-card-theme-fixed.c
   trunk/libgames-support/games-card-theme-kde.c
   trunk/libgames-support/games-card-theme-preimage.c
   trunk/libgames-support/games-card-theme-pysol.c
   trunk/libgames-support/games-card-theme-sliced.c
   trunk/libgames-support/games-card-theme-svg.c
   trunk/libgames-support/games-card-theme.c
   trunk/libgames-support/games-card-theme.h
   trunk/libgames-support/games-preimage.c

Modified: trunk/libgames-support/games-card-theme-fixed.c
==============================================================================
--- trunk/libgames-support/games-card-theme-fixed.c	(original)
+++ trunk/libgames-support/games-card-theme-fixed.c	Tue Jan  6 18:19:01 2009
@@ -53,13 +53,6 @@
   guint size_available : 1;
 };
 
-/* #defining this prints out the time it takes to render the theme */
-/* #define INSTRUMENT_LOADING */
-
-#ifdef INSTRUMENT_LOADING
-static long totaltime = 0;
-#endif
-
 /* Class implementation */
 
 G_DEFINE_TYPE (GamesCardThemeFixed, games_card_theme_fixed, GAMES_TYPE_CARD_THEME);
@@ -297,22 +290,8 @@
   GamesCardThemeFixed *theme = (GamesCardThemeFixed *) card_theme;
   GdkPixbuf *pixbuf;
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
-#endif
-
   pixbuf = games_card_theme_fixed_load_card (theme, card_id);
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  totaltime += (t2 - t1);
-  g_print ("took %.3fs to render card %d (cumulative: %.3fs)\n",
-           (t2 - t1) * 1.0 / CLOCKS_PER_SEC, card_id,
-           totaltime * 1.0 / CLOCKS_PER_SEC);
-#endif
-
   return pixbuf;
 }
 

Modified: trunk/libgames-support/games-card-theme-kde.c
==============================================================================
--- trunk/libgames-support/games-card-theme-kde.c	(original)
+++ trunk/libgames-support/games-card-theme-kde.c	Tue Jan  6 18:19:01 2009
@@ -52,13 +52,6 @@
 
 #define DELTA (0.0f)
 
-/* #defining this prints out the time it takes to render the theme */
-/* #define INSTRUMENT_LOADING */
-
-#ifdef INSTRUMENT_LOADING
-static long totaltime = 0;
-#endif
-
 #define KDE_BACKDECK_FILENAME     "index.desktop"
 #define KDE_BACKDECK_GROUP        "KDE Backdeck"
 #define KDE_BACKDECK_BACK_KEY     "Back"
@@ -78,19 +71,13 @@
   GamesCardThemePreimage *preimage_card_theme = (GamesCardThemePreimage *) card_theme;
   gboolean retval = FALSE;
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
+#ifndef HAVE_RSVG_BBOX
+  return FALSE;
 #endif
 
   if (!GAMES_CARD_THEME_CLASS (games_card_theme_kde_parent_class)->load (card_theme, error))
     goto out;
 
-#ifndef HAVE_RSVG_BBOX
-  goto out;
-#endif
-
   if (!games_preimage_is_scalable (preimage_card_theme->cards_preimage))
     goto out;
 
@@ -98,14 +85,6 @@
 
 out:
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  totaltime += (t2 - t1);
-  g_print ("took %.3fs to create preimage (cumulative %.3fs)\n",
-           (t2 - t1) * 1.0 / CLOCKS_PER_SEC,
-           totaltime * 1.0 / CLOCKS_PER_SEC);
-#endif
-
   return retval;
 }
 

Modified: trunk/libgames-support/games-card-theme-preimage.c
==============================================================================
--- trunk/libgames-support/games-card-theme-preimage.c	(original)
+++ trunk/libgames-support/games-card-theme-preimage.c	Tue Jan  6 18:19:01 2009
@@ -39,13 +39,6 @@
 
 #define DELTA (0.0f)
 
-/* #defining this prints out the time it takes to render the theme */
-/* #define INSTRUMENT_LOADING */
-
-#ifdef INSTRUMENT_LOADING
-static long totaltime = 0;
-#endif
-
 /* Class implementation */
 
 G_DEFINE_ABSTRACT_TYPE (GamesCardThemePreimage, games_card_theme_preimage, GAMES_TYPE_CARD_THEME);
@@ -58,11 +51,6 @@
 
   if (clear_sized_theme_data)
     clear_sized_theme_data (theme);
-
-#ifdef INSTRUMENT_LOADING
-  /* Reset the time */
-  totaltime = 0;
-#endif
 }
 
 static gboolean
@@ -75,12 +63,6 @@
   const char *slot_dir;
   char *path;
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
-#endif
-
   // XXX FIXMEchpe remove this crap
   /* First try and load the given file. */
   //filename = g_strdup_printf ("%s.svg", theme_name);
@@ -123,14 +105,6 @@
 
 out:
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  totaltime += (t2 - t1);
-  g_print ("took %.3fs to create preimage (cumulative %.3fs)\n",
-           (t2 - t1) * 1.0 / CLOCKS_PER_SEC,
-           totaltime * 1.0 / CLOCKS_PER_SEC);
-#endif
-
   return theme->cards_preimage != NULL;
 }
 

Modified: trunk/libgames-support/games-card-theme-pysol.c
==============================================================================
--- trunk/libgames-support/games-card-theme-pysol.c	(original)
+++ trunk/libgames-support/games-card-theme-pysol.c	Tue Jan  6 18:19:01 2009
@@ -40,13 +40,6 @@
   GamesCardTheme parent_instance;
 };
 
-/* #defining this prints out the time it takes to render the theme */
-/* #define INSTRUMENT_LOADING */
-
-#ifdef INSTRUMENT_LOADING
-static long totaltime = 0;
-#endif
-
 #define PYSOL_CONFIG_FILENAME "config.txt"
 
 typedef struct {
@@ -318,22 +311,8 @@
 {
   GdkPixbuf *pixbuf;
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
-#endif
-
   pixbuf = games_card_theme_pysol_load_card (card_theme->theme_info->data, card_id);
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  totaltime += (t2 - t1);
-  g_print ("took %.3fs to render card %d (cumulative: %.3fs)\n",
-           (t2 - t1) * 1.0 / CLOCKS_PER_SEC, card_id,
-           totaltime * 1.0 / CLOCKS_PER_SEC);
-#endif
-
   return pixbuf;
 }
 

Modified: trunk/libgames-support/games-card-theme-sliced.c
==============================================================================
--- trunk/libgames-support/games-card-theme-sliced.c	(original)
+++ trunk/libgames-support/games-card-theme-sliced.c	Tue Jan  6 18:19:01 2009
@@ -27,6 +27,7 @@
 #include "games-find-file.h"
 #include "games-files.h"
 #include "games-preimage.h"
+#include "games-profile.h"
 #include "games-runtime.h"
 #include "games-string-utils.h"
 
@@ -51,13 +52,6 @@
 
 #define DELTA (0.0f)
 
-/* #defining this prints out the time it takes to render the theme */
-/* #define INSTRUMENT_LOADING */
-
-#ifdef INSTRUMENT_LOADING
-static long totaltime = 0;
-#endif
-
 /* Class implementation */
 
 G_DEFINE_TYPE (GamesCardThemeSliced, games_card_theme_sliced, GAMES_TYPE_CARD_THEME_PREIMAGE);
@@ -71,11 +65,6 @@
     g_object_unref (theme->source);
     theme->source = NULL;
   }
-
-#ifdef INSTRUMENT_LOADING
-  /* Reset the time */
-  totaltime = 0;
-#endif
 }
 
 static gboolean
@@ -86,12 +75,6 @@
   GamesCardThemeSliced *theme = (GamesCardThemeSliced *) card_theme;
   gboolean retval = FALSE;
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
-#endif
-
   if (!GAMES_CARD_THEME_CLASS (games_card_theme_sliced_parent_class)->load (card_theme, error))
     goto out;
 
@@ -105,36 +88,27 @@
 
 out:
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  totaltime += (t2 - t1);
-  g_print ("took %.3fs to create preimage (cumulative %.3fs)\n",
-           (t2 - t1) * 1.0 / CLOCKS_PER_SEC,
-           totaltime * 1.0 / CLOCKS_PER_SEC);
-#endif
-
   return retval;
 }
 
 static gboolean
-games_card_theme_sliced_prerender_scalable (GamesCardThemeSliced * theme)
+games_card_theme_sliced_prerender_scalable (GamesCardThemeSliced *theme)
 {
   GamesCardThemePreimage *preimage_card_theme = (GamesCardThemePreimage *) theme;
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
-#endif
-
   // FIXMEchpe this doesn't look right
   g_return_val_if_fail (theme->prescaled
                         || theme->source != NULL, FALSE);
 
+  _games_profile_start ("prerendering source pixbuf for %s card theme %s", G_OBJECT_TYPE_NAME (theme), ((GamesCardTheme*)theme)->theme_info->display_name);
+
   theme->source =
     games_preimage_render (preimage_card_theme->cards_preimage,
                            preimage_card_theme->card_size.width * 13,
                            preimage_card_theme->card_size.height * 5);
+
+  _games_profile_end ("prerendering source pixbuf for %s card theme %s", G_OBJECT_TYPE_NAME (theme), ((GamesCardTheme*)theme)->theme_info->display_name);
+
   if (!theme->source)
     return FALSE;
 
@@ -143,11 +117,6 @@
   theme->subsize.height =
     gdk_pixbuf_get_height (theme->source) / 5;
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  g_print ("took %.3fs to prerender\n", (t2 - t1) * 1.0 / CLOCKS_PER_SEC);
-#endif
-
   return TRUE;
 }
 

Modified: trunk/libgames-support/games-card-theme-svg.c
==============================================================================
--- trunk/libgames-support/games-card-theme-svg.c	(original)
+++ trunk/libgames-support/games-card-theme-svg.c	Tue Jan  6 18:19:01 2009
@@ -48,13 +48,6 @@
 
 #define DELTA (0.0f)
 
-/* #defining this prints out the time it takes to render the theme */
-/* #define INSTRUMENT_LOADING */
-
-#ifdef INSTRUMENT_LOADING
-static long totaltime = 0;
-#endif
-
 /* Class implementation */
 
 G_DEFINE_TYPE (GamesCardThemeSVG, games_card_theme_svg, GAMES_TYPE_CARD_THEME_PREIMAGE);
@@ -66,12 +59,6 @@
   GamesCardThemePreimage *preimage_card_theme = (GamesCardThemePreimage *) card_theme;
   gboolean retval = FALSE;
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
-#endif
-
   if (!GAMES_CARD_THEME_CLASS (games_card_theme_svg_parent_class)->load (card_theme, error))
     goto out;
 
@@ -82,14 +69,6 @@
 
 out:
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  totaltime += (t2 - t1);
-  g_print ("took %.3fs to create preimage (cumulative %.3fs)\n",
-           (t2 - t1) * 1.0 / CLOCKS_PER_SEC,
-           totaltime * 1.0 / CLOCKS_PER_SEC);
-#endif
-
   return retval;
 }
 

Modified: trunk/libgames-support/games-card-theme.c
==============================================================================
--- trunk/libgames-support/games-card-theme.c	(original)
+++ trunk/libgames-support/games-card-theme.c	Tue Jan  6 18:19:01 2009
@@ -28,6 +28,7 @@
 #include "games-find-file.h"
 #include "games-files.h"
 #include "games-preimage.h"
+#include "games-profile.h"
 #include "games-runtime.h"
 
 #include "games-card-theme.h"
@@ -47,14 +48,6 @@
 
 static GList *theme_infos;
 
-/* #defining this prints out the time it takes to render the theme */
-/* #define INSTRUMENT_LOADING */
-
-
-#ifdef INSTRUMENT_LOADING
-static long totaltime = 0;
-#endif
-
 #if 0
 static GType
 get_default_theme_type (void)
@@ -113,6 +106,8 @@
 
   theme_infos = NULL;
 
+  _games_profile_start ("looking for card themes");
+
   for (i = 0; i < G_N_ELEMENTS (types); ++i) {
     GamesCardThemeClass *klass;
 
@@ -120,10 +115,15 @@
     if (!klass)
       continue;
 
+    _games_profile_start ("looking for %s card themes", G_OBJECT_CLASS_NAME (klass));
     klass->get_theme_infos (klass, &theme_infos);
+    _games_profile_end ("looking for %s card themes", G_OBJECT_CLASS_NAME (klass));
+
     g_type_class_unref (klass);
   }
 
+  _games_profile_end ("looking for card themes");
+
   theme_infos = g_list_reverse (theme_infos);
 }
 
@@ -337,19 +337,26 @@
   GDir *iter;
   const char *filename;
 
+  _games_profile_start ("looking for %s card themes in %s", G_OBJECT_CLASS_NAME (klass), path);
+
   iter = g_dir_open (path, 0, NULL);
   if (!iter)
-    return;
+    goto out;
 
   while ((filename = g_dir_read_name (iter)) != NULL) {
     GamesCardThemeInfo *info;
 
+    _games_profile_start ("checking for %ss card theme in file %s", G_OBJECT_CLASS_NAME (klass), filename);
     info = _games_card_theme_class_get_theme_info (klass, path, filename);
+    _games_profile_end ("checking for %ss card theme in file %s", G_OBJECT_CLASS_NAME (klass), filename);
     if (info)
       *list = g_list_prepend (*list, info);
   }
       
   g_dir_close (iter);
+
+out:
+  _games_profile_end ("looking for %s card themes in %s", G_OBJECT_CLASS_NAME (klass), path);
 }
 
 void
@@ -484,28 +491,18 @@
  * Returns: a new #GdkPixbuf, or %NULL if there was an error
  */
 GdkPixbuf *
-games_card_theme_get_card_pixbuf (GamesCardTheme * theme, gint card_id)
+games_card_theme_get_card_pixbuf (GamesCardTheme *theme,
+                                  int card_id)
 {
   GdkPixbuf *pixbuf;
 
-  g_return_val_if_fail ((card_id >= 0)
-                        && (card_id < GAMES_CARDS_TOTAL), NULL);
+  g_return_val_if_fail ((card_id >= 0) && (card_id < GAMES_CARDS_TOTAL), NULL);
 
-#ifdef INSTRUMENT_LOADING
-  clock_t t1, t2;
-
-  t1 = clock ();
-#endif
+  _games_profile_start ("loading card %d from theme %s", card_id, theme->theme_info->display_name);
 
   pixbuf = theme->klass->get_card_pixbuf (theme, card_id);
 
-#ifdef INSTRUMENT_LOADING
-  t2 = clock ();
-  totaltime += (t2 - t1);
-  g_print ("took %.3fs to render card %d (cumulative: %.3fs)\n",
-           (t2 - t1) * 1.0 / CLOCKS_PER_SEC, card_id,
-           totaltime * 1.0 / CLOCKS_PER_SEC);
-#endif
+  _games_profile_end ("loading card %d from theme %s", card_id, theme->theme_info->display_name);
 
   return pixbuf;
 }
@@ -528,13 +525,17 @@
   if (info->type == G_TYPE_INVALID)
     return NULL;
 
+  _games_profile_start ("loading %s card theme %s", g_type_name (info->type), info->display_name);
+
   theme = g_object_new (info->type, "theme-info", info, NULL);
   if (!theme->klass->load (theme, &error)) {
     g_clear_error (&error);
     g_object_unref (theme);
-    return NULL;
+    theme = NULL;
   }
 
+  _games_profile_end ("loading %s card theme %s", g_type_name (info->type), info->display_name);
+
   return theme;
 }
 

Modified: trunk/libgames-support/games-card-theme.h
==============================================================================
--- trunk/libgames-support/games-card-theme.h	(original)
+++ trunk/libgames-support/games-card-theme.h	Tue Jan  6 18:19:01 2009
@@ -58,8 +58,8 @@
 #define GAMES_CARD_THEME_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_CARD_THEME, GamesCardThemeClass))
 
 typedef struct {
-  gint width;
-  gint height;
+  int width;
+  int height;
 } CardSize;
 
 typedef struct _GamesCardThemeClass GamesCardThemeClass;

Modified: trunk/libgames-support/games-preimage.c
==============================================================================
--- trunk/libgames-support/games-preimage.c	(original)
+++ trunk/libgames-support/games-preimage.c	Tue Jan  6 18:19:01 2009
@@ -33,6 +33,8 @@
 #include <librsvg/rsvg-cairo.h>
 #endif /* HAVE_RSVG */
 
+#include "games-profile.h"
+
 #include "games-preimage.h"
 #include "games-preimage-private.h"
 
@@ -269,6 +271,8 @@
 
   g_return_val_if_fail (filename != NULL, NULL);
 
+  _games_profile_start ("creating GamesPreimage from %s", filename);
+
   preimage = g_object_new (GAMES_TYPE_PREIMAGE, NULL);
 
 #ifdef HAVE_RSVG
@@ -280,6 +284,8 @@
 
     rsvg_handle_get_dimensions (preimage->rsvg_handle, &data);
 
+    _games_profile_end ("creating GamesPreimage from %s", filename);
+
     if (data.width == 0 || data.height == 0) {
       g_set_error (error,
                    GDK_PIXBUF_ERROR,
@@ -299,6 +305,8 @@
   preimage->scalable = FALSE;
 
   pixbuf = gdk_pixbuf_new_from_file (filename, error);
+  _games_profile_end ("creating GamesPreimage from %s", filename);
+
   if (!pixbuf) {
     g_object_unref (preimage);
     return NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]