示例#1
1
 /**
  * @param $event
  * @param $parameters
  *
  * @return mixed|void
  */
 public function emit($event, $parameters)
 {
     self::$depth++;
     $this->stopwatch->openSection();
     if (isset($this->callbacks[$event])) {
         if (!$this->callbacks[$event][0]) {
             usort($this->callbacks[$event][1], function ($A, $B) {
                 if ($A[0] == $B[0]) {
                     return 0;
                 }
                 return $A[0] > $B[0] ? 1 : -1;
             });
             $this->callbacks[$event][0] = true;
         }
         foreach ($this->callbacks[$event][1] as $item) {
             $name = $this->getCallableName($item[1]);
             $this->stopwatch->start($name);
             $diagnoseEvent = Event::create()->setEvent($event)->setCallback($name)->setDepth(self::$depth);
             $this->events[] = $diagnoseEvent;
             call_user_func_array($item[1], $this->buildParameters($parameters));
             $stopwatchEvent = $this->stopwatch->stop($name);
             $diagnoseEvent->setDuration($stopwatchEvent->getDuration())->setMemory($stopwatchEvent->getMemory());
         }
     }
     $this->stopwatch->stopSection($event);
     self::$depth--;
 }
示例#2
1
 /**
  * @param        $url
  * @param array  $arguments
  * @param string $uniqueId
  *
  * @throws \Exception
  *
  * @return string
  */
 public function rasterizeUrl($url, $arguments = array(), $uniqueId = "")
 {
     if ($uniqueId === "") {
         $uniqueId = uniqid("rasterize-");
     }
     if ($this->stopwatch instanceof Stopwatch) {
         if ($this->stopwatch->isStarted($uniqueId)) {
             $this->stopwatch->lap($uniqueId);
         } else {
             $this->stopwatch->start($uniqueId);
         }
     }
     $process = $this->configHelper->buildProcess($url, $uniqueId, $arguments);
     $exitCode = $process->run();
     if ($exitCode != 0) {
         throw new \Exception(sprintf("Rasterize script failed.\nCommandLine: %s\nExitCode: %d\nErrorOutput: %s", $process->getCommandLine(), $process->getExitCode(), $process->getErrorOutput()));
     }
     if ($this->stopwatch instanceof Stopwatch) {
         $this->stopwatch->stop($uniqueId);
     }
     $output = $this->configHelper->getOutputFilePath($uniqueId);
     $content = file_get_contents($output);
     unlink($output);
     return $content;
 }
 function it_stops(Stopwatch $stopwatch, StopwatchEvent $event)
 {
     $stopwatch->getEvent('dom_manipulator_rules')->shouldBeCalled()->willReturn($event);
     $stopwatch->stop('dom_manipulator')->shouldBeCalled()->willReturn($event);
     $stopwatch->stop('dom_manipulator_manipulation')->shouldBeCalled()->willReturn($event);
     $this->stop();
 }
示例#4
0
 /**
  * Logs with an arbitrary level.
  *
  * @param  mixed  $level
  * @param  string $message
  * @param  array  $context
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     if (null === $this->logger) {
         return;
     }
     $add = true;
     $stackTrace = $this->getStackTrace();
     if (null !== $this->stopwatch) {
         $trace = debug_backtrace();
         $method = $trace[3]['function'];
         $watch = 'Propel Query ' . (count($this->queries) + 1);
         if ('prepare' === $method) {
             $this->isPrepared = true;
             $this->stopwatch->start($watch, 'propel');
             $add = false;
         } elseif ($this->isPrepared) {
             $this->isPrepared = false;
             $event = $this->stopwatch->stop($watch);
         }
     }
     // $trace[2] has no 'object' key if an exception is thrown while executing a query
     if ($add && isset($event) && isset($trace[2]['object'])) {
         $connection = $trace[2]['object'];
         $this->queries[] = array('sql' => $message, 'connection' => $connection->getName(), 'time' => $event->getDuration() / 1000, 'memory' => $event->getMemory(), 'stackTrace' => $stackTrace);
     }
     $this->logger->log($level, $message, $context);
 }
示例#5
0
 /**
  * @return string
  */
 public function compile()
 {
     $this->stopwatch->start('webpack.total');
     $this->stopwatch->start('webpack.prepare');
     // Recompile twig templates where its needed.
     $this->addSplitPoints();
     $this->addResolveConfig();
     // Write the webpack configuration file.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.config.js', $this->generator->getConfiguration());
     $this->profiler->set('compiler.performance.prepare', $this->stopwatch->stop('webpack.prepare')->getDuration());
     $this->stopwatch->start('webpack.compiler');
     $this->process->run();
     $output = $this->process->getOutput() . $this->process->getErrorOutput();
     $this->profiler->set('compiler.executed', true);
     $this->profiler->set('compiler.successful', strpos($output, 'Error:') === false);
     $this->profiler->set('compiler.last_output', $output);
     if ($this->profiler->get('compiler.successful')) {
         $this->tracker->rebuild();
     }
     // Finally, write some logging for later use.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.compiler.log', $output);
     $this->profiler->set('compiler.performance.compiler', $this->stopwatch->stop('webpack.compiler')->getDuration());
     $this->profiler->set('compiler.performance.total', $this->stopwatch->stop('webpack.total')->getDuration());
     return $output;
 }
