/**
  * @param Profile $profile
  */
 public function save(Profile $profile)
 {
     $dto = new ProfileDto();
     $dto->token = $profile->getToken();
     $dto->serialized = base64_encode(serialize($profile));
     $this->entityManager->persist($dto);
     $this->entityManager->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function write(Profile $profile)
 {
     $args = ['token' => $profile->getToken(), 'parent' => $profile->getParentToken(), 'data' => base64_encode(serialize($profile->getCollectors())), 'ip' => $profile->getIp(), 'method' => $profile->getMethod(), 'url' => $profile->getUrl(), 'time' => $profile->getTime(), 'created_at' => time()];
     try {
         $query = $this->database->select('webprofiler', 'w')->fields('w', ['token']);
         $query->condition('token', $profile->getToken());
         $count = $query->countQuery()->execute()->fetchAssoc();
         if ($count['expression']) {
             $this->database->update('webprofiler')->fields($args)->condition('token', $profile->getToken())->execute();
         } else {
             $this->database->insert('webprofiler')->fields($args)->execute();
         }
         $status = TRUE;
     } catch (\Exception $e) {
         $status = FALSE;
     }
     return $status;
 }
 /**
  * @param $profile ->getToken()
  * @param int $qid
  *
  * @return array
  */
 private function getQuery(Profile $profile, $qid)
 {
     $this->profiler->disable();
     $token = $profile->getToken();
     if (!($profile = $this->profiler->loadProfile($token))) {
         throw new NotFoundHttpException($this->t('Token @token does not exist.', ['@token' => $token]));
     }
     /** @var DatabaseDataCollector $databaseCollector */
     $databaseCollector = $profile->getCollector('database');
     $queries = $databaseCollector->getQueries();
     $query = $queries[$qid];
     return $query;
 }
 /**
  * {@inheritdoc}
  */
 public function write(Profile $profile)
 {
     $db = $this->initDb();
     $args = array(':token' => $profile->getToken(), ':parent' => $profile->getParent() ? $profile->getParent()->getToken() : '', ':data' => base64_encode(serialize($profile->getCollectors())), ':ip' => $profile->getIp(), ':url' => $profile->getUrl(), ':time' => $profile->getTime(), ':created_at' => time());
     try {
         $this->exec($db, 'INSERT INTO sf_profiler_data (token, parent, data, ip, url, time, created_at) VALUES (:token, :parent, :data, :ip, :url, :time, :created_at)', $args);
         $this->cleanup();
         $status = true;
     } catch (\Exception $e) {
         $status = false;
     }
     $this->close($db);
     return $status;
 }
 /**
  * Update the profiles with the timing info and saves them.
  *
  * @param Profile $profile        The root profile
  * @param Boolean $updateChildren Whether to update the children altogether
  */
 private function saveStopwatchInfoInProfile(Profile $profile, $updateChildren)
 {
     $profile->getCollector('time')->setEvents($this->stopwatch->getSectionEvents($profile->getToken()));
     $this->profiler->saveProfile($profile);
     if ($updateChildren) {
         foreach ($profile->getChildren() as $child) {
             $this->saveStopwatchInfoInProfile($child, true);
         }
     }
 }
 /**
  * Update the profiles with the timing and events information and saves them.
  *
  * @param Profile $profile        The root profile
  * @param Boolean $updateChildren Whether to update the children altogether
  */
 private function saveInfoInProfile(Profile $profile, $updateChildren)
 {
     try {
         $collector = $profile->getCollector('memory');
         $collector->updateMemoryUsage();
     } catch (\InvalidArgumentException $e) {
     }
     try {
         $collector = $profile->getCollector('time');
         $collector->setEvents($this->stopwatch->getSectionEvents($profile->getToken()));
     } catch (\InvalidArgumentException $e) {
     }
     try {
         $collector = $profile->getCollector('events');
         $collector->setCalledListeners($this->getCalledListeners());
         $collector->setNotCalledListeners($this->getNotCalledListeners());
     } catch (\InvalidArgumentException $e) {
     }
     $this->profiler->saveProfile($profile);
     if ($updateChildren) {
         foreach ($profile->getChildren() as $child) {
             $this->saveInfoInProfile($child, true);
         }
     }
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function write(Profile $profile)
 {
     $data = array('token' => $profile->getToken(), 'parent' => $profile->getParentToken(), 'children' => array_map(function ($p) {
         return $p->getToken();
     }, $profile->getChildren()), 'data' => $profile->getCollectors(), 'ip' => $profile->getIp(), 'method' => $profile->getMethod(), 'url' => $profile->getUrl(), 'time' => $profile->getTime());
     if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime, self::REDIS_SERIALIZER_PHP)) {
         // Add to index
         $indexName = $this->getIndexName();
         $indexRow = implode("\t", array($profile->getToken(), $profile->getIp(), $profile->getMethod(), $profile->getUrl(), $profile->getTime(), $profile->getParentToken())) . "\n";
         return $this->appendValue($indexName, $indexRow, $this->lifetime);
     }
     return false;
 }
 /**
  * Collects data for the given Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An exception instance if the request threw one
  *
  * @return Profile|null A Profile instance or null if the profiler is disabled
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (false === $this->enabled) {
         return;
     }
     $profile = new Profile(substr(sha1(uniqid(mt_rand(), true)), 0, 6));
     $profile->setTime(time());
     $profile->setUrl($request->getUri());
     $profile->setIp($request->getClientIp());
     $profile->setMethod($request->getMethod());
     $response->headers->set('X-Debug-Token', $profile->getToken());
     foreach ($this->collectors as $collector) {
         $collector->collect($request, $response, $exception);
         // forces collectors to become "read/only" (they loose their object dependencies)
         $profile->addCollector(unserialize(serialize($collector)));
     }
     return $profile;
 }
Esempio n. 9
0
 /**
  * Collects data for the given Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An exception instance if the request threw one
  *
  * @return Profile|null A Profile instance or null if the profiler is disabled
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (false === $this->enabled) {
         return;
     }
     $profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
     $profile->setTime(time());
     $profile->setUrl($request->getUri());
     $profile->setIp($request->getClientIp());
     $profile->setMethod($request->getMethod());
     $profile->setStatusCode($response->getStatusCode());
     $response->headers->set('X-Debug-Token', $profile->getToken());
     foreach ($this->collectors as $collector) {
         $collector->collect($request, $response, $exception);
         // we need to clone for sub-requests
         $profile->addCollector(clone $collector);
     }
     return $profile;
 }
Esempio n. 10
0
 /**
  * Returns the parent token.
  *
  * @return null|string The parent token
  */
 public function getParentToken()
 {
     return $this->parent ? $this->parent->getToken() : null;
 }
Esempio n. 11
0
 /**
  * Collects data for the given Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An exception instance if the request threw one
  *
  * @return Profile|false A Profile instance or false if the profiler is disabled
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (false === $this->enabled) {
         return;
     }
     $profile = new Profile(uniqid());
     $profile->setTime(time());
     $profile->setUrl($request->getUri());
     $profile->setIp($request->server->get('REMOTE_ADDR'));
     $response->headers->set('X-Debug-Token', $profile->getToken());
     $collectors = array();
     foreach ($this->collectors as $name => $collector) {
         $collector->collect($request, $response, $exception);
         // forces collectors to become "read/only" (they loose their object dependencies)
         $profile->addCollector(unserialize(serialize($collector)));
     }
     return $profile;
 }