Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractOutput.php
Go to the documentation of this file.
1 <?php
9 
10 abstract class AbstractOutput implements OutputInterface
11 {
17  protected $_filterPattern;
18 
24  protected $_thresholds = [Stat::TIME => 0.001, Stat::COUNT => 10, Stat::EMALLOC => 10000];
25 
31  protected $_columns = [
32  'Timer Id' => Stat::ID,
33  'Time' => Stat::TIME,
34  'Avg' => Stat::AVG,
35  'Cnt' => Stat::COUNT,
36  'Emalloc' => Stat::EMALLOC,
37  'RealMem' => Stat::REALMEM,
38  ];
39 
45  public function __construct(array $config = null)
46  {
47  if (!empty($config['filterPattern'])) {
48  $this->setFilterPattern($config['filterPattern']);
49  }
50  if (!empty($config['thresholds']) && is_array($config['thresholds'])) {
51  foreach ($config['thresholds'] as $fetchKey => $minAllowedValue) {
52  $this->setThreshold($fetchKey, (int)$minAllowedValue);
53  }
54  }
55  }
56 
63  public function setFilterPattern($filterPattern)
64  {
65  $this->_filterPattern = $filterPattern;
66  }
67 
73  public function getFilterPattern()
74  {
75  return $this->_filterPattern;
76  }
77 
87  public function setThreshold($fetchKey, $minAllowedValue)
88  {
89  if ($minAllowedValue === null) {
90  unset($this->_thresholds[$fetchKey]);
91  } else {
92  $this->_thresholds[$fetchKey] = $minAllowedValue;
93  }
94  }
95 
101  public function getThresholds()
102  {
103  return $this->_thresholds;
104  }
105 
113  protected function _renderColumnValue($value, $columnKey)
114  {
115  switch ($columnKey) {
116  case Stat::ID:
117  $result = $this->_renderTimerId($value);
118  break;
119  case Stat::TIME:
120  case Stat::AVG:
121  $result = number_format($value, 6);
122  break;
123  default:
124  $result = number_format((string)$value);
125  }
126  return $result;
127  }
128 
135  protected function _renderTimerId($timerId)
136  {
137  return $timerId;
138  }
139 
145  protected function _renderCaption()
146  {
147  return sprintf(
148  'Code Profiler (Memory usage: real - %s, emalloc - %s)',
149  memory_get_usage(true),
151  );
152  }
153 
162  protected function _getTimerIds(Stat $stat)
163  {
164  return $stat->getFilteredTimerIds($this->_thresholds, $this->_filterPattern);
165  }
166 }
getFilteredTimerIds(array $thresholds=null, $filterPattern=null)
Definition: Stat.php:156
$config
Definition: fraud_order.php:17
$value
Definition: gender.phtml:16