/**
  * @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();
 }
示例#2
0
 /**
  * @param \Symfony\Component\HttpKernel\Profiler\Profile $profile
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function savePerformanceTimingAction(Profile $profile, Request $request)
 {
     $this->profiler->disable();
     $data = Json::decode($request->getContent());
     /** @var  $collector */
     $collector = $profile->getCollector('performance_timing');
     $collector->setData($data);
     $this->profiler->updateProfile($profile);
     return new JsonResponse(['success' => TRUE]);
 }
 /**
  * @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;
 }
 public function testCleanup()
 {
     $dt = new \DateTime('-2 day');
     for ($i = 0; $i < 3; $i++) {
         $dt->modify('-1 day');
         $profile = new Profile('time_' . $i);
         $profile->setTime($dt->getTimestamp());
         $profile->setMethod('GET');
         self::$storage->write($profile);
     }
     $records = self::$storage->find('', '', 3, 'GET');
     $this->assertCount(1, $records, '->find() returns only one record');
     $this->assertEquals($records[0]['token'], 'time_2', '->find() returns the latest added record');
     self::$storage->purge();
 }
 public function testUtf8()
 {
     $profile = new Profile('utf8_test_profile');
     $data = 'HЁʃʃϿ, ϢorЃd!';
     $nonUtf8Data = mb_convert_encoding($data, 'UCS-2');
     $collector = new MongoDbProfilerStorageTestDataCollector();
     $collector->setData($nonUtf8Data);
     $profile->setCollectors(array($collector));
     self::$storage->write($profile);
     $readProfile = self::$storage->read('utf8_test_profile');
     $collectors = $readProfile->getCollectors();
     $this->assertCount(1, $collectors);
     $this->assertArrayHasKey('test_data_collector', $collectors);
     $this->assertEquals($nonUtf8Data, $collectors['test_data_collector']->getData(), 'Non-UTF8 data is properly encoded/decoded');
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 protected function createProfileFromData($token, $data, $parent = NULL)
 {
     $profile = new Profile($token);
     $profile->setIp($data['ip']);
     $profile->setMethod($data['method']);
     $profile->setUrl($data['url']);
     $profile->setTime($data['time']);
     $profile->setCollectors($data['data']);
     $profile->setStatusCode($data['status_code']);
     return $profile;
 }
 public function testMultiRowIndexFile()
 {
     $iteration = 3;
     for ($i = 0; $i < $iteration; $i++) {
         $profile = new Profile('token' . $i);
         $profile->setIp('127.0.0.' . $i);
         $profile->setUrl('http://foo.bar/' . $i);
         $storage = $this->getStorage();
         $storage->write($profile);
         $storage->write($profile);
         $storage->write($profile);
     }
     $handle = fopen(self::$tmpDir . '/index.csv', 'r');
     for ($i = 0; $i < $iteration; $i++) {
         $row = fgetcsv($handle);
         $this->assertEquals('token' . $i, $row[0]);
         $this->assertEquals('127.0.0.' . $i, $row[1]);
         $this->assertEquals('http://foo.bar/' . $i, $row[3]);
     }
     $this->assertFalse(fgetcsv($handle));
 }
示例#8
0
 /**
  * Gets template names of templates that are present in the viewed profile.
  *
  * @param Profile $profile
  *
  * @return array
  *
  * @throws \UnexpectedValueException
  */
 protected function getNames(Profile $profile)
 {
     $templates = array();
     foreach ($this->templates as $arguments) {
         if (null === $arguments) {
             continue;
         }
         list($name, $template) = $arguments;
         if (!$this->profiler->has($name) || !$profile->hasCollector($name)) {
             continue;
         }
         if ('.html.twig' === substr($template, -10)) {
             $template = substr($template, 0, -10);
         }
         if (!$this->templateExists($template . '.html.twig')) {
             throw new \UnexpectedValueException(sprintf('The profiler template "%s.html.twig" for data collector "%s" does not exist.', $template, $name));
         }
         $templates[$name] = $template . '.html.twig';
     }
     return $templates;
 }
 /**
  * @param boolean $secure
  * @dataProvider getSecureInsecure
  */
 public function testOk($secure)
 {
     $listener = new DebugResponseListener(['enabled' => true, 'key_name' => '_debug']);
     $listener->setProfilerListener($this->profileListener);
     $listener->addConverter(new FooConverter());
     $response = new Response(json_encode(['some' => ['data']]), 200, ['Content-Type' => 'application/json', 'X-Debug-Token-Link' => '/token']);
     $request = new Request([], [], [], [], [], ['SERVER_NAME' => 'foobar.test', 'SERVER_PORT' => $secure ? 443 : 80, 'HTTPS' => $secure ? 'on' : 'off']);
     $profile = new Profile('token');
     $profile->addCollector(new TimeDataCollector());
     $profile->setIp('8.8.8.8');
     $profile->setMethod(Request::METHOD_HEAD);
     $profile->setUrl('/some/url');
     $profile->setStatusCode(Response::HTTP_I_AM_A_TEAPOT);
     $profile->setTime(1000000);
     $this->profiles[$request] = $profile;
     $listener->onKernelResponse($this->getEvent($request, $response));
     $debugResponse = json_decode($response->getContent(), true);
     $this->assertEquals(['some' => ['data'], '_debug' => ['tokenUrl' => $secure ? 'https://foobar.test/token' : 'http://foobar.test/token', 'ip' => '8.8.8.8', 'method' => Request::METHOD_HEAD, 'url' => '/some/url', 'time' => date('c', 1000000), 'statusCode' => Response::HTTP_I_AM_A_TEAPOT, 'foo' => 'bar']], $debugResponse);
 }
 public function testStatusCode()
 {
     $profile = new Profile('token1');
     $profile->setStatusCode(200);
     $this->getStorage()->write($profile);
     $profile = new Profile('token2');
     $profile->setStatusCode(404);
     $this->getStorage()->write($profile);
     $tokens = $this->getStorage()->find('', '', 10, '');
     $this->assertCount(2, $tokens);
     $this->assertContains($tokens[0]['status_code'], array(200, 404));
     $this->assertContains($tokens[1]['status_code'], array(200, 404));
 }
 /**
  * @param string $token
  * @param $data
  *
  * @return Profile
  */
 private function createProfileFromData($token, $data)
 {
     $profile = new Profile($token);
     $profile->setIp($data->ip);
     $profile->setMethod($data->method);
     $profile->setUrl($data->url);
     $profile->setTime($data->time);
     $profile->setCollectors(unserialize(base64_decode($data->data)));
     return $profile;
 }
