non security modules update
This commit is contained in:
@@ -98,6 +98,33 @@ Statistics:
|
||||
You can view the recorded performance statistics (summary and details) at
|
||||
/admin/reports/performance-logging
|
||||
|
||||
Custom detailed logging implementation
|
||||
--------------------------------------
|
||||
As mentioned before, detailed logging is NOT recommended on production environ-
|
||||
ments. If you, for whatever reason, DO wish detailed logging on production, you
|
||||
should create a custom detailed logging mechanism that will NOT interfere with
|
||||
your live site. You can do this by creating your own versions of the following
|
||||
functions:
|
||||
|
||||
- performance_log_details($params)
|
||||
=> function that is called to store the performance data
|
||||
- performance_view_details()
|
||||
=> function that is called to view the stored detail log. This function is
|
||||
called from hook_menu() and should return content that Drupal can render
|
||||
as a page.
|
||||
- performance_clear_details()
|
||||
=> function that is called to delete the entire detail log
|
||||
|
||||
Have a look at includes/performance.details.inc for more details about these
|
||||
functions.
|
||||
|
||||
When you have created those functions, add the location of the file containing
|
||||
your custom implementation to settings.php like so:
|
||||
|
||||
$conf['performance_detail_logging'] = './sites/all/path/to/your/file';
|
||||
|
||||
NOTE: there is NO drush support for your custom detail logging implementation!
|
||||
|
||||
Drush support
|
||||
-------------
|
||||
Drush support has been integrated as well. You can check the summary and detail
|
||||
|
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Performance module detail logging related functions. Can be overridden by
|
||||
* adding $conf['performance_detail_logging'] = 'path/to/your/file' in
|
||||
* settings.php.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper function to store detailed data in database.
|
||||
* @param $params
|
||||
* an array containing the following keys: mem, timer, query_count, query_timer
|
||||
* anon, path, language, data.
|
||||
* @return void
|
||||
*/
|
||||
function performance_log_details($params) {
|
||||
$fields = array(
|
||||
'timestamp' => REQUEST_TIME,
|
||||
'bytes' => $params['mem'],
|
||||
'ms' => (int)$params['timer'],
|
||||
'query_count' => $params['query_count'],
|
||||
'query_timer' => (int)$params['query_timer'],
|
||||
'anon' => $params['anon'],
|
||||
'path' => $params['path'],
|
||||
'language' => $params['language'],
|
||||
'data' => $params['data'],
|
||||
);
|
||||
|
||||
try {
|
||||
db_insert('performance_detail')
|
||||
->fields($fields)
|
||||
->execute();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
watchdog_exception('performance', $e, NULL, array(), WATCHDOG_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detail page callback.
|
||||
* @return array
|
||||
* Drupal render array.
|
||||
*/
|
||||
function performance_view_details() {
|
||||
drupal_set_title(t('Performance logs: Details'));
|
||||
|
||||
$header = array(
|
||||
array('data' => t('#'), 'field' => 'pid', 'sort' => 'desc'),
|
||||
array('data' => t('Path'), 'field' => 'path'),
|
||||
array('data' => t('Date'), 'field' => 'timestamp'),
|
||||
array('data' => t('Memory (MB)'), 'field' => 'bytes'),
|
||||
array('data' => t('ms (Total)'), 'field' => 'ms'),
|
||||
array('data' => t('Language'), 'field' => 'language'),
|
||||
array('data' => t('Anonymous?'), 'field' => 'anon'),
|
||||
);
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$header[] = array('data' => t('# Queries'), 'field' => 'query_count');
|
||||
$header[] = array('data' => t('Query ms'), 'field' => 'query_timer');
|
||||
}
|
||||
|
||||
$pager_height = 50;
|
||||
$result = db_select('performance_detail', 'p')
|
||||
->fields('p')
|
||||
->extend('PagerDefault')
|
||||
->limit($pager_height)
|
||||
->extend('TableSort')
|
||||
->orderByHeader($header)
|
||||
->execute();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($result as $data) {
|
||||
$row_data = array();
|
||||
$row_data[] = $data->pid;
|
||||
$row_data[] = l($data->path, $data->path);
|
||||
$row_data[] = format_date($data->timestamp, 'small');
|
||||
$row_data[] = number_format($data->bytes / 1024 / 1024, 2);
|
||||
$row_data[] = $data->ms;
|
||||
$row_data[] = $data->language;
|
||||
$row_data[] = ($data->anon) ? t('Yes') : t('No');
|
||||
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$row_data[] = $data->query_count;
|
||||
$row_data[] = $data->query_timer;
|
||||
}
|
||||
|
||||
$rows[] = array('data' => $row_data);
|
||||
}
|
||||
|
||||
if (empty($rows) && !variable_get('performance_detail', 0)) {
|
||||
return array(
|
||||
'content' => array(
|
||||
'#markup' => t('Detail performance log is not enabled. Go to the !link to enable it.', array('!link' => l(t('settings page'), PERFORMANCE_SETTINGS, array('query' => drupal_get_destination()))))
|
||||
),
|
||||
);
|
||||
}
|
||||
elseif (!variable_get('performance_detail', 0)) {
|
||||
drupal_set_message(t('Detail performance log is not enabled! Showing stored logs.'), 'warning');
|
||||
}
|
||||
|
||||
// Return a renderable array.
|
||||
return array(
|
||||
'query_data_detail' => array(
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#sticky' => TRUE,
|
||||
'#empty' => t('No log messages available.'),
|
||||
),
|
||||
'clear' => array(
|
||||
'#markup' => l(t('Clear logs'), 'admin/reports/performance-logging/clear/details'),
|
||||
),
|
||||
'pager' => array(
|
||||
'#theme' => 'pager',
|
||||
'#quantity' => $pager_height,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to clear the detail logs.
|
||||
* @return void
|
||||
*/
|
||||
function performance_clear_details() {
|
||||
db_truncate('performance_detail')->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to prune detail log on cron.
|
||||
* @return void
|
||||
*/
|
||||
function performance_prune_details() {
|
||||
db_delete('performance_detail')
|
||||
->condition('timestamp', REQUEST_TIME - (24 * 60 * 60), '<=')
|
||||
->execute();
|
||||
}
|
@@ -6,9 +6,9 @@ configure = admin/config/development/performance-logging
|
||||
tags[] = developer
|
||||
tags[] = monitoring
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-01-12
|
||||
version = "7.x-2.0-beta1"
|
||||
; Information added by packaging script on 2013-11-09
|
||||
version = "7.x-2.0"
|
||||
core = "7.x"
|
||||
project = "performance"
|
||||
datestamp = "1358019516"
|
||||
datestamp = "1384025307"
|
||||
|
||||
|
@@ -23,6 +23,8 @@ define('PERFORMANCE_CACHE', 'cache_default_class');
|
||||
|
||||
define('PERFORMANCE_SETTINGS', 'admin/config/development/performance-logging');
|
||||
|
||||
include_once variable_get('performance_detail_logging', 'includes/performance.details.inc');
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
@@ -101,9 +103,9 @@ function performance_cron() {
|
||||
performance_traverse_cache('performance_cron_prune');
|
||||
|
||||
// Remove performance_detail rows on a daily basis.
|
||||
db_delete('performance_detail')
|
||||
->condition('timestamp', REQUEST_TIME - (24 * 60 * 60), '<=')
|
||||
->execute();
|
||||
if (variable_get('performance_detail', 0)) {
|
||||
performance_prune_details();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,7 +347,7 @@ function performance_log_summary($params) {
|
||||
}
|
||||
|
||||
// Keep records for 1 day.
|
||||
$expire = $result['last_access'] + (24 * 60 * 60);
|
||||
$expire = $result['data']['last_access'] + (24 * 60 * 60);
|
||||
cache_set($key, $result['data'], PERFORMANCE_BIN, $expire);
|
||||
}
|
||||
|
||||
@@ -481,32 +483,6 @@ function performance_get_summary($cache, $timestamp) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to store detailed data in database.
|
||||
*/
|
||||
function performance_log_details($params = array()) {
|
||||
$fields = array(
|
||||
'timestamp' => REQUEST_TIME,
|
||||
'bytes' => $params['mem'],
|
||||
'ms' => (int)$params['timer'],
|
||||
'query_count' => $params['query_count'],
|
||||
'query_timer' => (int)$params['query_timer'],
|
||||
'anon' => $params['anon'],
|
||||
'path' => $params['path'],
|
||||
'language' => $params['language'],
|
||||
'data' => $params['data'],
|
||||
);
|
||||
|
||||
try {
|
||||
db_insert('performance_detail')
|
||||
->fields($fields)
|
||||
->execute();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
watchdog_exception('performance', $e, NULL, array(), WATCHDOG_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary page callback.
|
||||
*/
|
||||
@@ -688,85 +664,6 @@ function performance_sort_summary($data, $direction, $field) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detail page callback.
|
||||
*/
|
||||
function performance_view_details() {
|
||||
drupal_set_title(t('Performance logs: Details'));
|
||||
|
||||
$header = array(
|
||||
array('data' => t('#'), 'field' => 'pid', 'sort' => 'desc'),
|
||||
array('data' => t('Path'), 'field' => 'path'),
|
||||
array('data' => t('Date'), 'field' => 'timestamp'),
|
||||
array('data' => t('Memory (MB)'), 'field' => 'bytes'),
|
||||
array('data' => t('ms (Total)'), 'field' => 'ms'),
|
||||
array('data' => t('Language'), 'field' => 'language'),
|
||||
array('data' => t('Anonymous?'), 'field' => 'anon'),
|
||||
);
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$header[] = array('data' => t('# Queries'), 'field' => 'query_count');
|
||||
$header[] = array('data' => t('Query ms'), 'field' => 'query_timer');
|
||||
}
|
||||
|
||||
$pager_height = 50;
|
||||
$result = db_select('performance_detail', 'p')
|
||||
->fields('p')
|
||||
->extend('PagerDefault')
|
||||
->limit($pager_height)
|
||||
->extend('TableSort')
|
||||
->orderByHeader($header)
|
||||
->execute();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($result as $data) {
|
||||
$row_data = array();
|
||||
$row_data[] = $data->pid;
|
||||
$row_data[] = l($data->path, $data->path);
|
||||
$row_data[] = format_date($data->timestamp, 'small');
|
||||
$row_data[] = number_format($data->bytes / 1024 / 1024, 2);
|
||||
$row_data[] = $data->ms;
|
||||
$row_data[] = $data->language;
|
||||
$row_data[] = ($data->anon) ? t('Yes') : t('No');
|
||||
|
||||
if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
|
||||
$row_data[] = $data->query_count;
|
||||
$row_data[] = $data->query_timer;
|
||||
}
|
||||
|
||||
$rows[] = array('data' => $row_data);
|
||||
}
|
||||
|
||||
if (empty($rows) && !variable_get('performance_detail', 0)) {
|
||||
return array(
|
||||
'content' => array(
|
||||
'#markup' => t('Detail performance log is not enabled. Go to the !link to enable it.', array('!link' => l(t('settings page'), PERFORMANCE_SETTINGS, array('query' => drupal_get_destination()))))
|
||||
),
|
||||
);
|
||||
}
|
||||
elseif (!variable_get('performance_detail', 0)) {
|
||||
drupal_set_message(t('Detail performance log is not enabled! Showing stored logs.'), 'warning');
|
||||
}
|
||||
|
||||
// Return a renderable array.
|
||||
return array(
|
||||
'query_data_detail' => array(
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#sticky' => TRUE,
|
||||
'#empty' => t('No log messages available.'),
|
||||
),
|
||||
'clear' => array(
|
||||
'#markup' => l(t('Clear logs'), 'admin/reports/performance-logging/clear/details'),
|
||||
),
|
||||
'pager' => array(
|
||||
'#theme' => 'pager',
|
||||
'#quantity' => $pager_height,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear logs form.
|
||||
*/
|
||||
@@ -812,7 +709,7 @@ function performance_clear_form_submit($form, &$form_state) {
|
||||
cache_clear_all('*', PERFORMANCE_BIN, TRUE);
|
||||
break;
|
||||
case 'details':
|
||||
db_truncate('performance_detail')->execute();
|
||||
performance_clear_details();
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user