Esempio n. 1
0
 public function testMonitor()
 {
     self::$monitor->snapShot('begin');
     require_once __DIR__ . '/dummy-php-file.php';
     self::$monitor->snapShot('after-include');
     $bytes = str_repeat('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 10000);
     $snapShots = self::$monitor->getSnapShots();
     $this->assertEquals(3, count($snapShots));
     $this->assertEquals(1, $snapShots['after-include']->numFilesIncludedSincePreviousSnapshot());
     $this->assertNotEmpty($snapShots['after-include']->memoryAllocationDifference());
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function getView(MonitorInterface $monitor)
 {
     $table = $this->getTableOpeningMarkup();
     $tableRowMarkup = $this->getTableRowMarkup();
     $performanceInfo = $monitor->getPerformanceInfo();
     $lastPercent = 0;
     foreach ($monitor->getSnapShots() as $name => $snapshot) {
         list($label, $percent) = $this->getPercentageDisplay($snapshot, $performanceInfo, $lastPercent);
         $table .= sprintf($tableRowMarkup, $name, $snapshot->timePassed(), $snapshot->memoryAllocated(), $snapshot->numFilesIncludedSincePreviousSnapshot(), $snapshot->numClassesDeclaredSincePreviousSnapshot(), $label);
         $lastPercent = $percent;
         $this->keepTrackOfPeakingMemoryAllocation($snapshot, $name);
     }
     $table .= sprintf($tableRowMarkup, 'Finish', $performanceInfo->timePassed(), $performanceInfo->memoryAllocated(), $performanceInfo->numFilesIncluded(), $performanceInfo->numClassesDeclared(), '100%' . (isset($lastPercent) ? ' <em>(' . (100 - $lastPercent) . '%)</em>' : ''));
     $table .= '</tbody></table>';
     return sprintf('<div id="php-benchmark-result" style="%s">
             <style type="text/css" scoped="scoped">
             %s
             </style>
             %s
             %s
         </div>', $this->getContainerCSS(), $this->getTableCSS(), $table, $this->informAboutPeakingMemoryAllocation($performanceInfo));
 }