示例#12
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;
 }
 public function testDuplicates()
 {
     for ($i = 1; $i <= 5; $i++) {
         $profile = new Profile('foo' . $i);
         $profile->setIp('127.0.0.1');
         $profile->setUrl('http://example.net/');
         $profile->setMethod('GET');
         ///three duplicates
         $this->getStorage()->write($profile);
         $this->getStorage()->write($profile);
         $this->getStorage()->write($profile);
     }
     $this->assertCount(3, $this->getStorage()->find('127.0.0.1', 'http://example.net/', 3, 'GET'), '->find() method returns incorrect number of entries');
 }
 /**
  * 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);
         }
     }
 }
示例#15
0
 private function createProfileFromData($token, $data, $parent = null)
 {
     $profile = new Profile($token);
     $profile->setIp($data['ip']);
     $profile->setMethod($data['method']);
     $profile->setUrl($data['url']);
     $profile->setTime($data['time']);
     $profile->setCollectors($data['data']);
     if (!$parent && $data['parent']) {
         $parent = $this->read($data['parent']);
     }
     if ($parent) {
         $profile->setParent($parent);
     }
     foreach ($data['children'] as $token) {
         if (!$token) {
             continue;
         }
         if (!($childProfileData = $this->getValue($this->getItemName($token), self::REDIS_SERIALIZER_PHP))) {
             continue;
         }
         $profile->addChild($this->createProfileFromData($token, $childProfileData, $profile));
     }
     return $profile;
 }
 public function testPurge()
 {
     $profile = new Profile('token1');
     $profile->setIp('127.0.0.1');
     $profile->setUrl('http://example.com/');
     $profile->setMethod('GET');
     $this->getStorage()->write($profile);
     $this->assertTrue(false !== $this->getStorage()->read('token1'));
     $this->assertCount(1, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'));
     $profile = new Profile('token2');
     $profile->setIp('127.0.0.1');
     $profile->setUrl('http://example.net/');
     $profile->setMethod('GET');
     $this->getStorage()->write($profile);
     $this->assertTrue(false !== $this->getStorage()->read('token2'));
     $this->assertCount(2, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'));
     $this->getStorage()->purge();
     $this->assertEmpty($this->getStorage()->read('token'), '->purge() removes all data stored by profiler');
     $this->assertCount(0, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'), '->purge() removes all items from index');
 }
示例#17
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;
 }
 /**
  * @param Profile             $profile
  * @param FilterResponseEvent $event
  * @return array
  */
 protected function extractInformation(Profile $profile, FilterResponseEvent $event)
 {
     $debugInformation = ['tokenUrl' => $this->getTokenLink($event), 'ip' => $profile->getIp(), 'method' => $profile->getMethod(), 'url' => $profile->getUrl(), 'time' => date('c', $profile->getTime()), 'statusCode' => $profile->getStatusCode()];
     foreach ($profile->getCollectors() as $collector) {
         $debugInformation = array_merge($debugInformation, $this->convertCollector($collector));
     }
     return $debugInformation;
 }
 public function testRetrieveByUrl()
 {
     $profile = new Profile('simple_quote');
     $profile->setIp('127.0.0.1');
     $profile->setUrl('http://foo.bar/\'');
     self::$storage->write($profile);
     $profile = new Profile('double_quote');
     $profile->setIp('127.0.0.1');
     $profile->setUrl('http://foo.bar/"');
     self::$storage->write($profile);
     $profile = new Profile('backslash');
     $profile->setIp('127.0.0.1');
     $profile->setUrl('http://foo\\bar/');
     self::$storage->write($profile);
     $profile = new Profile('percent');
     $profile->setIp('127.0.0.1');
     $profile->setUrl('http://foo.bar/%');
     self::$storage->write($profile);
     $profile = new Profile('underscore');
     $profile->setIp('127.0.0.1');
     $profile->setUrl('http://foo.bar/_');
     self::$storage->write($profile);
     $this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10)), 1, '->find() accepts single quotes in URLs');
     $this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10)), 1, '->find() accepts double quotes in URLs');
     $this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10)), 1, '->find() accepts backslash in URLs');
     $this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10)), 1, '->find() does not interpret a "%" as a wildcard in the URL');
     $this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10)), 1, '->find() does not interpret a "_" as a wildcard in the URL');
 }
