subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1489883 - in /subversion/trunk/subversion: include/private/svn_cache.h libsvn_fs_fs/caching.c libsvn_subr/cache-membuffer.c libsvn_subr/cache.c
Date Wed, 05 Jun 2013 14:13:59 GMT
Author: stefan2
Date: Wed Jun  5 14:13:58 2013
New Revision: 1489883

URL: http://svn.apache.org/r1489883
Log:
Improve cache statistics in particular for membuffer caches:
- show index bucket usage distribution
- show size stats only as an option
- provide global membuffer stats
Update our reporting code to use all these nice features.

* subversion/include/private/svn_cache.h
  (svn_cache__info_t): add bucket fill level histogram
  (svn_cache__get_info): add option to reduce output
  (svn_cache__membuffer_get_global_info): new private API function

* subversion/libsvn_subr/cache.c
  (svn_cache__format_info): extend implementation

* subversion/libsvn_fs_fs/caching.c
  (dump_cache_statistics): access stats only; skip unused caches
  (dump_global_cache_statistics): new utility function
  (svn_fs_fs__initialize_caches): register global stats dump

* subversion/libsvn_subr/cache-membuffer.c
  (svn_membuffer_get_segment_info): optionally include histogram
  (svn_membuffer_cache_get_info): update caller
  (svn_membuffer_get_global_segment_info): new utility
  (svn_cache__membuffer_get_global_info): implement new private API

Modified:
    subversion/trunk/subversion/include/private/svn_cache.h
    subversion/trunk/subversion/libsvn_fs_fs/caching.c
    subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
    subversion/trunk/subversion/libsvn_subr/cache.c

Modified: subversion/trunk/subversion/include/private/svn_cache.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_cache.h?rev=1489883&r1=1489882&r2=1489883&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_cache.h (original)
+++ subversion/trunk/subversion/include/private/svn_cache.h Wed Jun  5 14:13:58 2013
@@ -173,6 +173,12 @@ typedef struct svn_cache__info_t
    * May be 0 if that information is not available.
    */
   apr_uint64_t total_entries;
+
+  /** Number of index buckets with the given number of entries.
+   * Bucket sizes larger than the array will saturate into the
+   * highest array index.
+   */
+  apr_uint64_t histogram[32];
 } svn_cache__info_t;
 
 /**
@@ -461,13 +467,16 @@ svn_cache__get_info(svn_cache__t *cache,
 
 /**
  * Return the information given in @a info formatted as a multi-line string.
- * Allocations take place in @a result_pool.
+ * If @a access_only has been set, size and fill-level statistics will be
+ * omitted.  Allocations take place in @a result_pool.
  */
 svn_string_t *
 svn_cache__format_info(const svn_cache__info_t *info,
+                       svn_boolean_t access_only,
                        apr_pool_t *result_pool);
 
-/* Access the process-global (singleton) membuffer cache. The first call
+/**
+ * Access the process-global (singleton) membuffer cache. The first call
  * will automatically allocate the cache using the current cache config.
  * NULL will be returned if the desired cache size is 0.
  *
@@ -476,6 +485,13 @@ svn_cache__format_info(const svn_cache__
 struct svn_membuffer_t *
 svn_cache__get_global_membuffer_cache(void);
 
+/**
+ * Return total access and size stats over all membuffer caches as they
+ * share the underlying data buffer.  The result will be allocated in POOL.
+ */
+svn_cache__info_t *
+svn_cache__membuffer_get_global_info(apr_pool_t *pool);
+
 /** @} */
 
 

Modified: subversion/trunk/subversion/libsvn_fs_fs/caching.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/caching.c?rev=1489883&r1=1489882&r2=1489883&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/caching.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/caching.c Wed Jun  5 14:13:58 2013
@@ -210,9 +210,10 @@ dump_cache_statistics(void *baton_void)
                                          TRUE,
                                          baton->pool);
 
-  if (! err)
+  /* skip unused caches */
+  if (! err && (info.gets > 0 || info.sets > 0))
     {
-      text_stats = svn_cache__format_info(&info, baton->pool);
+      text_stats = svn_cache__format_info(&info, TRUE, baton->pool);
       lines = svn_cstring_split(text_stats->data, "\n", FALSE, baton->pool);
 
       for (i = 0; i < lines->nelts; ++i)
@@ -233,6 +234,29 @@ dump_cache_statistics(void *baton_void)
 
   return result;
 }
