Commit bb41ffc9 authored by Jeremy's avatar Jeremy

Issue #2365839 by Jeremy: Provide introspection tool

parent f1e36aaf
......@@ -431,6 +431,42 @@ $conf['memcache_options'] = array(
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
);
## DEBUG LOGGING ##
You can optionally enable debug logging by adding the following to your
settings.php:
$conf['memcache_debug_log'] = '/path/to/file.log';
By default, only the following memcache actions are logged: 'set', 'add',
'delete', and 'flush'. If you'd like to also log 'get' actions, enble verbose
logging:
$conf['memcache_debug_verbose'] = TRUE;
This file needs to be writable by the web server (and/or by drush) or you will
see lots of watchdog errors. You are responsible for ensuring that the debug log
doesn't get too large. By default, enabling debug logging will write logs
looking something like:
1484719570|add|semaphore|semaphore-memcache_system_list%3Acache_bootstrap|1
1484719570|set|cache_bootstrap|cache_bootstrap-system_list|1
1484719570|delete|semaphore|semaphore-memcache_system_list%3Acache_bootstrap|1
The default log format is pipe delineated, containing the following fields:
timestamp|action|bin|cid|return code
You can specify a custom log format by setting the memcache_debug_log_format
variable. Supported variables that will be replaced in your format are:
'!timestamp', '!action', '!bin', '!cid', and '!rc'.
For example, the default log format (note that it includes a new line at the
end) is:
$conf['memcache_debug_log_format'] = "!timestamp|!action|!bin|!cid|!rc\n";
You can change the timestamp format by specifying a PHP date() format string in
the memcache_debug_time_format variable. PHP date() formats are documented at
http://php.net/manual/en/function.date.php. By default timestamps are written as
a unix timestamp. For example:
$conf['memcache_debug_time_format'] = 'U';
## TROUBLESHOOTING ##
PROBLEM:
......
......@@ -80,6 +80,10 @@ function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) {
dmemcache_stats_write('set', $bin, array($full_key => $rc));
}
if (variable_get('memcache_debug_log', FALSE)) {
_dmemcache_write_debug('set', $bin, $full_key, $rc);
}
return $rc;
}
......@@ -246,6 +250,10 @@ function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag
dmemcache_stats_write('add', $bin, array($full_key => $rc));
}
if (variable_get('memcache_debug_log', FALSE)) {
_dmemcache_write_debug('add', $bin, $full_key, $rc);
}
return $rc;
}
......@@ -287,6 +295,10 @@ function dmemcache_get($key, $bin = 'cache', $mc = NULL) {
dmemcache_stats_write('get', $bin, array($full_key => (bool) $result));
}
if (variable_get('memcache_debug_log', FALSE) && variable_get('memcache_debug_verbose', FALSE)) {
_dmemcache_write_debug('get', $bin, $full_key, (bool) $result);
}
return $result;
}
......@@ -496,6 +508,10 @@ function dmemcache_delete($key, $bin = 'cache', $mc = NULL) {
dmemcache_stats_write('delete', $bin, array($full_key => $rc));
}
if (variable_get('memcache_debug_log', FALSE)) {
_dmemcache_write_debug('delete', $bin, $full_key, $rc);
}
return $rc;
}
......@@ -525,6 +541,10 @@ function dmemcache_flush($bin = 'cache', $mc = NULL) {
dmemcache_stats_write('flush', $bin, array('' => $rc));
}
if (variable_get('memcache_debug_log', FALSE)) {
_dmemcache_write_debug('flush', $bin, $full_key, $rc);
}
return $rc;
}
......@@ -1133,3 +1153,23 @@ function dmemcache_stats_write($action, $bin, $keys) {
}
// Reset the dmemcache timer for timing the next memcache operation.
}
/**
* Write to a debug log when enabled.
*
* @param string $action
* The action being performed (get, set, etc...).
* @param string $bin
* The memcache bin the action is being performed in.
* @param array $rc
* The return code of the action performed.
*/
function _dmemcache_write_debug($action, $bin, $key, $rc) {
$memcache_debug_log = variable_get('memcache_debug_log', FALSE);
$debug_log = strtr(variable_get('memcache_debug_log_format', "!timestamp|!action|!bin|!cid|!rc\n"), array('!timestamp' => date(variable_get('memcache_debug_time_format', 'U')), '!action' => $action, '!bin' => $bin, '!cid' => $key, '!rc' => (int) $rc));
if (file_put_contents($memcache_debug_log, $debug_log, FILE_APPEND) === FALSE) {
// This can lead to a lot of watchdog entries...
register_shutdown_function('watchdog', 'memcache', 'Unable to write to debug log at !debug_file: !debug_log.', array('!debug_file' => $memcache_debug_file, '!debug_log' => $debug_log), WATCHDOG_ERROR);
}
}
......@@ -259,6 +259,15 @@ function memcache_admin_stats($bin = 'default') {
if (!class_exists('MemCacheDrupal', FALSE)) {
return t('There is a problem with your memcache configuration. Please review !readme for help resolving the following issue: %error.', array('!readme' => l('README.txt', 'http://cgit.drupalcode.org/memcache/tree/README.txt?id=refs/heads;id2=7.x-1.x'), '%error' => t('cache_backends not properly configured in settings.php, failed to load required file memcache.inc')));
}
if ($memcache_debug_log = variable_get('memcache_debug_log', FALSE)) {
if (variable_get('memcache_debug_verbose', FALSE)) {
$verbose = t('verbose');
}
else {
$verbose = '';
}
drupal_set_message(t('You are writing !verbose debug logs to !debug_log.', array('!verbose' => $verbose, '!debug_log' => $memcache_debug_log)), 'warning');
}
$bin = memcache_admin_bin_mapping($bin);
$output = '';
$server = array();
......
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