Exemplo n.º 1
0
    /**
     * Build timeline JS code for the given profile.
     *
     * @param \Sandstorm\PhpProfiler\Domain\Model\ProfilingRun $profile
     * @param integer $eventSourceIndex
     * @return string
     */
    protected function buildJavaScriptForProfile(ProfilingRun $profile, $eventSourceIndex)
    {
        $javaScript = array();
        foreach ($profile->getTimersAsDuration() as $event) {
            $javaScript[] = sprintf('timelineRunner.addEvent(%s, new Timeline.DefaultEventSource.Event({
				start: new Date(%s),
				end:  new Date(%s),
				durationEvent: true,
				caption: %s,
				description: %s,
				color: "#%s"
			}));', $eventSourceIndex, (int) ($event['start'] * 1000), (int) ($event['stop'] * 1000), json_encode($event['name']), json_encode($event['data']), $this->getColorForEventName($event['name']));
        }
        foreach ($profile->getTimestamps() as $event) {
            $javaScript[] = sprintf('timelineRunner.addEvent(%s, new Timeline.DefaultEventSource.Event({
				start: new Date(%s),
				durationEvent: false,
				text: %s,
				caption: %s,
				description: %s,
				color: "#%s"
			}));', $eventSourceIndex, (int) ($event['time'] * 1000), json_encode($event['name']), json_encode($event['name']), json_encode($event['data']), $this->getColorForEventName($event['name']));
        }
        $memory = $profile->getMemory();
        foreach ($memory as &$record) {
            $record['time'] = (int) ($record['time'] * 1000);
        }
        $javaScript[] = sprintf('timelineRunner.setMemory(%s, %s);', $eventSourceIndex, json_encode($memory));
        return implode("\n", $javaScript);
    }
Exemplo n.º 2
0
 /**
  * Calculate the maximum memory usage for the given profile.
  *
  * @param \Sandstorm\PhpProfiler\Domain\Model\ProfilingRun $profile
  * @param array $calculationOptions
  * @return array
  */
 protected function calculateMaxMemory(ProfilingRun $profile, array $calculationOptions)
 {
     $memory = $profile->getMemory();
     $lastSamplingPoint = array_pop($memory);
     return array('value' => round($lastSamplingPoint['mem'] / 1024));
 }
Exemplo n.º 3
0
 /**
  * Wire signals to slots as needed in TYPO3 Neos.
  *
  * @param \TYPO3\Flow\SignalSlot\Dispatcher $dispatcher
  * @param Profiler $profiler
  * @param \Sandstorm\PhpProfiler\Domain\Model\ProfilingRun $run
  * @param \TYPO3\Flow\Core\Bootstrap $bootstrap
  * @return void
  */
 protected function connectToNeosSignals(\TYPO3\Flow\SignalSlot\Dispatcher $dispatcher, Profiler $profiler, \Sandstorm\PhpProfiler\Domain\Model\ProfilingRun $run, \TYPO3\Flow\Core\Bootstrap $bootstrap)
 {
     $dispatcher->connect('TYPO3\\TypoScript\\Core\\Runtime', 'beginEvaluation', function ($typoScriptPath) use($run) {
         $run->startTimer('TypoScript Runtime: ' . $typoScriptPath);
     });
     $dispatcher->connect('TYPO3\\TypoScript\\Core\\Runtime', 'endEvaluation', function ($typoScriptPath) use($run) {
         $run->stopTimer('TypoScript Runtime: ' . $typoScriptPath);
     });
     $dispatcher->connect('TYPO3\\Neos\\View\\TypoScriptView', 'beginRender', function () use($run) {
         $run->startTimer('Neos TypoScript Rendering');
     });
     $dispatcher->connect('TYPO3\\Neos\\View\\TypoScriptView', 'endRender', function () use($run) {
         $run->stopTimer('Neos TypoScript Rendering');
     });
 }
Exemplo n.º 4
0
 /**
  * Save a profiling run.
  *
  * @param Domain\Model\ProfilingRun $run
  * @throws \Exception
  * @return void
  */
 public function save(Domain\Model\ProfilingRun $run)
 {
     $configuration = $this->configurationProvider->__invoke();
     if (!isset($configuration['plumber']['profilePath'])) {
         throw new \Exception('Profiling path not set');
     }
     $run->save($configuration);
 }