示例#6
0
 /**
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  *
  * @return array
  */
 protected function getLogData(RequestInterface $request, ResponseInterface $response = null)
 {
     $time = $this->stopwatch->stop(self::STOPWATCH_EVENT)->getDuration();
     $uagent = $request->getHeader('User-Agent', '-');
     $uagent = $uagent[0];
     $xcache = $response && $response->hasHeaderWithValue('x-cache', 'HIT') ? 'HIT' : 'MISS';
     $postDumpLimit = 200;
     $postData = json_encode($request->getPostParams());
     if (strlen($postData) > $postDumpLimit) {
         $postData = substr($postData, 0, $postDumpLimit) . '...';
     }
     $data = array();
     $data[] = $xcache;
     $data[] = bcdiv($time, 1000, 4);
     // milliseconds
     $data[] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // @todo ip is always set to 127.0.0.1 due to broken request object
     $data[] = $request->getMethod();
     $data[] = $request->getUri();
     $data[] = $response ? $response->getStatusCode() : '-';
     // bytes
     $data[] = $response ? $response->getLength() : '-';
     // bytes
     $data[] = sprintf('"%s"', $uagent);
     $data[] = $postData;
     return $data;
 }
 /** {@inheritdoc} */
 public function invoke($calls)
 {
     $this->stopwatch->start($this->clientName, 'rpc_call');
     $collection = new TraceableResponseCollection($this->client->invoke($calls), $this->stopwatch, $this->clientName);
     $this->stopwatch->stop($this->clientName);
     return $collection;
 }
 /** {@inheritdoc} */
 public function getResponse(RpcRequestInterface $request)
 {
     $this->stopwatch->start($this->client, 'rpc_response');
     $response = $this->collection->getResponse($request);
     $this->stopwatch->stop($this->client);
     return $response;
 }
 /**
  * @inheritDoc
  */
 public function fetchWithNamespace($id, $namespaceId = null)
 {
     self::$stopwatch->start('doctrine_cache_extension_bundle');
     $data = $this->cacheProviderDecorator->fetchWithNamespace($id, $namespaceId);
     self::$stopwatch->stop('doctrine_cache_extension_bundle');
     self::$collectedData[self::$callId++] = new FetchWithNamespaceCacheCollectedData($id, $namespaceId, $data, self::$stopwatch);
     return $data;
 }
示例#10
0
 /**
  * @return void
  */
 public function stopQuery()
 {
     if ($this->stopwatch) {
         $this->stopwatch->stop('sphinx');
     }
     $this->queries[$this->queryCurrent]['time'] = microtime(true) - $this->queryStart;
     $this->queryCurrent++;
 }
 /**
  * @param ConsoleTerminateEvent $event
  */
 public function onConsoleTerminate(ConsoleTerminateEvent $event)
 {
     if ('check' == $event->getCommand()->getName()) {
         $stopEvent = $this->stopwatch->stop('check_command');
         $output = $event->getOutput();
         $output->writeln(sprintf('Checked source files in %s seconds, %s MB memory used', $stopEvent->getDuration() / 1000, $stopEvent->getMemory() / 1024 / 1024));
     }
 }
 /**
  * @param string $function
  * @param array  $arguments
  *
  * @return mixed
  */
 private function collectFilter($function, $arguments)
 {
     $this->stopwatch->start('acl.filters');
     $result = call_user_func_array([$this->aclFilter, $function], $arguments);
     $periods = $this->stopwatch->stop('acl.filters')->getPeriods();
     $this->filters[] = ['method' => $function, 'query' => $result->getSQL(), 'time' => end($periods)->getDuration()];
     return $result;
 }
 /**
  * @param PostResponseEvent $event
  */
 public function onKernelTerminate(PostResponseEvent $event)
 {
     $stopwatchEvent = $this->stopwatch->stop('request');
     $duration = $stopwatchEvent->getDuration();
     $attributes = $this->flattenAttributes($event->getRequest()->attributes->all());
     $data = ['service' => 'request.duration', 'metrics' => $duration];
     $this->logger->log($data, $attributes);
 }
