Example #1
0
 /**
  * A convenience function for logging a debug event.
  *
  * @param mixed $message the message to log.
  */
 public function debug($message)
 {
     $add = true;
     if (null !== $this->stopwatch) {
         $trace = debug_backtrace();
         $method = $trace[2]['args'][2];
         $watch = 'Propel Query ' . (count($this->queries) + 1);
         if ('PropelPDO::prepare' === $method) {
             $this->isPrepared = true;
             $this->stopwatch->start($watch, 'propel');
             $add = false;
         } elseif ($this->isPrepared) {
             $this->isPrepared = false;
             $this->stopwatch->stop($watch);
         }
     }
     if ($add) {
         $this->queries[] = $message;
         if (null !== $this->logger) {
             $this->logger->debug($message);
         }
     }
 }
Example #2
0
    public function testSection()
    {
        $stopwatch = new Stopwatch();

        $stopwatch->startSection();
        $stopwatch->start('foo', 'cat');
        $stopwatch->stop('foo');
        $stopwatch->start('bar', 'cat');
        $stopwatch->stop('bar');
        $stopwatch->stopSection(1);

        $stopwatch->startSection();
        $stopwatch->start('foobar', 'cat');
        $stopwatch->stop('foobar');
        $stopwatch->stopSection(2);

        // the section is an event by itself
        $this->assertEquals(3, count($stopwatch->getSectionEvents(1)));
        $this->assertEquals(2, count($stopwatch->getSectionEvents(2)));
    }
    public function testStopwatchSections()
    {
        $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch = new Stopwatch());
        $kernel = $this->getHttpKernel($dispatcher, function () { return new Response(); });
        $request = Request::create('/');
        $response = $kernel->handle($request);
        $kernel->terminate($request, $response);

        $events = $stopwatch->getSectionEvents($response->headers->get('X-Debug-Token'));
        $this->assertEquals(array(
            '__section__',
            'kernel.request',
            'kernel.request.loading',
            'kernel.controller',
            'kernel.controller.loading',
            'controller',
            'kernel.response',
            'kernel.response.loading',
            'kernel.terminate',
            'kernel.terminate.loading',
        ), array_keys($events));
    }
Example #4
0
 /**
  * @expectedException \LogicException
  */
 public function testReopenANewSectionShouldThrowAnException()
 {
     $stopwatch = new Stopwatch();
     $stopwatch->openSection('section');
 }
Example #5
0
 public function testSection()
 {
     $stopwatch = new Stopwatch();
     $stopwatch->startSection();
     $stopwatch->start('foo', 'cat');
     $stopwatch->stop('foo');
     $stopwatch->start('bar', 'cat');
     $stopwatch->stop('bar');
     $stopwatch->stopSection('1');
     $stopwatch->startSection();
     $stopwatch->start('foobar', 'cat');
     $stopwatch->stop('foobar');
     $stopwatch->stopSection('2');
     $stopwatch->startSection();
     $stopwatch->start('foobar', 'cat');
     $stopwatch->stop('foobar');
     $stopwatch->stopSection('0');
     // the section is an event by itself
     $this->assertCount(3, $stopwatch->getSectionEvents('1'));
     $this->assertCount(2, $stopwatch->getSectionEvents('2'));
     $this->assertCount(2, $stopwatch->getSectionEvents('0'));
 }