+
+static apr_status_t
+dump_global_cache_statistics(void *baton_void)
+{
+  apr_pool_t *pool = baton_void;
+
+  svn_cache__info_t *info = svn_cache__membuffer_get_global_info(pool);
+  svn_string_t *text_stats = svn_cache__format_info(info, FALSE, pool);
+  apr_array_header_t *lines = svn_cstring_split(text_stats->data, "\n",
+                                                FALSE, pool);
+
+  int i;
+  for (i = 0; i < lines->nelts; ++i)
+    {
+      const char *line = APR_ARRAY_IDX(lines, i, const char *);
+#ifdef SVN_DEBUG
+      SVN_DBG(("%s\n", line));
+#endif
+    }
+
+  return APR_SUCCESS;
+}
+
 #endif /* SVN_DEBUG_CACHE_DUMP_STATS */
 
 /* This function sets / registers the required callbacks for a given
@@ -369,6 +393,18 @@ svn_fs_fs__initialize_caches(svn_fs_t *f
 
   membuffer = svn_cache__get_global_membuffer_cache();
 
+#ifdef SVN_DEBUG_CACHE_DUMP_STATS
+
+  /* schedule printing the global access statistics upon pool cleanup,
+    * i.e. end of FSFS session.
+    */
+  if (membuffer)
+    apr_pool_cleanup_register(pool,
+                              pool,
+                              dump_global_cache_statistics,
+                              apr_pool_cleanup_null);
+#endif
+
   /* Make the cache for revision roots.  For the vast majority of
    * commands, this is only going to contain a few entries (svnadmin
    * dump/verify is an exception here), so to reduce overhead let's

Modified: subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c?rev=1489883&r1=1489882&r2=1489883&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-membuffer.c Wed Jun  5 14:13:58 2013
@@ -31,6 +31,7 @@
 #include "svn_private_config.h"
 #include "cache.h"
 #include "svn_string.h"
+#include "svn_sorts.h"  /* get the MIN macro */
 #include "private/svn_dep_compat.h"
 #include "private/svn_mutex.h"
 #include "private/svn_pseudo_md5.h"
@@ -2423,12 +2424,16 @@ svn_membuffer_cache_is_cachable(void *ca
   return size <= cache->membuffer->max_entry_size;
 }
 
