Beispiel #1
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;
 }
Beispiel #2
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--;
 }
 /**
  * @param CleverAge\Orchestrator\Events\ServiceEvent $event
  * @return Symfony\Component\Stopwatch\StopwatchEvent
  */
 protected function startProfiling(ServiceEvent $event)
 {
     if ($this->stopwatch instanceof Stopwatch) {
         $this->profiles[$event->getService()->getName()][$this->counter] = array('method' => $event->getRequestMethod(), 'parameters' => print_r($event->getRequestParameters(), true), 'results' => null, 'duration' => null, 'result_count' => 0);
         return $this->stopwatch->start($event->getService()->getName() . '_' . $this->counter);
     }
 }
 /**
  * @param App\CoreBundle\Event\BuildStartedEvent
  */
 public function onBuildStarted(BuildStartedEvent $event)
 {
     $build = $event->getBuild();
     $this->logger->info('starting stopwatch for build #' . $build->getId());
     $this->stopwatch->start($build->getChannel());
     $build->setStartTime(new DateTime());
 }
 /**
  * @param Event $e
  */
 private function start(Event $e)
 {
     $request = $e['request'];
     $this->requests[$this->hash($request)] = count($this->requests) + 1;
     $name = $this->getEventName($request);
     $this->stopwatch->start($name, 'guzzle');
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function enter(\Twig_Profiler_Profile $profile)
 {
     if ($this->stopwatch && $profile->isTemplate()) {
         $this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
     }
     parent::enter($profile);
 }
Beispiel #7
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;
 }
 /**
  * @param InvokeEvent $event
  */
 public function onBeforeInvoke(InvokeEvent $event)
 {
     if (!$this->stopwatch) {
         return;
     }
     $this->stopwatch->start('invoke ' . $event->getDirectRequest()->getRequestKey());
 }
