Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OutputBamboo.php
Go to the documentation of this file.
1 <?php
11 
12 class OutputBamboo extends \Magento\Framework\Profiler\Driver\Standard\Output\Csvfile
13 {
17  protected $_metrics;
18 
24  public function __construct(array $config = null)
25  {
26  parent::__construct($config);
27  $this->_metrics = isset($config['metrics']) ? (array)$config['metrics'] : [];
28  }
29 
38  protected function _aggregateTimerValues(
39  \Magento\Framework\Profiler\Driver\Standard\Stat $stat,
40  array $timerNames,
41  $fetchKey = \Magento\Framework\Profiler\Driver\Standard\Stat::AVG
42  ) {
43  /* Prepare pattern that matches timers with deepest nesting level only */
44  $nestingSep = preg_quote(\Magento\Framework\Profiler::NESTING_SEPARATOR, '/');
45  array_map('preg_quote', $timerNames, ['/']);
46  $pattern = '/(?<=' . $nestingSep . '|^)(?:' . implode('|', $timerNames) . ')$/';
47 
48  /* Sum profiler values for matched timers */
49  $result = 0;
50  foreach ($this->_getTimerIds($stat) as $timerId) {
51  if (preg_match($pattern, $timerId)) {
52  $result += $stat->fetch($timerId, $fetchKey);
53  }
54  }
55 
56  /* Convert seconds -> milliseconds */
57  $result = round($result * 1000);
58 
59  return $result;
60  }
61 
68  protected function _writeFileContent($fileHandle, \Magento\Framework\Profiler\Driver\Standard\Stat $stat)
69  {
70  /* First column must be a timestamp */
71  $result = ['Timestamp' => time()];
72  foreach ($this->_metrics as $metricName => $timerNames) {
73  $result[$metricName] = $this->_aggregateTimerValues($stat, $timerNames);
74  }
75  fputcsv($fileHandle, array_keys($result), $this->_delimiter, $this->_enclosure);
76  fputcsv($fileHandle, array_values($result), $this->_delimiter, $this->_enclosure);
77  }
78 }
_aggregateTimerValues(\Magento\Framework\Profiler\Driver\Standard\Stat $stat, array $timerNames, $fetchKey=\Magento\Framework\Profiler\Driver\Standard\Stat::AVG)
$pattern
Definition: website.php:22
$config
Definition: fraud_order.php:17
_writeFileContent($fileHandle, \Magento\Framework\Profiler\Driver\Standard\Stat $stat)