Report.php in XHProf 8
File
src/XHProfLib/Report/Report.php
View source
<?php
namespace Drupal\xhprof\XHProfLib\Report;
use Drupal\xhprof\XHProfLib\Parser\Parser;
class Report implements ReportInterface {
private $data;
private $parser;
public function __construct(Parser $parser) {
$this->parser = $parser;
$this->data = $parser
->parse();
}
public function getSymbols($length = 100) {
if ($length != -1) {
$data = array_slice($this->data, 0, $length);
}
else {
$data = $this->data;
}
$totals = $this
->getTotals();
$symbols = [];
foreach ($data as $key => $value) {
$symbol = [];
$symbol[] = $key;
$symbol[] = $this
->getValue($value['ct'], 'ct');
$symbol[] = $this
->getPercentValue($value['ct'], 'ct', $totals['ct']);
foreach ($this
->getMetrics() as $metric) {
$symbol[] = $this
->getValue($value[$metric], $metric);
$symbol[] = $this
->getPercentValue($value[$metric], $metric, $totals[$metric]);
$symbol[] = $this
->getValue($value['excl_' . $metric], 'excl_' . $metric);
$symbol[] = $this
->getPercentValue($value['excl_' . $metric], 'excl_' . $metric, $totals[$metric]);
}
$symbols[$key] = $symbol;
}
return $symbols;
}
public function getSummary() {
$summary = [];
$totals = $this
->getTotals();
foreach ($this
->getMetrics() as $metric) {
$summary[$metric] = $this
->getValue($totals[$metric], $metric);
}
if ($this
->getDisplayCalls()) {
$summary['ct'] = $this
->getValue($totals['ct'], 'ct');
}
return $summary;
}
public function getTotals() {
return $this->parser
->getTotals();
}
public function getPossibleMetrics() {
return $this->parser
->getPossibleMetrics();
}
public function getMetrics() {
return $this->parser
->getMetrics();
}
public function getDisplayCalls() {
return $this->parser
->getDisplayCalls();
}
private function getValue($value, $metric) {
$format_cbk = ReportConstants::getFormatCbk();
return call_user_func($format_cbk[$metric], $value);
}
private function getPercentValue($value, $metric, $totals) {
if ($totals == 0) {
$pct = "N/A%";
}
else {
$format_cbk = ReportConstants::getFormatCbk();
$pct = call_user_func($format_cbk[$metric . '_perc'], $value / abs($totals));
}
return $pct;
}
}