public function testNested() { $manager = new Manager(); $a = $manager->namedStart('A'); $b = $manager->namedStart('B'); $this->assertNull($a->getParent()); $this->assertSame($a, $b->getParent()); $this->assertSame($b, $manager->stop()); $c = $manager->namedStart('C'); $this->assertSame($a, $c->getParent()); $d = $manager->namedStart('D'); $this->assertSame($d, $manager->stop()); $this->assertSame($c, $manager->stop()); $this->assertSame($a, $manager->stop()); $e = $manager->namedStart('E'); $this->assertSame($e, $manager->stop()); $this->assertSame($a, $manager->getIterator()->offsetGet(0)); $this->assertSame($b, $a->getIterator()->offsetGet(0)); $this->assertSame($c, $a->getIterator()->offsetGet(1)); $this->assertSame($d, $c->getIterator()->offsetGet(0)); $this->assertSame($e, $manager->getIterator()->offsetGet(1)); $z = $manager->namedStart('Z'); $this->assertSame($z, $manager->discard()); $this->assertSame(2, $manager->getIterator()->count()); }
public function testInFunction() { $this->manager->namedStart('1'); $trace = $this->manager->stop()->refScopeStatistic(BacktraceObserver::class); $this->assertSame('PHProfilingTest\\Example\\BacktraceTest->testInFunction', $trace[BacktraceObserver::FILED_START_POSITION][BacktraceObserver::SUB_FILED_EXPRESSION]); $this->assertEquals($trace[BacktraceObserver::FILED_START_POSITION], $trace[BacktraceObserver::FILED_STOP_POSITION]); $this->manager->namedStart('2'); $this->innerFunction(); }
public function testTiming() { $this->manager->namedStart('test'); usleep(500000); $this->manager->pause(); usleep(750000); $this->manager->resume(); usleep(500000); $item = $this->manager->stop(); $this->assertEquals(1, $item->getStatistic(TimingObserver::class, TimingObserver::FILED_RUNTIME), 'Time is out of tolerance, check delta first.', 0.1); $this->manager->namedStart('test2'); usleep(300000); $this->manager->pause(); usleep(700000); $item = $this->manager->stop(); $this->assertEquals(0.3, $item->getStatistic(TimingObserver::class, TimingObserver::FILED_RUNTIME), 'Time is out of tolerance, check delta first.', 0.1); $this->assertEquals(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], TimingObserver::getGlobalT(), 'Global time is out of tolerance, check delta first.', 0.1); }
public function testTag() { $manager = new Manager(); $tag = new TaggingObserver('SQL'); $this->assertSame('SQL', $tag->getTag()); $manager->getPrototype()->attach($tag); $manager->namedStart('foo'); $item = $manager->stop(); $this->assertSame('foo', $item->getTitle()); $this->assertSame('SQL', $item->getStatistic(TaggingObserver::class, TaggingObserver::FILED_TAG)); }
public function testBasic() { $this->expectOutputRegex('/\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}] test\\.DEBUG: 1 \\{"PHProfiling\\\\\\\\Example\\\\\\\\TaggingObserver":\\{"tag":"EX"\\},"PHProfiling\\\\\\\\Example\\\\\\\\MemoryPeekUseObserver":\\{"usage":\\d+\\}\\} \\[\\]/'); $logger = new Logger('test'); $logger->pushHandler(new StreamHandler('php://output')); $prototype = new Item(); $prototype->attach(new MonologOutput($logger, Logger::DEBUG)); $prototype->attach(new TaggingObserver('EX')); $prototype->attach(new MemoryPeekUseObserver()); $manager = new Manager($prototype); $manager->namedStart('1'); $memoryEater = range(0, 500); $this->assertTrue($manager->stop()->isHandled()); unset($memoryEater); }