Commit 6b64d9a1 authored by robertDouglass's avatar robertDouglass

#911226 by robertDouglass: Added Improved statistics reporting.

parent 1cde38f2
......@@ -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);
}
......
......@@ -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);
......
......@@ -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>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment