コード例 #1
0
ファイル: Export.php プロジェクト: phperf/xhprof-analytics
 public function exportCombined()
 {
     $res = Database::getInstance()->query("select\n  child.name as child,\n  parent.name as parent,\n  sum(wall_time) as wt,\n  sum(count) as ct,\n  sum(cpu) as cpu,\n  round(avg(memory_usage)) as mu,\n  max(peak_memory_usage) as pmu\nfrom phperf_xhprof_related_stat\n  LEFT JOIN phperf_xhprof_symbol as child ON phperf_xhprof_related_stat.child_symbol_id = child.id\n  LEFT JOIN phperf_xhprof_symbol as parent ON phperf_xhprof_related_stat.parent_symbol_id = parent.id\nGROUP BY child_symbol_id, parent_symbol_id;")->fetchAll();
     $result = array();
     foreach ($res as $row) {
         $result[$row['parent'] . '==>' . $row['child']] = array('ct' => (int) $row['ct'], 'wt' => (int) $row['wt'], 'cpu' => (int) $row['cpu'], 'mu' => (int) $row['mu'], 'pmu' => (int) $row['pmu']);
     }
     $res = Database::getInstance()->query("select\n  symbol.name as symbol,\n  sum(wall_time) as wt,\n  sum(count) as ct,\n  sum(cpu) as cpu,\n  round(avg(memory_usage)) as mu,\n  max(peak_memory_usage) as pmu\nfrom phperf_xhprof_single_stat\n  LEFT JOIN phperf_xhprof_symbol as symbol ON phperf_xhprof_single_stat.symbol_id = symbol.id\nGROUP BY symbol_id;")->fetchAll();
     foreach ($res as $row) {
         $result[$row['symbol']] = array('ct' => (int) $row['ct'], 'wt' => (int) $row['wt'], 'cpu' => (int) $row['cpu'], 'mu' => (int) $row['mu'], 'pmu' => (int) $row['pmu']);
     }
     file_put_contents('export.serialized', serialize($result));
 }
コード例 #2
0
 public function listTop()
 {
     $database = Database::getInstance();
     $esc = SymbolStat::columns();
     $statement = $database->select(SymbolStat::table())->select("SUM(?) AS total_wt, SUM(?) AS total_ct, COUNT(DISTINCT ?) AS runs, ?, ?", $esc->wallTime, $esc->calls, $esc->runId, $esc->symbolId, Symbol::columns()->name)->leftJoin('? ON ? = ?', Symbol::table(), Symbol::columns()->id, $esc->symbolId)->groupBy(SymbolStat::columns()->symbolId)->order('total_wt DESC')->limit(50);
     $res = $statement->query();
     $table = new HTML();
     foreach ($res as $row) {
         $row['name'] = '<a href="?symbol=' . urlencode($row['name']) . '">' . $row['name'] . '</a>';
         unset($row['symbol_id']);
         $table->addRow($row);
     }
     $this->layout->pushMain($table)->render();
 }
コード例 #3
0
ファイル: DatabaseProxy.php プロジェクト: php-yaoi/php-yaoi
 public function __construct(Settings $dsn = null)
 {
     $this->dsn = $dsn ? $dsn : new Settings();
     if (empty($dsn->proxyClient)) {
         throw new Exception('proxyClient required in dsn', Exception::PROXY_REQUIRED);
     }
     $this->table = new Symbol($dsn->path ? $dsn->path : 'key_value_storage');
     $this->keyField = new Symbol('k');
     $this->valueField = new Symbol('v');
     $this->expireField = new Symbol('e');
     $this->db = Database::getInstance($this->dsn->proxyClient);
     $this->time = App::time($this->dsn->dateSource);
     // TODO use getInstance after Date_Source refactoring
 }
コード例 #4
0
 public function performAction()
 {
     $database = Database::getInstance();
     $settings = $database->getSettings();
     $tables = $settings->getTables();
     $log = new Log('colored-stdout');
     if ($this->wipe) {
         foreach ($tables as $table) {
             $table->migration()->setDryRun($this->dryRun)->setLog($log)->rollback();
         }
     }
     foreach ($tables as $table) {
         $table->migration()->setDryRun($this->dryRun)->setLog($log)->apply();
     }
 }