Beispiel #9
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);
 }
 /** {@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;
 }
Beispiel #11
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);
 }
 /**
  * @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());
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function start(LogOperation $log)
 {
     if (!is_null($this->stopwatch)) {
         $this->stopwatch->start('ldaptools', strtolower($log->getOperation()->getName()));
     }
     if (!is_null($this->logger)) {
         $this->log($log);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function startQuery($sql, array $params = null, array $types = null)
 {
     if ($this->enabled) {
         $e = new \Exception();
         $this->callstack = $e->getTraceAsString();
     }
     if (null !== $this->stopwatch) {
         $this->stopwatch->start('doctrine');
     }
     parent::startQuery($sql, $params, $types);
 }
Beispiel #19
0
 /**
  * @param string     $sql    The SQL to be executed.
  * @param array|null $params The SQL parameters.
  * @param array|null $types  The SQL parameter types.
  * @return void
  */
 public function startQuery($sql, array $params = null, array $types = null)
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('sphinx', 'sphinx');
     }
     if ($this->logger) {
         $this->logger->debug($sql, $params === null ? array() : $params);
     }
     $this->queryStart = microtime(true);
     $this->queries[$this->queryCurrent] = array('sql' => $sql, 'params' => $params, 'time' => 0);
 }
 /**
  * {@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;
     });
 }
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $route = $event->getRequest()->get('_route');
     // Ignore web debug toolbar
     if (null !== $route && '_wdt' !== $route) {
         $this->stopwatch = new Stopwatch();
         $this->stopwatch->start($event->getRequest()->getUri());
     }
 }
 /**
  * {@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;
 }
 /**
  * {@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;
 }
 /**
  * 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());
     });
 }
 private function watch($name)
 {
     if ($this->stopwatch !== null) {
         switch ($name) {
             case 'query:pre':
                 $this->stopwatch->start('query.pomm', 'pomm');
                 break;
             case 'query:post':
                 $this->stopwatch->stop('query.pomm');
                 break;
         }
     }
 }
Beispiel #26
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;
 }
 /**
  * Prints runner start information.
  *
  * @param Event $event
  *
  * @return null
  */
 public function onRunnerStart(Event $event)
 {
     $this->stopwatch->start('runner');
     /** @var DeploymentPayload $payload */
     $payload = $event->getPayload();
     $this->outputHandler->write('');
     $this->outputHandler->write('+-----');
     $this->outputHandler->write(sprintf("| Deploying project '%s' to environment '%s'", $payload->getProject()->getName(), $payload->getEnvironment()->getName()));
     $this->outputHandler->write('+-----');
     $this->outputHandler->write(sprintf("| Mode: %s", $payload->isDryRun() ? '<warning>Dry-Run</warning>' : '<success>No Dry-Run</success>'));
     $this->outputHandler->write('+-----');
     $this->outputHandler->write('|');
 }
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     $string = $input->getArgument('query');
     $raw = $input->getOption('raw');
     if (!$raw) {
         $output->writeln(sprintf('Parsing search query: <comment>%s</comment>', $string));
         $output->writeln(str_repeat('-', 20));
     }
     $postprocessing = !$input->getOption('no-compiler-postprocessing');
     $compiler = $this->container['query_compiler'];
     $stopwatch = new Stopwatch();
     $stopwatch->start('parsing');
     if ($input->getOption('compiler-dump')) {
         $dump = $compiler->dump($string, $postprocessing);
     } else {
         $query = $compiler->parse($string, $postprocessing);
         $dump = $query->dump();
     }
     $event = $stopwatch->stop('parsing');
     if (!$raw) {
         $output->writeln($dump);
         $output->writeln(str_repeat('-', 20));
         $output->writeln(sprintf("Took %sms", $event->getDuration()));
     } else {
         $output->write($dump);
     }
 }
 /**
  * Starts profiling
  *
  * @param string $name   Method name
  * @param string $query  Query text
  * @param string $source Source language
  * @param string $target Target language
  *
  * @return StopwatchEvent
  */
 protected function startProfiling($name, $query, $source = null, $target = null)
 {
     if ($this->stopwatch instanceof Stopwatch) {
         $this->profiles[$this->counter] = array('query' => urldecode($query), 'source' => $source, 'target' => $target, 'duration' => null, 'memory_start' => memory_get_usage(true), 'memory_end' => null, 'memory_peak' => null);
         return $this->stopwatch->start($name);
     }
 }
Beispiel #30
0
 /**
  * @return User[]
  */
 public function getBirthdays()
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('block_birthdays', 'home_blocks');
     }
     $query = $this->manager->createQueryBuilder()->select('u, m, o')->from('EtuUserBundle:User', 'u')->leftJoin('u.memberships', 'm')->leftJoin('m.organization', 'o')->where('DAY(u.birthday) = DAY(CURRENT_TIMESTAMP())')->andWhere('MONTH(u.birthday) = MONTH(CURRENT_TIMESTAMP())')->andWhere('u.birthday IS NOT NULL')->andWhere('u.birthdayPrivacy = :privacy')->setParameter('privacy', User::PRIVACY_PUBLIC)->andWhere('u.id != :me')->setParameter('me', $this->user->getId())->getQuery();
     $query->useResultCache(true, 3600);
     /** @var User[] $users */
     $users = $query->getResult();
     // Find more interesting birthdays : same promotion (SRT4), same branch (SRT), others
     $usersWeights = [];
     foreach ($users as $key => $user) {
         $usersWeights[$key] = 0;
         if ($user->getBranch() == $this->user->getBranch()) {
             $usersWeights[$key]++;
         }
         if ($user->getNiveau() == $this->user->getNiveau()) {
             $usersWeights[$key]++;
         }
     }
     array_multisort($usersWeights, SORT_DESC, SORT_NUMERIC, $users);
     $result = array_slice($users, 0, 3);
     if ($this->stopwatch) {
         $this->stopwatch->stop('block_birthdays');
     }
     return $result;
 }