You are here

function memcache_admin_shutdown in Memcache API and Integration 6

Same name and namespace in other branches
  1. 5 memcache_admin/memcache_admin.module \memcache_admin_shutdown()
  2. 7 memcache_admin/memcache_admin.module \memcache_admin_shutdown()

See memcache_admin_init() which registers this function as a shutdown function. Displays memcache stats in the footer.

1 string reference to 'memcache_admin_shutdown'
memcache_admin_init in memcache_admin/memcache_admin.module
For the collection of memcache stats. This small .js file makes sure that the HTML displaying the stats is inside of the <body> part of the HTML document.

File

memcache_admin/memcache_admin.module, line 548

Code

function memcache_admin_shutdown() {
  global $_dmemcache_stats;

  // Don't call theme() during shutdown if the registry has been rebuilt (such
  // as when enabling/disabling modules on admin/build/modules) as things break.
  // Instead, simply exit without displaying admin statistics for this page
  // load.  See http://drupal.org/node/616282 for discussion.
  if (!function_exists('theme_get_registry') || !theme_get_registry()) {
    return;
  }

  // Try not to break non-HTML pages.
  if (function_exists('drupal_get_headers')) {
    $headers = drupal_get_headers();
    if ($headers) {
      $formats = array(
        'xml',
        'javascript',
        'json',
        'plain',
        'image',
        'application',
        'csv',
        'x-comma-separated-values',
      );
      foreach ($formats as $format) {
        if (strstr($headers, $format)) {
          return;
        }
      }
    }
  }
  if (variable_get('show_memcache_statistics', FALSE) && function_exists('user_access') && user_access('access memcache statistics')) {
    $output = '';
    if (!empty($_dmemcache_stats['ops'])) {
      foreach ($_dmemcache_stats['ops'] as $row => $stats) {
        $_dmemcache_stats['ops'][$row][0] = check_plain($stats[0]);
        $_dmemcache_stats['ops'][$row][1] = number_format($stats[1], 2);
        $hits = number_format(_memcache_admin_stats_percent($stats[2], $stats[3]), 1);
        $misses = number_format(_memcache_admin_stats_percent($stats[3], $stats[2]), 1);
        $_dmemcache_stats['ops'][$row][2] = number_format($stats[2]) . " ({$hits}%)";
        $_dmemcache_stats['ops'][$row][3] = number_format($stats[3]) . " ({$misses}%)";
      }
      $variables = array(
        'header' => array(
          t('operation'),
          t('total ms'),
          t('total hits'),
          t('total misses'),
        ),
        'rows' => $_dmemcache_stats['ops'],
      );
      $output .= theme('table', $variables['header'], $variables['rows']);
    }
    if (!empty($_dmemcache_stats['all'])) {
      foreach ($_dmemcache_stats['all'] as $row => $stats) {
        $_dmemcache_stats['all'][$row][1] = check_plain($stats[1]);
        $_dmemcache_stats['all'][$row][2] = check_plain($stats[2]);
        $_dmemcache_stats['all'][$row][3] = check_plain($stats[3]);
      }
      $variables = array(
        'header' => array(
          t('ms'),
          t('operation'),
          t('bin'),
          t('key'),
          t('status'),
        ),
        'rows' => $_dmemcache_stats['all'],
      );
      $output .= theme('table', $variables['header'], $variables['rows']);
    }
    if (!empty($output)) {

      // 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>';
    }
  }
}