コード例 #5
0
 public function showSymbol()
 {
     if (!empty($_GET['run'])) {
         $run = new Run();
         $run->name = $_GET['run'];
         $run->findSaved()->id;
         $this->runName = $run->findSaved()->id;
     }
     /** @var Symbol $symbol */
     $symbol = Symbol::statement()->where('? = ?', Symbol::columns()->name, $this->symbol)->query()->fetchRow();
     if (null === $symbol) {
         return $this->error('Symbol ? not found', $this->symbol);
     }
     $stack = new Stack();
     $database = Database::getInstance();
     $inc = RelatedStat::columns();
     $mainSymbol = new Symbol();
     $mainSymbol->name = 'main()';
     $mainSymbol->findOrSave();
     $total_wt = $database->select(Run::table())->select("SUM(?) AS total_wt", Run::columns()->wallTime)->query()->fetchRow('total_wt');
     $stack->push(Raw::create('<h2>Total: ' . $total_wt . '</h2>'));
     $statement = $database->select(RelatedStat::table())->select("SUM(?)/1000000 AS total_wt, SUM(?) AS total_ct, COUNT(DISTINCT ?) AS runs, ? AS symbol_id, ?", $inc->wallTime, $inc->calls, $inc->runId, $inc->parentSymbolId, Symbol::columns()->name)->leftJoin('? ON ? = ?', Symbol::table(), Symbol::columns()->id, $inc->parentSymbolId)->where('? = ?', $inc->childSymbolId, $symbol->id)->groupBy($inc->parentSymbolId)->order('total_wt DESC')->limit(50);
     $res = $statement->query();
     $table = new HTML();
     $stack->push(Raw::create('<h2>Parents</h2>'));
     $stack->push($table);
     foreach ($res as $row) {
         $row['percent'] = round(100 * $row['total_wt'] / $total_wt, 2);
         $row['name'] = '<a href="?symbol=' . urlencode($row['name']) . '&run=' . $_GET['run'] . '">' . $row['name'] . '</a>';
         unset($row['symbol_id']);
         $table->addRow($row);
     }
     $statement = $database->select(RelatedStat::table())->select("SUM(?)/1000000 AS total_wt, SUM(?) AS total_ct, COUNT(DISTINCT ?) AS runs, ? AS symbol_id, ?", $inc->wallTime, $inc->calls, $inc->runId, $inc->childSymbolId, Symbol::columns()->name)->leftJoin('? ON ? = ?', Symbol::table(), Symbol::columns()->id, $inc->childSymbolId)->where('? = ?', $inc->parentSymbolId, $symbol->id)->groupBy($inc->childSymbolId)->order('total_wt DESC')->limit(50);
     $res = $statement->query();
     $table = new HTML();
     $stack->push(Raw::create('<h2>Children</h2>'));
     $stack->push($table);
     foreach ($res as $row) {
         $row['percent'] = round(100 * $row['total_wt'] / $total_wt, 2);
         $row['name'] = '<a href="?symbol=' . urlencode($row['name']) . '&run=' . $_GET['run'] . '">' . $row['name'] . '</a>';
         unset($row['symbol_id']);
         $table->addRow($row);
     }
     $this->layout->setTitle($symbol->name)->pushMain($stack)->render();
 }
コード例 #6
0
ファイル: Compare.php プロジェクト: phperf/xhprof-analytics
 /**
  * @return $this|\Yaoi\Sql\SelectInterface|\Yaoi\Sql\UpdateInterface
  */
 public function build($statExpr)
 {
     $symbolsDerived = SymbolStat::table('s');
     $symbolsDerivedCols = SymbolStat::columns($symbolsDerived);
     $symbolCols = Symbol::columns();
     $this->expr = Database::getInstance()->statement()->select('? AS ?', $symbolCols->name, new S('function'))->from('? AS s', $statExpr)->leftJoin('? ON ? = ?', Symbol::table(), $symbolsDerivedCols->symbolId, $symbolCols->id)->groupBy('?', $symbolsDerivedCols->symbolId);
     $this->avgWtSymbols = array();
     foreach ($this->runs as $run) {
         $runXTable = SymbolStat::table($run->name);
         $runXCols = SymbolStat::columns($runXTable);
         $this->addColumns($run, $runXCols);
         $this->expr->leftJoin('? ON ? = ? AND ? = ? AND ? = ?', $runXTable, $runXCols->symbolId, $symbolsDerivedCols->symbolId, $runXCols->isInclusive, $this->isInclusive, $runXCols->runId, $run->id);
     }
     $outerExpr = Database::getInstance()->statement()->select('*')->from('? AS ss', $this->expr)->order('COALESCE(null, ?) DESC', array($this->avgWtSymbols))->limit($this->limit);
     return $outerExpr;
 }
コード例 #7
0
ファイル: bootstrap.php プロジェクト: phperf/xhprof-analytics
<?php

namespace Phperf\Xhprof;

use Yaoi\Database;
use Yaoi\Log;
require_once __DIR__ . '/../vendor/autoload.php';
$dbFilePath = sys_get_temp_dir() . '/xh-tests.sqlite';
register_shutdown_function(function () use($dbFilePath) {
    unlink($dbFilePath);
});
Database::register('sqlite:///' . $dbFilePath);
unset($dbFilePath);
Entity\Migrations::create()->run();
Database::getInstance()->log(new Log('colored-stdout'));
コード例 #8
0
ファイル: Entity.php プロジェクト: php-yaoi/php-yaoi
 private static function getDatabase($class)
 {
     if (isset(self::$databases[$class])) {
         return self::$databases[$class];
     } else {
         return Database::getInstance();
     }
 }
コード例 #9
0
ファイル: App.php プロジェクト: php-yaoi/php-yaoi
 /**
  * @param string $identifier
  * @return Database\Contract
  */
 static function database($identifier = Service::PRIMARY)
 {
     return Database::getInstance($identifier);
 }