You are here

function drush_performance_details in Performance Logging and Monitoring 7

Same name and namespace in other branches
  1. 6.2 performance.drush.inc \drush_performance_details()
  2. 6 performance.drush.inc \drush_performance_details()
  3. 7.2 performance.drush.inc \drush_performance_details()
1 string reference to 'drush_performance_details'
performance_drush_command in ./performance.drush.inc
Implements hook_drush_command().

File

./performance.drush.inc, line 192
Drush integration for the Performance module.

Code

function drush_performance_details() {
  if (!variable_get('performance_detail', 0)) {
    return drush_set_error(dt('Detail performance log is not enabled! Go to the settings page to enable it.'));
  }
  $header = array(
    dt('#'),
    dt('Date'),
    dt('Path'),
    dt('Memory (MB)'),
    dt('ms (Total)'),
    dt('Anonymous?'),
  );
  if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
    $header[] = dt('# Queries');
    $header[] = dt('Query ms');
  }
  $rows[] = $header;

  // Collect arguments.
  $args = func_get_args();
  $orderby = 'timestamp';
  $columns = array(
    'pid',
    'timestamp',
    'bytes',
    'ms',
    'anon',
    'path',
  );
  if (variable_get(PERFORMANCE_QUERY_VAR, 0)) {
    $columns[] = 'query_count';
    $columns[] = 'query_timer';
  }
  $arguments = drush_performance_parse_args($args, $orderby, $columns);

  // Error thrown, abort.
  if (!is_array($arguments)) {
    return $arguments;
  }
  $data_list = drush_performance_db_get_data('performance_detail', $arguments);
  foreach ($data_list as $data) {

    // Cast to object because of the DB API now returning row objects by default.
    $data = is_array($data) ? (object) $data : $data;
    $row_data = array();
    $row_data[] = $data->pid;
    $row_data[] = format_date($data->timestamp, 'small');
    $row_data[] = check_plain($data->path);
    $row_data[] = number_format($data->bytes / 1024 / 1024, 2);
    $row_data[] = $data->ms;
    $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[] = $row_data;
  }
  drush_print("\33[1m" . dt('Performance log details: !limit entries ordered by !column, !direction', array(
    '!limit' => $arguments['limit'],
    '!column' => $arguments['orderby'],
    '!direction' => $arguments['direction'],
  )) . "\33[0m", 1);
  drush_print_table($rows, TRUE);
}