gnome-games r8484 - trunk/libgames-support
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8484 - trunk/libgames-support
- Date: Tue, 6 Jan 2009 18:20:05 +0000 (UTC)
Author: chpe
Date: Tue Jan 6 18:20:05 2009
New Revision: 8484
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8484&view=rev
Log:
Add cache hit/miss logging.
Modified:
trunk/libgames-support/games-card-images.c
trunk/libgames-support/games-card-images.h
trunk/libgames-support/games-card-textures-cache.c
Modified: trunk/libgames-support/games-card-images.c
==============================================================================
--- trunk/libgames-support/games-card-images.c (original)
+++ trunk/libgames-support/games-card-images.c Tue Jan 6 18:20:05 2009
@@ -33,6 +33,29 @@
#include "games-card-private.h"
#include "games-debug.h"
+struct _GamesCardImagesClass {
+ GObjectClass parent_class;
+};
+
+struct _GamesCardImages {
+ GObject parent;
+
+ GamesCardTheme *theme;
+ GdkDrawable *drawable;
+ GdkBitmap *card_mask;
+ GdkBitmap *slot_mask;
+ gpointer *cache;
+ GdkColor background_colour;
+ GdkColor selection_colour;
+
+ guint cache_mode;
+
+#ifdef GNOME_ENABLE_DEBUG
+ guint n_calls;
+ guint cache_hits;
+#endif
+};
+
enum {
PROP_0,
PROP_THEME
@@ -61,6 +84,17 @@
#define CARD_ALPHA_THRESHOLD (127)
#define SLOT_ALPHA_THRESHOLD (255)
+/* Logging */
+#ifdef GNOME_ENABLE_DEBUG
+#define LOG_CALL(obj) obj->n_calls++
+#define LOG_CACHE_HIT(obj) obj->cache_hits++
+#define LOG_CACHE_MISS(obj)
+#else
+#define LOG_CALL(obj)
+#define LOG_CACHE_HIT(obj)
+#define LOG_CACHE_MISS(obj)
+#endif /* GNOME_ENABLE_DEBUG */
+
static void
games_card_images_clear_cache (GamesCardImages * images)
{
@@ -201,6 +235,15 @@
g_object_unref (images->theme);
}
+#ifdef GNOME_ENABLE_DEBUG
+ _GAMES_DEBUG_IF (GAMES_DEBUG_CARD_CACHE) {
+ _games_debug_print (GAMES_DEBUG_CARD_CACHE,
+ "GamesCardImages %p statistics: %u calls with %u hits and %u misses for a hit/total of %.3f\n",
+ images, images->n_calls, images->cache_hits, images->n_calls - images->cache_hits,
+ images->n_calls > 0 ? (double) images->cache_hits / (double) images->n_calls : 0.0);
+ }
+#endif
+
G_OBJECT_CLASS (games_card_images_parent_class)->finalize (object);
}
@@ -481,14 +524,18 @@
&& (card_id < GAMES_CARDS_TOTAL), NULL);
g_return_val_if_fail (images->cache_mode == CACHE_PIXBUFS, NULL);
+ LOG_CALL (images);
+
idx = card_id;
if (G_UNLIKELY (highlighted)) {
idx += GAMES_CARDS_TOTAL;
}
data = images->cache[idx];
- if (IS_FAILED_POINTER (data))
+ if (IS_FAILED_POINTER (data)) {
+ LOG_CACHE_HIT (images);
return NULL;
+ }
pixbuf = UNMARK_POINTER (data);
@@ -497,9 +544,12 @@
(!highlighted || HAS_MARK (data, MARK_IS_TRANSFORMED))) {
g_assert (!HAS_MARK (data, MARK_IS_PIXMAP));
g_assert (GDK_IS_PIXBUF (pixbuf));
+ LOG_CACHE_HIT (images);
return pixbuf;
}
+ LOG_CACHE_MISS (images);
+
/* Create the pixbuf */
if (!pixbuf) {
pixbuf = create_pixbuf (images, card_id);
@@ -576,14 +626,18 @@
g_return_val_if_fail (images->cache_mode == CACHE_PIXMAPS, NULL);
g_return_val_if_fail (images->drawable != NULL, NULL);
+ LOG_CALL (images);
+
idx = card_id;
if (G_UNLIKELY (highlighted)) {
idx += GAMES_CARDS_TOTAL;
}
data = images->cache[idx];
- if (IS_FAILED_POINTER (data))
+ if (IS_FAILED_POINTER (data)) {
+ LOG_CACHE_HIT (images);
return NULL;
+ }
pixbuf_or_pixmap = UNMARK_POINTER (data);
@@ -592,9 +646,12 @@
g_assert (!highlighted || HAS_MARK (data, MARK_IS_TRANSFORMED));
g_assert (GDK_IS_PIXMAP (pixbuf_or_pixmap));
+ LOG_CACHE_HIT (images);
return pixbuf_or_pixmap;
}
+ LOG_CACHE_MISS (images);
+
/* We either have a pixbuf, or need to create it first */
if (!pixbuf_or_pixmap) {
pixbuf = create_pixbuf (images, card_id);
Modified: trunk/libgames-support/games-card-images.h
==============================================================================
--- trunk/libgames-support/games-card-images.h (original)
+++ trunk/libgames-support/games-card-images.h Tue Jan 6 18:20:05 2009
@@ -45,21 +45,8 @@
LAST_CACHE_MODE
} GamesCardImagesCacheMode;
-typedef struct _GamesCardImages {
- GObject parent;
-
- GamesCardTheme *theme;
- GdkDrawable *drawable;
- GdkBitmap *card_mask;
- GdkBitmap *slot_mask;
- gpointer *cache;
- GdkColor background_colour;
- GdkColor selection_colour;
-
- guint cache_mode;
-} GamesCardImages;
-
-typedef GObjectClass GamesCardImagesClass;
+typedef struct _GamesCardImages GamesCardImages;
+typedef struct _GamesCardImagesClass GamesCardImagesClass;;
GType games_card_images_get_type (void);
Modified: trunk/libgames-support/games-card-textures-cache.c
==============================================================================
--- trunk/libgames-support/games-card-textures-cache.c (original)
+++ trunk/libgames-support/games-card-textures-cache.c Tue Jan 6 18:20:05 2009
@@ -34,6 +34,11 @@
guint theme_changed_handler;
CoglHandle *cards;
+
+#ifdef GNOME_ENABLE_DEBUG
+ guint n_calls;
+ guint cache_hits;
+#endif
};
enum
@@ -46,6 +51,17 @@
#define FAILED_HANDLE ((gpointer) 0x1)
#define IS_FAILED_HANDLE(ptr) (G_UNLIKELY ((ptr) == FAILED_HANDLE))
+/* Logging */
+#ifdef GNOME_ENABLE_DEBUG
+#define LOG_CALL(obj) obj->priv->n_calls++
+#define LOG_CACHE_HIT(obj) obj->priv->cache_hits++
+#define LOG_CACHE_MISS(obj)
+#else
+#define LOG_CALL(obj)
+#define LOG_CACHE_HIT(obj)
+#define LOG_CACHE_MISS(obj)
+#endif /* GNOME_ENABLE_DEBUG */
+
static void games_card_textures_cache_dispose (GObject *object);
static void games_card_textures_cache_finalize (GObject *object);
@@ -115,11 +131,20 @@
static void
games_card_textures_cache_finalize (GObject *object)
{
- GamesCardTexturesCache *self = (GamesCardTexturesCache *) object;
- GamesCardTexturesCachePrivate *priv = self->priv;
+ GamesCardTexturesCache *cache = GAMES_CARD_TEXTURES_CACHE (object);
+ GamesCardTexturesCachePrivate *priv = cache->priv;
g_free (priv->cards);
+#ifdef GNOME_ENABLE_DEBUG
+ _GAMES_DEBUG_IF (GAMES_DEBUG_CARD_CACHE) {
+ _games_debug_print (GAMES_DEBUG_CARD_CACHE,
+ "GamesCardTexturesCache %p statistics: %u calls with %u hits and %u misses for a hit/total of %.3f\n",
+ cache, priv->n_calls, priv->cache_hits, priv->n_calls - priv->cache_hits,
+ priv->n_calls > 0 ? (double) priv->cache_hits / (double) priv->n_calls : 0.0);
+ }
+#endif
+
G_OBJECT_CLASS (games_card_textures_cache_parent_class)->finalize (object);
}
@@ -261,13 +286,19 @@
g_return_val_if_fail (card_id < GAMES_CARDS_TOTAL , NULL);
+ LOG_CALL (cache);
+
handle = priv->cards[card_id];
- if (IS_FAILED_HANDLE (handle))
+ if (IS_FAILED_HANDLE (handle)) {
+ LOG_CACHE_HIT (cache);
return COGL_INVALID_HANDLE;
+ }
if (handle == COGL_INVALID_HANDLE) {
GdkPixbuf *pixbuf;
+ LOG_CACHE_MISS (cache);
+
pixbuf = games_card_theme_get_card_pixbuf (priv->theme, card_id);
if (!pixbuf) {
priv->cards[card_id] = FAILED_HANDLE;
@@ -291,6 +322,8 @@
}
priv->cards[card_id] = handle;
+ } else {
+ LOG_CACHE_HIT (cache);
}
return handle;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]