You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2011/03/13 14:46:41 UTC
svn commit: r1081114 - in /subversion/trunk/subversion:
include/private/svn_cache.h libsvn_subr/cache-inprocess.c
libsvn_subr/cache-membuffer.c libsvn_subr/cache-memcache.c
libsvn_subr/cache.c libsvn_subr/cache.h
Author: stefan2
Date: Sun Mar 13 13:46:41 2011
New Revision: 1081114
URL: http://svn.apache.org/viewvc?rev=1081114&view=rev
Log:
Add internal statistics functions to SVN cache API.
* subversion/include/private/svn_cache.h
(svn_cache__info_t): new structure
(svn_cache__get_info, svn_cache__format_info): new internal API
* subversion/libsvn_subr/cache.h
(svn_cache__vtable_t): extend vtable to cover the new function
* subversion/libsvn_subr/cache.c
(svn_cache__get_info, svn_cache__format_info): implement new API
* subversion/libsvn_subr/cache-inprocess.c
(inprocess_cache_get_info): implement new API
(inprocess_cache_vtable): extend vtable
* subversion/libsvn_subr/cache-membuffer.c
(svn_membuffer_cache_t, svn_cache__create_membuffer_cache):
store id as well
(svn_membuffer_cache_get_info): implement new API
(membuffer_cache_vtable): extend vtable
* subversion/libsvn_subr/cache-memcache.c
(memcache_get_info): implement new API
(memcache_vtable): extend vtable
Modified:
subversion/trunk/subversion/include/private/svn_cache.h
subversion/trunk/subversion/libsvn_subr/cache-inprocess.c
subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
subversion/trunk/subversion/libsvn_subr/cache-memcache.c
subversion/trunk/subversion/libsvn_subr/cache.c
subversion/trunk/subversion/libsvn_subr/cache.h
Modified: subversion/trunk/subversion/include/private/svn_cache.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_cache.h?rev=1081114&r1=1081113&r2=1081114&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_cache.h (original)
+++ subversion/trunk/subversion/include/private/svn_cache.h Sun Mar 13 13:46:41 2011
@@ -35,7 +35,7 @@
#include "svn_error.h"
#include "svn_iter.h"
#include "svn_config.h"
-
+#include "svn_string.h"
#ifdef __cplusplus
extern "C" {
@@ -106,6 +106,61 @@ typedef struct svn_membuffer_t svn_membu
typedef struct svn_cache__t svn_cache__t;
/**
+ * A structure containing typical statistics about a given cache instance.
+ * Use @ref svn_cache__get_info to get this data. Note that not all types
+ * of caches will be able to report complete and correct information.
+ */
+typedef struct svn_cache__info_t
+{
+ /** A string identifying the cache instance. Usually a copy of the @a id
+ * or @a prefix parameter passed to the cache constructor.
+ */
+ const char* id;
+
+ /** Number of getter calls (@ref svn_cache__get or @ref svn_cache__get).
+ */
+ apr_uint64_t gets;
+
+ /** Number of getter calls that return data.
+ */
+ apr_uint64_t hits;
+
+ /** Number of setter calls (@ref svn_cache__set).
+ */
+ apr_uint64_t sets;
+
+ /** Number of function calls that returned an error.
+ */
+ apr_uint64_t failures;
+
+ /** Size of the data currently stored in the cache.
+ * May be 0 if that information is not available.
+ */
+ apr_size_t used_size;
+
+ /** Amount of memory currently reserved for cached data.
+ * Will be equal to @a used_size if no precise information is available.
+ */
+ apr_size_t data_size;
+
+ /** Lower threshold of the total size of memory allocated to the cache and
+ * its index as well as management structures. The actual memory allocated
+ * by the cache may be larger.
+ */
+ apr_size_t total_size;
+
+ /** Number of cache entries.
+ * May be 0 if that information is not available.
+ */
+ apr_size_t used_entries;
+
+ /** Maximum numbers of cache entries.
+ * May be 0 if that information is not available.
+ */
+ apr_size_t total_entries;
+} svn_cache__info_t;
+
+/**
* Creates a new cache in @a *cache_p. This cache will use @a pool
* for all of its storage needs. The elements in the cache will be
* indexed by keys of length @a klen, which may be APR_HASH_KEY_STRING
@@ -332,6 +387,26 @@ svn_cache__get_partial(void **value,
svn_cache__partial_getter_func_t func,
void *baton,
apr_pool_t *scratch_pool);
+
+/**
+ * Collect all available usage statistics on the cache instance @a cache
+ * and write the data into @a info. If @a reset has been set, access
+ * counters will be reset right after copying the statistics info.
+ * @a pool will be used for allocations.
+ */
+svn_error_t *
+svn_cache__get_info(svn_cache__t *cache,
+ svn_cache__info_t *info,
+ svn_boolean_t reset,
+ apr_pool_t *pool);
+
+/**
+ * Return the information given in @a info formatted as a multi-line string.
+ * Allocations take place in @a pool.
+ */
+svn_string_t *
+svn_cache__format_info(const svn_cache__info_t *info,
+ apr_pool_t *pool);
/** @} */
Modified: subversion/trunk/subversion/libsvn_subr/cache-inprocess.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-inprocess.c?rev=1081114&r1=1081113&r2=1081114&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-inprocess.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-inprocess.c Sun Mar 13 13:46:41 2011
@@ -493,12 +493,39 @@ inprocess_cache_is_cachable(void *cache_
return size < SVN_ALLOCATOR_RECOMMENDED_MAX_FREE / cache->items_per_page;
}
+static svn_error_t *
+inprocess_cache_get_info(void *cache_void,
+ svn_cache__info_t *info,
+ svn_boolean_t reset,
+ apr_pool_t *pool)
+{
+ inprocess_cache_t *cache = cache_void;
+
+ SVN_ERR(lock_cache(cache));
+
+ info->id = apr_pstrdup(pool, cache->id);
+
+ info->used_entries = apr_hash_count(cache->hash);
+ info->total_entries = (apr_size_t)(cache->items_per_page *
+ cache->total_pages);
+
+ info->used_size = cache->data_size;
+ info->data_size = cache->data_size;
+ info->total_size = cache->data_size
+ + cache->items_per_page * sizeof(struct cache_page)
+ + info->used_entries * sizeof(struct cache_entry);
+
+ return unlock_cache(cache, SVN_NO_ERROR);
+}
+
+
static svn_cache__vtable_t inprocess_cache_vtable = {
inprocess_cache_get,
inprocess_cache_set,
inprocess_cache_iter,
inprocess_cache_is_cachable,
- inprocess_cache_get_partial
+ inprocess_cache_get_partial,
+ inprocess_cache_get_info
};
svn_error_t *
Modified: subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c?rev=1081114&r1=1081113&r2=1081114&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-membuffer.c Sun Mar 13 13:46:41 2011
@@ -1270,6 +1270,11 @@ typedef struct svn_membuffer_cache_t
*/
unsigned char prefix [APR_MD5_DIGESTSIZE];
+ /* A copy of the unmodified prefix. It is being used as a user-visible
+ * ID for this cache instance.
+ */
+ const char* full_prefix;
+
/* length of the keys that will be passed to us through the
* svn_cache_t interface. May be APR_HASH_KEY_STRING.
*/
@@ -1481,6 +1486,49 @@ svn_membuffer_cache_is_cachable(void *ca
&& (size < APR_UINT32_MAX - ITEM_ALIGNMENT);
}
+static svn_error_t *
+svn_membuffer_cache_get_info(void *cache_void,
+ svn_cache__info_t *info,
+ svn_boolean_t reset,
+ apr_pool_t *pool)
+{
+ svn_membuffer_cache_t *cache = cache_void;
+ apr_uint32_t i;
+
+ /* cache frontend specific data */
+
+ info->id = apr_pstrdup(pool, cache->full_prefix);
+
+ /* collect info from shared cache backend */
+
+ info->data_size = 0;
+ info->used_size = 0;
+ info->total_size = 0;
+
+ info->used_entries = 0;
+ info->total_entries = 0;
+
+ for (i = 0; i < CACHE_SEGMENTS; ++i)
+ {
+ svn_membuffer_t *segment = cache->membuffer + i;
+
+ SVN_ERR(lock_cache(segment));
+
+ info->data_size += segment->data_size;
+ info->used_size += segment->data_used;
+ info->total_size += segment->data_size +
+ segment->group_count * GROUP_SIZE * sizeof(entry_t);
+
+ info->used_entries += segment->used_entries;
+ info->total_entries += segment->group_count * GROUP_SIZE;
+
+ SVN_ERR(unlock_cache(segment, SVN_NO_ERROR));
+ }
+
+ return SVN_NO_ERROR;
+}
+
+
/* the v-table for membuffer-based caches
*/
static svn_cache__vtable_t membuffer_cache_vtable = {
@@ -1488,7 +1536,8 @@ static svn_cache__vtable_t membuffer_cac
svn_membuffer_cache_set,
svn_membuffer_cache_iter,
svn_membuffer_cache_is_cachable,
- svn_membuffer_cache_get_partial
+ svn_membuffer_cache_get_partial,
+ svn_membuffer_cache_get_info
};
/* standard serialization function for svn_stringbuf_t items
@@ -1551,6 +1600,7 @@ svn_cache__create_membuffer_cache(svn_ca
cache->deserializer = deserializer
? deserializer
: deserialize_svn_stringbuf;
+ cache->full_prefix = apr_pstrdup(pool, prefix);
cache->key_len = klen;
cache->pool = svn_pool_create(pool);
cache->alloc_counter = 0;
Modified: subversion/trunk/subversion/libsvn_subr/cache-memcache.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-memcache.c?rev=1081114&r1=1081113&r2=1081114&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-memcache.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-memcache.c Sun Mar 13 13:46:41 2011
@@ -281,12 +281,36 @@ memcache_is_cachable(void *unused, apr_s
return size < 1000000;
}
+static svn_error_t *
+memcache_get_info(void *cache_void,
+ svn_cache__info_t *info,
+ svn_boolean_t reset,
+ apr_pool_t *pool)
+{
+ memcache_t *cache = cache_void;
+
+ SVN_ERR(lock_cache(cache));
+
+ info->id = apr_pstrdup(pool, cache->prefix);
+
+ /* we don't have any memory allocation info */
+
+ info->used_size = 0;
+ info->total_size = 0;
+ info->data_size = 0;
+ info->used_entries = 0;
+ info->total_entries = 0;
+
+ return unlock_cache(cache, SVN_NO_ERROR);
+}
+
static svn_cache__vtable_t memcache_vtable = {
memcache_get,
memcache_set,
memcache_iter,
memcache_is_cachable,
- memcache_get_partial
+ memcache_get_partial,
+ memcache_get_info
};
svn_error_t *
Modified: subversion/trunk/subversion/libsvn_subr/cache.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache.c?rev=1081114&r1=1081113&r2=1081114&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache.c Sun Mar 13 13:46:41 2011
@@ -152,3 +152,83 @@ svn_cache__get_partial(void **value,
return err;
}
+
+svn_error_t *
+svn_cache__get_info(svn_cache__t *cache,
+ svn_cache__info_t *info,
+ svn_boolean_t reset,
+ apr_pool_t *pool)
+{
+ /* write general statistics */
+
+ info->gets = cache->reads;
+ info->hits = cache->hits;
+ info->sets = cache->writes;
+ info->failures = cache->failures;
+
+ /* Call the cache implementation for filling the blanks.
+ * It might also replace some of the general stats but
+ * this is currently not done.
+ */
+ SVN_ERR((cache->vtable->get_info)(cache->cache_internal,
+ info,
+ reset,
+ pool));
+
+ /* reset statistics */
+
+ if (reset)
+ {
+ cache->reads = 0;
+ cache->hits = 0;
+ cache->writes = 0;
+ cache->failures = 0;
+ }
+
+ return SVN_NO_ERROR;
+}
+
+svn_string_t *
+svn_cache__format_info(const svn_cache__info_t *info,
+ apr_pool_t *pool)
+{
+ enum { _1MB = 1024 * 1024 };
+
+ apr_uint64_t misses = info->gets - info->hits;
+ float hit_rate = (100.0 * info->hits)
+ / (info->gets ? info->gets : 1);
+ float write_rate = (100.0 * info->sets)
+ / (misses ? misses : 1);
+ float data_usage_rate = (100.0 * info->used_size)
+ / (info->data_size ? info->data_size : 1);
+ float data_entry_rate = (100.0 * info->used_entries)
+ / (info->total_entries ? info->total_entries : 1);
+
+ return svn_string_createf(pool,
+
+ "prefix : %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"
+ "failures: %" APR_UINT64_T_FMT "\n"
+ "used : %" APR_SIZE_T_FMT " MB (%5.2f%%)"
+ " of %" APR_SIZE_T_FMT " MB data cache"
+ " / %" APR_SIZE_T_FMT " MB total cache memory\n"
+ " %" APR_SIZE_T_FMT " entries (%5.2f%%)"
+ " of %" APR_SIZE_T_FMT " total\n",
+
+ info->id,
+
+ info->gets,
+ info->hits, hit_rate,
+ info->sets, write_rate,
+ info->failures,
+
+ info->used_size / _1MB, data_usage_rate,
+ info->data_size / _1MB,
+ info->total_size / _1MB,
+
+ info->used_entries, data_entry_rate,
+ info->total_entries);
+}
Modified: subversion/trunk/subversion/libsvn_subr/cache.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache.h?rev=1081114&r1=1081113&r2=1081114&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache.h (original)
+++ subversion/trunk/subversion/libsvn_subr/cache.h Sun Mar 13 13:46:41 2011
@@ -58,6 +58,11 @@ typedef struct svn_cache__vtable_t {
svn_cache__partial_getter_func_t func,
void *baton,
apr_pool_t *pool);
+
+ svn_error_t *(*get_info)(void *cache_implementation,
+ svn_cache__info_t *info,
+ svn_boolean_t reset,
+ apr_pool_t *pool);
} svn_cache__vtable_t;
struct svn_cache__t {