示例#20
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(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;
 }
示例#21
0
 /**
  * Adds the child token.
  *
  * @param Profile $child The child Profile
  */
 public function addChild(Profile $child)
 {
     $this->children[] = $child;
     $child->setParent($this);
 }
 /**
  * @param Response $response
  * @param Profile $profile
  */
 protected function validateGetGamesCore(Response $response, Profile $profile)
 {
     $this->assertGetJsonCors($response);
     /** @var DoctrineDataCollector $doctrineDataCollector */
     $doctrineDataCollector = $profile->getCollector('db');
     // SELECT user1, SELECT game, [... SELECT user (available game)]
     $this->assertGreaterThanOrEqual(2, $doctrineDataCollector->getQueryCount());
 }
 protected function createProfileFromData($token, $data, $parent = null)
 {
     $profile = new Profile($token);
     $profile->setIp($data['ip']);
     $profile->setUrl($data['url']);
     $profile->setTime($data['time']);
     $profile->setCollectors(unserialize(base64_decode($data['data'])));
     if (!$parent && isset($data['parent']) && $data['parent']) {
         $parent = $this->read($data['parent']);
     }
     if ($parent) {
         $profile->setParent($parent);
     }
     $profile->setChildren($this->readChildren($token, $profile));
     return $profile;
 }
 /**
  * Exposes collector's data as JSON.
  *
  * @param \Symfony\Component\HttpKernel\Profiler\Profile $profile
  * @param $collector
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function restCollectorAction(Profile $profile, $collector)
 {
     $this->profiler->disable();
     $data = $profile->getCollector($collector)->getData();
     return new JsonResponse(['data' => $data]);
 }
示例#25
0
 protected function assertHasServiceInDIContainer(Profile $profile, $serviceName, $RequestedService = array("security.context"))
 {
     $logMessages = $profile->getCollector("dependency_injection")->getLogMessages();
     $servicesDI = array();
     if (null !== $logMessages) {
         foreach ($logMessages as $k => $message) {
             if (in_array($message['id'], $RequestedService)) {
                 $servicesDI[] = $message['caller']['method'];
             }
         }
     }
     $this->assertContains($serviceName, implode(array_values($servicesDI)));
 }
 /**
  * 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);
         }
     }
 }
 /**
  * @param Profile $profile
  */
 protected function validateCorsResponseDbCount(Profile $profile)
 {
     /** @var DoctrineDataCollector $doctrineDataCollector */
     $doctrineDataCollector = $profile->getCollector('db');
     $this->assertEquals(0, $doctrineDataCollector->getQueryCount());
 }