You are here

class XHProfRunsFile in XHProf 7

Same name in this branch
  1. 7 XHProfRunsFile.inc \XHProfRunsFile
  2. 7 XHProfLib/XHProfRuns.php \XHProfRunsFile
Same name and namespace in other branches
  1. 6 XHProfRunsFile.inc \XHProfRunsFile
  2. 6 XHProfLib/XHProfRuns.php \XHProfRunsFile

Hierarchy

Expanded class hierarchy of XHProfRunsFile

7 string references to 'XHProfRunsFile'
xhprof_admin_settings in ./xhprof.admin.inc
Administrative settings form for XHProf module.
xhprof_display_run in ./xhprof.module
Display XHProf run report.
xhprof_get_classes in ./xhprof.module
List all available XHProf storage backends.
xhprof_include in ./xhprof.module
Helper. Make sure expensive module_load_include() does not run needlessly.
xhprof_run_list in ./xhprof.module
Display list of saved XHProf runs.

... See full list

File

XHProfLib/XHProfRuns.php, line 3

View source
class XHProfRunsFile implements XHProfRunsInterface {
  private $dir;
  private $suffix;
  public function __construct() {
    $this->dir = ini_get('xhprof.output_dir') && is_dir(ini_get('xhprof.output_dir')) ? ini_get('xhprof.output_dir') : file_directory_temp();
    $this->suffix = 'xhprof';
  }
  private function gen_run_id($type) {
    return uniqid();
  }
  private function fileName($run_id, $namespace) {
    $file = implode('.', array(
      $run_id,
      $namespace,
      $this->suffix,
    ));
    if (!empty($this->dir)) {
      $file = $this->dir . "/" . $file;
    }
    return $file;
  }
  public function getRun($run_id, $namespace) {
    $file_name = $this
      ->fileName($run_id, $namespace);
    if (!file_exists($file_name)) {
      throw new Exception("Could not find file {$file_name}");
    }
    $contents = file_get_contents($file_name);
    return unserialize($contents);
  }
  public function getRuns($namespace = NULL) {
    xdebug_break();
    $files = $this
      ->scanXHProfDir($this->dir, $namespace);
    $files = array_map(function ($f) {
      $f['date'] = strtotime($f['date']);
      return $f;
    }, $files);
    return $files;
  }
  public function scanXHProfDir($dir, $namespace = NULL) {
    if (is_dir($dir)) {
      $runs = array();
      foreach (glob("{$this->dir}/*.{$this->suffix}") as $file) {
        list($run, $source) = explode('.', basename($file));
        $runs[] = array(
          'run_id' => $run,
          'namespace' => $source,
          'basename' => htmlentities(basename($file)),
          'date' => date("Y-m-d H:i:s", filemtime($file)),
        );
      }
    }
    return array_reverse($runs);
  }

}

Members