/** * 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); }
/** * 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)); }