You are here

class MongodbXHProfRuns in XHProf 6

Same name and namespace in other branches
  1. 8 modules/xhprof_mongodb/MongodbXHProfRuns.inc \MongodbXHProfRuns
  2. 7 modules/xhprof_mongodb/MongodbXHProfRuns.inc \MongodbXHProfRuns

Defines a MongoDB storage backend for XHProf.

Hierarchy

Expanded class hierarchy of MongodbXHProfRuns

1 string reference to 'MongodbXHProfRuns'
xhprof_mongodb_xhprof_classes_alter in modules/xhprof_mongodb/xhprof_mongodb.module
Implementation of hook_xhprof_classes_alter().

File

modules/xhprof_mongodb/MongodbXHProfRuns.inc, line 11
Definition of MongodbXHProfRuns.

View source
class MongodbXHProfRuns implements XHProfRunsInterface {
  private $dir = '';
  private function gen_run_id($type) {
    return uniqid();
  }
  private function file_name($run_id, $type) {
    $file = "{$run_id}.{$type}";
    if (!empty($this->dir)) {
      $file = $this->dir . "/" . $file;
    }
    return $file;
  }
  public function __construct($dir = NULL) {
  }

  /**
   * This function gets runs based on passed parameters, column data as key, value as the value. Values
   * are escaped automatically. You may also pass limit, order by, group by, or "where" to add those values,
   * all of which are used as is, no escaping.
   *
   * @param array $stats Criteria by which to select columns
   * @return resource
   */
  public function getRuns($stats, $limit = 50, $skip = 0) {
    $collection = mongodb_collection('xhprof');
    $sort = isset($_GET['order']) ? $_GET['order'] : 'date';
    $sort_direction_str = isset($_GET['sort']) ? $_GET['sort'] : 'desc';
    $sort_direction = array(
      'asc' => 1,
      'desc' => -1,
    );
    $cursor = $collection
      ->find(array())
      ->limit($limit)
      ->skip($skip)
      ->sort(array(
      strtolower($sort) => $sort_direction[$sort_direction_str],
    ));
    $runs = array();
    foreach ($cursor as $id => $run) {
      $run['run_id'] = $id;
      $runs[] = $run;
    }
    return $runs;
  }
  public function getCount() {
    $collection = mongodb_collection('xhprof');
    $count = $collection
      ->count();
    return $count;
  }
  public function get_run($run_id, $type, &$run_desc) {
    $collection = mongodb_collection('xhprof');
    $run_desc = "XHProf Run (Namespace={$type})";
    $run = $collection
      ->findOne(array(
      '_id' => (string) $run_id,
    ));
    return $run['run_data'];
  }
  public function save_run($xhprof_data, $type, $run_id = NULL) {
    if ($run_id === NULL) {
      $run_id = $this
        ->gen_run_id($type);
    }
    $mongo_id = $run_id;
    module_load_include('module', 'mongodb');
    $collection = mongodb_collection('xhprof');
    $entry = array();
    $entry['_id'] = (string) $mongo_id;
    $entry['run_data'] = $xhprof_data;
    $entry['get'] = serialize($_GET);
    $entry['cookie'] = serialize($_COOKIE);
    $entry['date'] = $_SERVER['REQUEST_TIME'];
    $entry['pmu'] = isset($xhprof_data['main()']['pmu']) ? $xhprof_data['main()']['pmu'] : '';
    $entry['wt'] = isset($xhprof_data['main()']['wt']) ? $xhprof_data['main()']['wt'] : '';
    $entry['cpu'] = isset($xhprof_data['main()']['cpu']) ? $xhprof_data['main()']['cpu'] : '';
    $entry['path'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
    $entry['servername'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
    $collection
      ->save($entry);
    return $run_id;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MongodbXHProfRuns::$dir private property
MongodbXHProfRuns::file_name private function
MongodbXHProfRuns::gen_run_id private function
MongodbXHProfRuns::getCount public function
MongodbXHProfRuns::getRuns public function This function gets runs based on passed parameters, column data as key, value as the value. Values are escaped automatically. You may also pass limit, order by, group by, or "where" to add those values, all of which are used as is, no escaping.
MongodbXHProfRuns::get_run public function
MongodbXHProfRuns::save_run public function
MongodbXHProfRuns::__construct public function