[gegl] gegl-stats: add more stats
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gegl-stats: add more stats
- Date: Sat, 30 Dec 2017 18:56:52 +0000 (UTC)
commit 25c39ce6c9bb618f06ac96d118e624be66464d74
Author: Ell <ell_se yahoo com>
Date: Sat Dec 30 13:27:46 2017 -0500
gegl-stats: add more stats
Add the following properties to GeglStats:
- cache-total-max: The maximal total size of the cache,
throughout the session.
- cache-total-uncloned: The total size the cache would have had
if all cached tiles were uncloned.
- cache-hits: Number of cache hits.
- cache-misses Number of cache misses.
gegl/buffer/gegl-tile-handler-cache.c | 57 ++++++++++++++++++++++++++++-----
gegl/buffer/gegl-tile-handler-cache.h | 24 ++++++++------
gegl/gegl-stats.c | 48 +++++++++++++++++++++++++++
3 files changed, 111 insertions(+), 18 deletions(-)
---
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index a41442c..aee0d83 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -91,10 +91,10 @@ static GMutex mutex = { 0, };
static GQueue *cache_queue = NULL;
static gint cache_wash_percentage = 20;
static volatile guintptr cache_total = 0; /* approximate amount of bytes stored */
-#ifdef GEGL_DEBUG_CACHE_HITS
+static guintptr cache_total_max = 0; /* maximal value of cache_total */
+static guintptr cache_total_uncloned = 0; /* approximate amount of uncloned bytes stored */
static gint cache_hits = 0;
static gint cache_misses = 0;
-#endif
G_DEFINE_TYPE (GeglTileHandlerCache, gegl_tile_handler_cache, GEGL_TYPE_TILE_HANDLER)
@@ -167,6 +167,7 @@ gegl_tile_handler_cache_reinit (GeglTileHandlerCache *cache)
{
if (g_atomic_int_dec_and_test (gegl_tile_n_cached_clones (item->tile)))
g_atomic_pointer_add (&cache_total, -item->tile->size);
+ cache_total_uncloned -= item->tile->size;
drop_hot_tile (item->tile);
gegl_tile_mark_as_stored (item->tile); // to avoid saving
item->tile->tile_storage = NULL;
@@ -214,14 +215,13 @@ gegl_tile_handler_cache_get_tile_command (GeglTileSource *tile_store,
tile = gegl_tile_handler_cache_get_tile (cache, x, y, z);
if (tile)
{
-#ifdef GEGL_DEBUG_CACHE_HITS
+ /* we don't bother making cache_{hits,misses} atomic, since they're only
+ * needed for GeglStats.
+ */
cache_hits++;
-#endif
return tile;
}
-#ifdef GEGL_DEBUG_CACHE_HITS
cache_misses++;
-#endif
if (source)
tile = gegl_tile_source_get_tile (source, x, y, z);
@@ -485,6 +485,7 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
g_hash_table_remove (last_writable->handler->items, last_writable);
if (g_atomic_int_dec_and_test (gegl_tile_n_cached_clones (tile)))
g_atomic_pointer_add (&cache_total, -tile->size);
+ cache_total_uncloned -= tile->size;
last_writable->handler->count--;
/* drop_hot_tile (tile); */ /* XXX: no use in trying to drop the hot
* tile, since this tile can't be it --
@@ -519,6 +520,7 @@ gegl_tile_handler_cache_invalidate (GeglTileHandlerCache *cache,
{
if (g_atomic_int_dec_and_test (gegl_tile_n_cached_clones (item->tile)))
g_atomic_pointer_add (&cache_total, -item->tile->size);
+ cache_total_uncloned -= item->tile->size;
cache->count--;
g_queue_unlink (cache_queue, &item->link);
@@ -552,6 +554,7 @@ gegl_tile_handler_cache_void (GeglTileHandlerCache *cache,
{
if (g_atomic_int_dec_and_test (gegl_tile_n_cached_clones (item->tile)))
g_atomic_pointer_add (&cache_total, -item->tile->size);
+ cache_total_uncloned -= item->tile->size;
g_queue_unlink (cache_queue, &item->link);
g_hash_table_remove (cache->items, item);
cache->count--;
@@ -600,6 +603,7 @@ gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
g_mutex_lock (&mutex);
if (g_atomic_int_add (gegl_tile_n_cached_clones (tile), 1) == 0)
g_atomic_pointer_add (&cache_total, tile->size);
+ cache_total_uncloned += item->tile->size;
g_queue_push_head_link (cache_queue, &item->link);
cache->count ++;
@@ -608,6 +612,13 @@ gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
gegl_tile_handler_cache_trim (cache);
+ /* there's a race between this assignment, and the one at the bottom of
+ * gegl_tile_handler_cache_tile_uncloned(). this is acceptable, though,
+ * since we only need cache_total_max for GeglStats, so its accuracy is not
+ * ciritical.
+ */
+ cache_total_max = MAX (cache_total_max, cache_total);
+
g_mutex_unlock (&mutex);
}
@@ -615,8 +626,12 @@ void
gegl_tile_handler_cache_tile_uncloned (GeglTileHandlerCache *cache,
GeglTile *tile)
{
- if ((guintptr) g_atomic_pointer_add (&cache_total, tile->size) + tile->size >
- gegl_config ()->tile_cache_size)
+ guintptr total;
+
+ total = (guintptr) g_atomic_pointer_add (&cache_total, tile->size) +
+ tile->size;
+
+ if (total > gegl_config ()->tile_cache_size)
{
g_mutex_lock (&mutex);
@@ -624,6 +639,8 @@ gegl_tile_handler_cache_tile_uncloned (GeglTileHandlerCache *cache,
g_mutex_unlock (&mutex);
}
+
+ cache_total_max = MAX (cache_total_max, total);
}
GeglTileHandler *
@@ -638,6 +655,30 @@ gegl_tile_handler_cache_get_total (void)
return cache_total;
}
+gsize
+gegl_tile_handler_cache_get_total_max (void)
+{
+ return cache_total_max;
+}
+
+gsize
+gegl_tile_handler_cache_get_total_uncloned (void)
+{
+ return cache_total_uncloned;
+}
+
+gint
+gegl_tile_handler_cache_get_hits (void)
+{
+ return cache_hits;
+}
+
+gint
+gegl_tile_handler_cache_get_misses (void)
+{
+ return cache_misses;
+}
+
static guint
gegl_tile_handler_cache_hashfunc (gconstpointer key)
diff --git a/gegl/buffer/gegl-tile-handler-cache.h b/gegl/buffer/gegl-tile-handler-cache.h
index 913340a..568dfa0 100644
--- a/gegl/buffer/gegl-tile-handler-cache.h
+++ b/gegl/buffer/gegl-tile-handler-cache.h
@@ -49,18 +49,22 @@ struct _GeglTileHandlerCacheClass
GeglTileHandlerClass parent_class;
};
-GType gegl_tile_handler_cache_get_type (void) G_GNUC_CONST;
+GType gegl_tile_handler_cache_get_type (void) G_GNUC_CONST;
-GeglTileHandler * gegl_tile_handler_cache_new (void);
+GeglTileHandler * gegl_tile_handler_cache_new (void);
-void gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
- GeglTile *tile,
- gint x,
- gint y,
- gint z);
-void gegl_tile_handler_cache_tile_uncloned (GeglTileHandlerCache *cache,
- GeglTile *tile);
+void gegl_tile_handler_cache_insert (GeglTileHandlerCache *cache,
+ GeglTile *tile,
+ gint x,
+ gint y,
+ gint z);
+void gegl_tile_handler_cache_tile_uncloned (GeglTileHandlerCache *cache,
+ GeglTile *tile);
-gsize gegl_tile_handler_cache_get_total (void);
+gsize gegl_tile_handler_cache_get_total (void);
+gsize gegl_tile_handler_cache_get_total_max (void);
+gsize gegl_tile_handler_cache_get_total_uncloned (void);
+gint gegl_tile_handler_cache_get_hits (void);
+gint gegl_tile_handler_cache_get_misses (void);
#endif
diff --git a/gegl/gegl-stats.c b/gegl/gegl-stats.c
index ab82926..a986cd6 100644
--- a/gegl/gegl-stats.c
+++ b/gegl/gegl-stats.c
@@ -32,6 +32,10 @@ enum
{
PROP_0,
PROP_TILE_CACHE_TOTAL,
+ PROP_TILE_CACHE_TOTAL_MAX,
+ PROP_TILE_CACHE_TOTAL_UNCLONED,
+ PROP_TILE_CACHE_HITS,
+ PROP_TILE_CACHE_MISSES,
PROP_SWAP_TOTAL,
PROP_SWAP_FILE_SIZE,
PROP_SWAP_BUSY
@@ -66,6 +70,34 @@ gegl_stats_class_init (GeglStatsClass *klass)
0, G_MAXUINT64, 0,
G_PARAM_READABLE));
+ g_object_class_install_property (object_class, PROP_TILE_CACHE_TOTAL_MAX,
+ g_param_spec_uint64 ("tile-cache-total-max",
+ "Tile Cache maximal total size",
+ "Maximal total size of tile cache throughout the
session in bytes",
+ 0, G_MAXUINT64, 0,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class, PROP_TILE_CACHE_TOTAL_UNCLONED,
+ g_param_spec_uint64 ("tile-cache-total-uncloned",
+ "Tile Cache total uncloned size",
+ "Total size of tile cache if all tiles were uncloned
in bytes",
+ 0, G_MAXUINT64, 0,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class, PROP_TILE_CACHE_HITS,
+ g_param_spec_int ("tile-cache-hits",
+ "Tile Cache hits",
+ "Number of tile cache hits",
+ 0, G_MAXINT, 0,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class, PROP_TILE_CACHE_MISSES,
+ g_param_spec_int ("tile-cache-misses",
+ "Tile Cache misses",
+ "Number of tile cache misses",
+ 0, G_MAXINT, 0,
+ G_PARAM_READABLE));
+
g_object_class_install_property (object_class, PROP_SWAP_TOTAL,
g_param_spec_uint64 ("swap-total",
"Swap total size",
@@ -119,6 +151,22 @@ gegl_stats_get_property (GObject *object,
g_value_set_uint64 (value, gegl_tile_handler_cache_get_total ());
break;
+ case PROP_TILE_CACHE_TOTAL_MAX:
+ g_value_set_uint64 (value, gegl_tile_handler_cache_get_total_max ());
+ break;
+
+ case PROP_TILE_CACHE_TOTAL_UNCLONED:
+ g_value_set_uint64 (value, gegl_tile_handler_cache_get_total_uncloned ());
+ break;
+
+ case PROP_TILE_CACHE_HITS:
+ g_value_set_int (value, gegl_tile_handler_cache_get_hits ());
+ break;
+
+ case PROP_TILE_CACHE_MISSES:
+ g_value_set_int (value, gegl_tile_handler_cache_get_misses ());
+ break;
+
case PROP_SWAP_TOTAL:
g_value_set_uint64 (value, gegl_tile_backend_swap_get_total ());
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]