You are here

function dba_mysql_report_driver in Database Administration 7

Return MySQL specific stuff. Prepares MyISAM and InnoDB stats.

File

database/mysql.report.inc, line 105
Provides database driver specific report functions.

Code

function dba_mysql_report_driver($data) {
  $return = new stdClass();

  // MyISAM
  $return->myisam = new stdClass();
  $return->myisam->questions = $data->status->questions;
  $return->myisam->keyReadRatio = $data->status->key_read_requests ? (1.0 - $data->status->key_reads / $data->status->key_read_requests) * 100.0 : 0;
  $return->myisam->keyWriteRatio = $data->status->key_write_requests ? (1.0 - $data->status->key_writes / $data->status->key_write_requests) * 100.0 : 0;
  $return->myisam->keyCacheBlockSize = isset($data->variables->key_cache_block_size) ? $data->variables->key_cache_block_size : 1024;
  $return->myisam->keyBufferUsed = $data->status->key_blocks_used * $return->myisam->keyCacheBlockSize;
  $return->myisam->keyBufferUsage = isset($data->status->key_blocks_unused) ? $data->variables->key_buffer_size - $data->status->key_blocks_unused * $return->myisam->keyCacheBlockSize : -1;

  // Data Manipulation Statements: http://dev.mysql.com/doc/refman/5.0/en/data-manipulation.html
  $return->myisam->DMS = array(
    'SELECT' => $data->status->com_select,
    'INSERT' => $data->status->com_insert + $data->status->com_insert_select,
    'REPLACE' => $data->status->com_replace + $data->status->com_replace_select,
    'UPDATE' => $data->status->com_update + (isset($data->status->com_update_multi) ? $data->status->com_update_multi : 0),
    'DELETE' => $data->status->com_delete + (isset($data->status->com_delete_multi) ? $data->status->com_delete_multi : 0),
  );
  $return->myisam->DMS['DMS'] = array_sum($return->myisam->DMS);
  arsort($return->myisam->DMS);
  $return->myisam->slowQueryTime = $data->variables->long_query_time;

  // InnoDB
  if ($data->version
    ->compare_version(new dba_report_version(5, 0, 2), '>=')) {
    $return->innodb = new stdClass();
    $return->innodb->bufferPoolUsed = ($data->status->innodb_buffer_pool_pages_total - $data->status->innodb_buffer_pool_pages_free) * $data->status->innodb_page_size;
    $return->innodb->bufferPoolTotal = $data->status->innodb_buffer_pool_pages_total * $data->status->innodb_page_size;
    $return->innodb->bufferPoolReadRatio = $data->status->innodb_buffer_pool_read_requests != 0 ? 1.0 - $data->status->innodb_buffer_pool_reads / $data->status->innodb_buffer_pool_read_requests : 0;
  }
  return $return;
}