示例#14
0
 /**
  * {@inheritdoc}
  */
 public function trace(array $spans)
 {
     $key = count($spans) == 1 ? $spans[0]->getName() : count($spans);
     $key = 'trace (' . $key . ')';
     $this->stopwatch->start($key);
     $this->decoratedTracer->trace($spans);
     $this->stopwatch->stop($key);
 }
示例#15
0
 /**
  * @param string|array $data
  * @param string       $routeName
  * @param array[]      $routeParameters
  */
 public function push($data, $routeName, array $routeParameters = array(), array $context = [])
 {
     $eventName = 'push.' . $this->getName();
     $this->stopwatch->start($eventName, 'websocket');
     $this->pusher->push($data, $routeName, $routeParameters, $context);
     $this->stopwatch->stop($eventName);
     $this->dataCollector->collectData($this->stopwatch->getEvent($eventName), $this->getName());
 }
 /**
  * Stops the stopwatch.
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  */
 private function onRequestComplete(RequestInterface $request, ResponseInterface $response)
 {
     $hash = $this->hash($request);
     // Send the log message to the adapter, adding a category and host
     $priority = $response && $this->isError($response) ? LOG_ERR : LOG_DEBUG;
     $message = $this->formatter->format($request, $response);
     $event = $this->stopwatch->stop($hash);
     $this->logAdapter->log($message, $priority, array('request' => $request, 'response' => $response, 'time' => $event->getDuration()));
 }
示例#17
0
 /**
  * {@inheritdoc}
  */
 public function end(LogOperation $log)
 {
     if (!is_null($this->stopwatch)) {
         $this->stopwatch->stop('ldaptools');
     }
     if (!is_null($this->logger)) {
         $this->log($log);
     }
 }
 /**
  * Stop and assign values to contao debug bar.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function stop()
 {
     $rulesEvent = $this->watch->getEvent('dom_manipulator_rules');
     $manipulationEvent = $this->watch->stop('dom_manipulator_manipulation');
     $totalEvent = $this->watch->stop('dom_manipulator');
     $GLOBALS['TL_DEBUG']['dom_manipulator_total'] = $this->formatDuration('total', $totalEvent);
     $GLOBALS['TL_DEBUG']['dom_manipulator_rules'] = $this->formatDuration('rule creation', $rulesEvent);
     $GLOBALS['TL_DEBUG']['dom_manipulator_dom'] = $this->formatDuration('manipulation', $manipulationEvent);
 }
 /**
  * {@inheritdoc}
  */
 public function sendRequest($body)
 {
     $stopwatchId = uniqid('speicher210_fastbill.collector.transport.');
     $this->stopwatch->start($stopwatchId);
     $return = $this->service->sendRequest($body);
     $stop = $this->stopwatch->stop($stopwatchId);
     $this->requests[] = array('time' => $stop->getDuration(), 'request' => json_decode($body, true), 'response' => json_decode($return, true));
     return $return;
 }
 /**
  * @internal
  *
  * @param string $name
  * @param array  $arguments
  *
  * @return mixed
  */
 public function __call($name, array $arguments)
 {
     $this->stopwatch->start($this->name, $name);
     $this->logger->debug('> ' . $this->name . '::' . $name, $arguments);
     $r = call_user_func_array([$this->originalClient, $name], $arguments);
     $this->logger->debug('< ' . $this->name . '::' . $name, [$r]);
     $this->stopwatch->stop($this->name);
     return $r;
 }
 /**
  * Returns a callable handler that stops the stopwatch for the given request when it is successful.
  * (Fills the X-Duration header with the duration of the request in milliseconds.)
  *
  * @param RequestInterface $request The request.
  *
  * @return \Closure Handler.
  */
 protected function onSuccess(RequestInterface $request)
 {
     return function (ResponseInterface $response) use($request) {
         if (null !== $this->stopwatch) {
             $event = $this->stopwatch->stop((string) $request->getUri());
             return $response->withHeader('X-Duration', $event->getDuration());
         }
         return $response;
     };
 }
 /**
  * @param int $fileCount
  * @param int $violationCount
  */
 public function endProgress($fileCount, $violationCount)
 {
     $stats = $this->stopwatch->stop(static::PROGRESS_NAME);
     if (0 === $violationCount) {
         $this->output->writeln('<info>There are no violations - congratulations!</info>');
     } else {
         $this->output->writeln(sprintf('<comment>%s deprecations found.</comment>', $violationCount));
     }
     $this->output->writeln(sprintf('Checked %s source files in %s seconds, %s MB memory used', $fileCount, $stats->getDuration() / 1000, $stats->getMemory() / 1024 / 1024));
 }