-/* Add statistics of SEGMENT to INFO.
+/* Add statistics of SEGMENT to INFO.  If INCLUDE_HISTOGRAM is TRUE,
+ * accumulate index bucket fill levels in INFO->HISTOGRAM.
  */
 static svn_error_t *
 svn_membuffer_get_segment_info(svn_membuffer_t *segment,
-                               svn_cache__info_t *info)
+                               svn_cache__info_t *info,
+                               svn_boolean_t include_histogram)
 {
+  apr_size_t i;
+
   info->data_size += segment->l1.size + segment->l2.size;
   info->used_size += segment->data_used;
   info->total_size += segment->l1.size + segment->l2.size +
@@ -2437,6 +2442,15 @@ svn_membuffer_get_segment_info(svn_membu
   info->used_entries += segment->used_entries;
   info->total_entries += segment->group_count * GROUP_SIZE;
 
+  if (include_histogram)
+    for (i = 0; i < segment->group_count; ++i)
+      {
+        apr_size_t use
+          = MIN(segment->directory[i].used,
+                sizeof(info->histogram) / sizeof(info->histogram[0]) - 1);
+        info->histogram[use]++;
+      }
+
   return SVN_NO_ERROR;
 }
 
@@ -2462,7 +2476,7 @@ svn_membuffer_cache_get_info(void *cache
     {
       svn_membuffer_t *segment = cache->membuffer + i;
       WITH_READ_LOCK(segment,
-                     svn_membuffer_get_segment_info(segment, info));
+                     svn_membuffer_get_segment_info(segment, info, FALSE));
     }
 
   return SVN_NO_ERROR;
@@ -2690,3 +2704,37 @@ svn_cache__create_membuffer_cache(svn_ca
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+svn_membuffer_get_global_segment_info(svn_membuffer_t *segment,
+                                      svn_cache__info_t *info)
+{
+  info->gets += segment->total_reads;
+  info->sets += segment->total_writes;
+  info->hits += segment->total_hits;
+
+  WITH_READ_LOCK(segment,
+                  svn_membuffer_get_segment_info(segment, info, TRUE));
+
+  return SVN_NO_ERROR;
+}
+
+svn_cache__info_t *
+svn_cache__membuffer_get_global_info(apr_pool_t *pool)
+{
+  apr_uint32_t i;
+
+  svn_membuffer_t *membuffer = svn_cache__get_global_membuffer_cache();
+  svn_cache__info_t *info = apr_pcalloc(pool, sizeof(*info));
+
+  /* cache front-end specific data */
+
+  info->id = "membuffer globals";
+
+  /* collect info from shared cache back-end */
+
+  for (i = 0; i < membuffer->segment_count; ++i)
+    svn_error_clear(svn_membuffer_get_global_segment_info(membuffer + i,
+                                                          info));
+
+  return info;
+}

Modified: subversion/trunk/subversion/libsvn_subr/cache.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache.c?rev=1489883&r1=1489882&r2=1489883&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache.c Wed Jun  5 14:13:58 2013
@@ -222,6 +222,7 @@ svn_cache__get_info(svn_cache__t *cache,
 
 svn_string_t *
 svn_cache__format_info(const svn_cache__info_t *info,
+                       svn_boolean_t access_only,
                        apr_pool_t *result_pool)
 {
   enum { _1MB = 1024 * 1024 };
@@ -236,9 +237,40 @@ svn_cache__format_info(const svn_cache__
   double data_entry_rate = (100.0 * (double)info->used_entries)
                  / (double)(info->total_entries ? info->total_entries : 1);
 
-  return svn_string_createf(result_pool,
+  const char *histogram = "";
+  if (!access_only)
+    {
+      svn_stringbuf_t *text = svn_stringbuf_create_empty(result_pool);
+
+      int i;
+      int count = sizeof(info->histogram) / sizeof(info->histogram[0]);
+      for (i = 0; i < count; ++i)
+        if (info->histogram[i] > 0 || text->len > 0)
+          text = svn_stringbuf_createf(result_pool,
+                                       i == count - 1
+                                         ? "%12" APR_UINT64_T_FMT
+                                           " buckets with >%d entries\n%s"
+                                         : "%12" APR_UINT64_T_FMT
+                                           " buckets with %d entries\n%s",
+                                        info->histogram[i], i, text->data);
+
+      histogram = text->data;
+    }
+
+  return access_only
+       ? svn_string_createf(result_pool,
+                            "%s\n"
+                            "gets    : %" APR_UINT64_T_FMT
+                            ", %" APR_UINT64_T_FMT " hits (%5.2f%%)\n"
+                            "sets    : %" APR_UINT64_T_FMT
+                            " (%5.2f%% of misses)\n",
+                            info->id,
+                            info->gets,
+                            info->hits, hit_rate,
+                            info->sets, write_rate)
+       : svn_string_createf(result_pool,
 
-                            "prefix  : %s\n"
+                            "%s\n"
                             "gets    : %" APR_UINT64_T_FMT
                             ", %" APR_UINT64_T_FMT " hits (%5.2f%%)\n"
                             "sets    : %" APR_UINT64_T_FMT
@@ -248,7 +280,7 @@ svn_cache__format_info(const svn_cache__
                             " of %" APR_UINT64_T_FMT " MB data cache"
                             " / %" APR_UINT64_T_FMT " MB total cache memory\n"
                             "          %" APR_UINT64_T_FMT " entries (%5.2f%%)"
-                            " of %" APR_UINT64_T_FMT " total\n",
+                            " of %" APR_UINT64_T_FMT " total\n%s",
 
                             info->id,
 
@@ -262,5 +294,6 @@ svn_cache__format_info(const svn_cache__
                             info->total_size / _1MB,
 
                             info->used_entries, data_entry_rate,
-                            info->total_entries);
+                            info->total_entries,
+                            histogram);
 }



Mime
View raw message