summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Douglass2010-09-28 16:57:46 (GMT)
committerRobert Douglass2010-09-28 16:57:46 (GMT)
commit6b64d9a120ffb73134ec1dc024695fb6e9fb7ec1 (patch)
treefc6706d18543a3b5090252f941fe339b88ccc0f7
parent1cde38f2e372ef5a6be680fd441bc2c28e8f6734 (diff)
#911226 by robertDouglass: Added Improved statistics reporting.
-rw-r--r--dmemcache.inc49
-rw-r--r--memcache-lock.inc2
-rw-r--r--memcache_admin/memcache_admin.module12
3 files changed, 34 insertions, 29 deletions
diff --git a/dmemcache.inc b/dmemcache.inc
index cc32f38..5cc04e2 100644
--- a/dmemcache.inc
+++ b/dmemcache.inc
@@ -10,7 +10,7 @@
*/
global $_memcache_statistics;
-$_memcache_statistics = array('get' => array(), 'set' => array(), 'hit' => array());
+$_memcache_statistics = array();
/*
* A memcache API for Drupal.
@@ -35,10 +35,9 @@ $_memcache_statistics = array('get' => array(), 'set' => array(), 'hit' => array
*/
function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) {
global $_memcache_statistics;
- $_memcache_statistics['set'][] = $key;
- $_memcache_statistics['bins'][] = $bin;
+ $full_key = dmemcache_key($key, $bin);
+ $_memcache_statistics[] = array('set', $bin, $full_key, '');
if ($mc || ($mc = dmemcache_object($bin))) {
- $full_key = dmemcache_key($key, $bin);
if (class_exists('Memcached')) {
return $mc->set($full_key, $value, $exp);
}
@@ -72,10 +71,9 @@ function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) {
*/
function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag = FALSE) {
global $_memcache_statistics;
- $_memcache_statistics['add'][] = $key;
- $_memcache_statistics['bins'][] = $bin;
+ $full_key = dmemcache_key($key, $bin);
+ $_memcache_statistics[] = array('add', $bin, $full_key, '');
if ($mc || ($mc = dmemcache_object($bin))) {
- $full_key = dmemcache_key($key, $bin);
if (class_exists('Memcached')) {
return $mc->add($full_key, $value, $exp);
}
@@ -96,16 +94,18 @@ function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag
*/
function dmemcache_get($key, $bin = 'cache', $mc = NULL) {
global $_memcache_statistics;
- $_memcache_statistics['get'][] = $key;
- $_memcache_statistics['bins'][] = $bin;
+ $full_key = dmemcache_key($key, $bin);
+ $statistics = array('get', $bin, $full_key);
+ $success = '0';
if ($mc || ($mc = dmemcache_object($bin))) {
- $full_key = dmemcache_key($key, $bin);
$result = $mc->get($full_key);
if ($result) {
- $_memcache_statistics['hit'][] = $key;
- return $result;
+ $success = '1';
}
}
+ $statistics[] = $success;
+ $_memcache_statistics[] = $statistics;
+ return $result;
}
/**
@@ -115,19 +115,18 @@ function dmemcache_get($key, $bin = 'cache', $mc = NULL) {
* @param $bin The bin in which the item was stored.
*
* @return The item which was originally saved or FALSE
- *
- * TODO: Record statistics w/ multi-get
*/
function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
global $_memcache_statistics;
- $_memcache_statistics['get'] = array_merge($_memcache_statistics['get'], $keys);
- $_memcache_statistics['bins'][] = $bin;
+ $full_keys = array();
+ $statistics = array();
+ foreach ($keys as $key => $cid) {
+ $full_key = dmemcache_key($cid, $bin);
+ $statistics[$full_key] = array('getMulti', $bin, $full_key);
+ $full_keys[] = $full_key;
+ }
$results = array();
if ($mc || ($mc = dmemcache_object($bin))) {
- $full_keys = array();
- foreach ($keys as $key => $cid) {
- $full_keys[] = dmemcache_key($cid, $bin);
- }
if (class_exists('Memcached')) {
$results = $mc->getMulti($full_keys);
}
@@ -135,6 +134,10 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
$results = $mc->get($full_keys);
}
}
+ foreach ($statistics as $key => $values) {
+ $values[] = isset($results[$key]) ? '1': '0';
+ $_memcache_statistics[] = $values;
+ }
return $results;
}
@@ -147,8 +150,10 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
* @return Returns TRUE on success or FALSE on failure.
*/
function dmemcache_delete($key, $bin = 'cache', $mc = NULL) {
+ global $_memcache_statistics;
+ $full_key = dmemcache_key($key, $bin);
+ $_memcache_statistics[] = array('delete', $bin, $full_key, '');
if ($mc || ($mc = dmemcache_object($bin))) {
- $full_key = dmemcache_key($key, $bin);
return $mc->delete($full_key);
}
return FALSE;
@@ -165,6 +170,8 @@ function dmemcache_delete($key, $bin = 'cache', $mc = NULL) {
* @return Returns TRUE on success or FALSE on failure.
*/
function dmemcache_flush($bin = 'cache', $mc = NULL) {
+ global $_memcache_statistics;
+ $_memcache_statistics[] = array('flush', $bin, '', '');
if ($mc || ($mc = dmemcache_object($bin))) {
return memcache_flush($mc);
}
diff --git a/memcache-lock.inc b/memcache-lock.inc
index 5d25284..12944c5 100644
--- a/memcache-lock.inc
+++ b/memcache-lock.inc
@@ -6,6 +6,8 @@
* See includes/lock.inc for documenation
*/
+require_once dirname(__FILE__) . '/dmemcache.inc';
+
// Set up a define to make the code more readable, so we know we're setting a
// value for our lock and not simply passing dmemcache a flag.
define('LOCK_VALUE', TRUE);
diff --git a/memcache_admin/memcache_admin.module b/memcache_admin/memcache_admin.module
index 5e08bcb..31b337d 100644
--- a/memcache_admin/memcache_admin.module
+++ b/memcache_admin/memcache_admin.module
@@ -239,14 +239,10 @@ function memcache_admin_shutdown() {
}
if (variable_get('show_memcache_statistics', TRUE) && function_exists('user_access') && user_access('access memcache statistics')) {
- $stats = array();
-
- foreach ($_memcache_statistics as $stat => $value) {
- $items = array('items' => $value);
- $stats[] = "<strong>$stat:</strong> ". theme('item_list', array('items' => $value));
- }
- if (!empty($stats)) {
- $output = theme('item_list', array('items' => $stats));
+ if (!empty($_memcache_statistics)) {
+ $variables = array('header' => array(t('Operation'), t('Bin'), t('Key'), t('Hit')),
+ 'rows' => $_memcache_statistics);
+ $output = theme('table', $variables);
// this makes sure all of the HTML is within the <body> even though this <script> is outside it
print '<div id="memcache-devel"><h2>'. t('Memcache statistics'). '</h2>'. $output. '</div>';