示例#23
0
 /**
  * Ends the watch, extract logs and write them to the storage service chosen.
  * @param $identifier
  * @param OutputInterface|null $output If you want to write on output the logs
  * @param array $extra
  *
  * @return array
  */
 public function end($identifier, OutputInterface $output = null, $extra = array())
 {
     $logs = array();
     if ($this->stopWatch->isStarted($identifier)) {
         $stopWatchEvent = $this->stopWatch->stop($identifier);
         $logs = $this->extractLog($stopWatchEvent, $output, $extra);
         $this->writer->write($logs, $identifier);
     }
     return $logs;
 }
示例#24
0
 /**
  * @param string|null $returnValue
  *
  * @return string
  */
 public function stop($returnValue = null)
 {
     $this->output = ob_get_clean();
     $this->returnValue = $returnValue;
     $event = $this->stopWatch->stop($this->randomName);
     $this->duration = $event->getDuration();
     $this->memory = $event->getMemory();
     $this->startAt = $event->getOrigin();
     return $this->serialize();
 }
示例#25
0
 /**
  * {@inheritdoc}
  */
 public function stopQuery()
 {
     parent::stopQuery();
     if (null !== $this->stopwatch) {
         $this->stopwatch->stop('doctrine');
     }
     if ($this->enabled) {
         $this->queries[$this->currentQuery]['callstack'] = $this->callstack;
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doSendInternalRequests(array $internalRequests)
 {
     $this->stopwatch->start($name = 'ivory.http_adapter');
     try {
         $result = parent::doSendInternalRequests($internalRequests);
     } catch (\Exception $e) {
         $this->stopwatch->stop($name);
         throw $e;
     }
     $this->stopwatch->stop($name);
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function handleRequest(RequestInterface $request, callable $next, callable $first)
 {
     $eventName = $this->getStopwatchEventName($request);
     $this->stopwatch->start($eventName, self::CATEGORY);
     return $next($request)->then(function (ResponseInterface $response) use($eventName) {
         $this->stopwatch->stop($eventName, self::CATEGORY);
         return $response;
     }, function (Exception $exception) use($eventName) {
         $this->stopwatch->stop($eventName, self::CATEGORY);
         throw $exception;
     });
 }
 /**
  * Registers this collector on the event dispatcher
  *
  * @param \Symfony\Component\EventDispatcher\EventDispatcher
  * @return void
  */
 public function register($eventDispatcher)
 {
     // Add the listeners to start and stop events
     $eventDispatcher->addListener(WardenEvents::WARDEN_START, function (StartEvent $event) {
         $this->stopwatch->start('request');
     });
     $eventDispatcher->addListener(WardenEvents::WARDEN_END, function (StopEvent $event) {
         $sw = $this->stopwatch->stop('request');
         $event->params->setValue('request_time', $sw->getDuration());
         $event->params->setValue('request_memory', $sw->getMemory());
     });
 }
示例#29
0
 /**
  * {@inheritdoc}
  */
 protected function decorate($method, array $params = array())
 {
     $this->stopwatch->start($name = 'ivory.http_adapter');
     try {
         $result = parent::decorate($method, $params);
     } catch (\Exception $e) {
         $this->stopwatch->stop($name);
         throw $e;
     }
     $this->stopwatch->stop($name);
     return $result;
 }
示例#30
0
 /**
  * @param string $path
  * @param string $method
  * @param array  $data
  * @param array  $query
  *
  * @return \Elastica\Response
  */
 public function request($path, $method = Request::GET, $data = array(), array $query = array())
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('es_request', 'fos_elastica');
     }
     $start = microtime(true);
     $response = parent::request($path, $method, $data, $query);
     $this->logQuery($path, $method, $data, $query, $start);
     if ($this->stopwatch) {
         $this->stopwatch->stop('es_request');
     }
     return $response;
 }