8000 Reset profiler. · symfony/symfony@cacbb30 · GitHub
[go: up one dir, main page]

Skip to content

Commit cacbb30

Browse files
committed
Reset profiler.
1 parent bd3bc69 commit cacbb30

File tree

45 files changed

+456
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+456
-40
lines changed

UPGRADE-3.4.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Debug
6363

6464
* Support for stacked errors in the `ErrorHandler` is deprecated and will be removed in Symfony 4.0.
6565

66+
EventDispatcher
67+
---------------
68+
69+
* Implementing `TraceableEventDispatcherInterface` without the method
70+
`clearCalledListeners()` is deprecated and will be unsupported in 4.0.
71+
6672
Filesystem
6773
----------
6874

@@ -259,6 +265,10 @@ HttpKernel
259265
Use the `%kernel.cache_dir%` parameter instead. Not doing so may break the `cache:clear` command.
260266

261267
* The `Symfony\Component\HttpKernel\Config\EnvParametersResource` class has been deprecated and will be removed in 4.0.
268+
269+
* Implementing `DataCollectorInterface` without a `reset()` method has been deprecated and will be unsupported in 4.0.
270+
271+
* Implementing `DebugLoggerInterface` without a `clear()` method has been deprecated and will be unsupported in 4.0.
262272

263273
Process
264274
-------

UPGRADE-4.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ EventDispatcher
191191

192192
* The `ContainerAwareEventDispatcher` class has been removed.
193193
Use `EventDispatcher` with closure factories instead.
194+
195+
* The `clearCalledListeners()` method has been added to `TraceableEventDispatcherInterface`.
194196

195197
ExpressionLanguage
196198
------------------
@@ -602,6 +604,10 @@ HttpKernel
602604
Use the `%kernel.cache_dir%` parameter instead. Not doing so may break the `cache:clear` command.
603605

604606
* The `Symfony\Component\HttpKernel\Config\EnvParametersResource` class has been removed.
607+
608+
* The `reset()` method has been added to `Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface`.
609+
610+
* The `clear()` method has been added to `Symfony\Component\HttpKernel\Log\DebugLoggerInterface`.
605611

606612
Ldap
607613
----

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"ext-xml": "*",
2121
"doctrine/common": "~2.4",
2222
"fig/link-util": "^1.0",
23-
"twig/twig": "~1.34|~2.4",
23+
"twig/twig": "^1.35|^2.4.4",
2424
"psr/cache": "~1.0",
2525
"psr/container": "^1.0",
2626
"psr/link": "^1.0",

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class DoctrineDataCollector extends DataCollector
2828
private $registry;
2929
private $connections;
3030
private $managers;
31+
32+
/**
33+
* @var DebugStack[]
34+
*/
3135
private $loggers = array();
3236

3337
public function __construct(ManagerRegistry $registry)
@@ -65,6 +69,16 @@ public function collect(Request $request, Response $response, \Exception $except
6569
);
6670
}
6771

72+
public function reset()
73+
{
74+
$this->data = array();
75+
76+
foreach ($this->loggers as $logger) {
77+
$logger->queries = array();
78+
$logger->currentQuery = 0;
79+
}
80+
}
81+
6882
public function getManagers()
6983
{
7084
return $this->data['managers'];

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ public function testCollectQueryWithNoParams()
101101
$this->assertTrue($collectedQueries['default'][1]['explainable']);
102102
}
103103

104+
public function testReset()
105+
{
106+
$queries = array(
107+
array('sql' => 'SELECT * FROM table1', 'params' => array(), 'types' => array(), 'executionMS' => 1),
108+
);
109+
$c = $this->createCollector($queries);
110+
$c->collect(new Request(), new Response());
111+
112+
$c->reset();
113+
$c->collect(new Request(), new Response());
114+
115+
$this->assertEquals(array('default' => array()), $c->getQueries());
116+
}
117+
104118
/**
105119
* @dataProvider paramProvider
106120
*/

src/Symfony/Bridge/Monolog/Logger.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ public function countErrors()
4545
return 0;
4646
}
4747

48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public function clear()
52+
{
53+
if (($logger = $this->getDebugLogger()) && method_exists($logger, 'clear')) {
54+
$logger->clear();
55+
}
56+
}
57+
4858
/**
4959
* Returns a DebugLoggerInterface instance if one is registered with this logger.
5060
*

src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ public function countErrors()
5555
{
5656
return $this->errorCount;
5757
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
public function clear()
63+
{
64+
$this->records = array();
65+
$this->errorCount = 0;
66+
}
5867
}

src/Symfony/Bridge/Monolog/Tests/LoggerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,17 @@ public function testGetLogsWithDebugProcessor2()
128128
$this->assertEquals('test', $record['message']);
129129
$this->assertEquals(Logger::INFO, $record['priority']);
130130
}
131+
132+
public function testClear()
133+
{
134+
$handler = new TestHandler();
135+
$logger = new Logger('test', array($handler));
136+
$logger->pushProcessor(new DebugProcessor());
137+
138+
$logger->addInfo('test');
139+
$logger->clear();
140+
141+
$this->assertEmpty($logger->getLogs());
142+
$this->assertSame(0, $logger->countErrors());
143+
}
131144
}

src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public function collect(Request $request, Response $response, \Exception $except
4444
{
4545
}
4646

47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function reset()
51+
{
52+
$this->profile->reset();
53+
$this->computed = null;
54+
$this->data = array();
55+
}
56+
4757
/**
4858
* {@inheritdoc}
4959
*/

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^5.5.9|>=7.0.8",
20-
"twig/twig": "~1.34|~2.4"
20+
"twig/twig": "^1.35|^2.4.4"
2121
},
2222
"require-dev": {
2323
"fig/link-util": "^1.0",

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,13 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
608608
}
609609
}
610610

611-
if (!$config['collect']) {
612-
$container->getDefinition('profiler')->addMethodCall('disable', array());
611+
$profilerDefinition = $container->getDefinition('profiler');
612+
$profilerDefinition->addTag('kernel.reset', array('method' => 'reset'));
613+
if ($config['collect']) {
614+
$profilerDefinition->addTag('kernel.reset', array('method' => 'enable'));
615+
} else {
616+
$profilerDefinition->addMethodCall('disable');
617+
$profilerDefinition->addTag('kernel.reset', array('method' => 'disable'));
613618
}
614619
}
615620

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ public function collect(Request $request, Response $response, \Exception $except
207207
}
208208
}
209209

210+
/**
211+
* {@inheritdoc}
212+
*/
213+
public function reset()
214+
{
215+
$this->data = array();
216+
}
217+
210218
public function lateCollect()
211219
{
212220
$this->data = $this->cloneVar($this->data);

src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public function collect(Request $request, Response $response, \Exception $except
5353
$this->data['total']['statistics'] = $this->calculateTotalStatistics();
5454
}
5555

56+
public function reset()
57+
{
58+
$this->data = array();
59+
foreach ($this->instances as $instance) {
60+
// Calling getCalls() will clear the calls.
61+
$instance->getCalls();
62+
}
63+
}
64+
5665
public function lateCollect()
5766
{
5867
$this->data = $this->cloneVar($this->data);

src/Symfony/Component/EventDispatcher/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
3.4.0
5+
-----
6+
7+
* Implementing `TraceableEventDispatcherInterface` without the method
8+
`clearCalledListeners()` has been deprecated.
9+
410
3.3.0
511
-----
612

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ public function getNotCalledListeners()
214214
return $notCalled;
215215
}
216216

217+
public function reset()
218+
{
219+
$this->called = array();
220+
}
221+
217222
/**
218223
* Proxies all method calls to the original event dispatcher.
219224
*

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcherInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* @author Fabien Potencier <fabien@symfony.com>
18+
*
19+
* @method reset() Resets the trace.
1820
*/
1921
interface TraceableEventDispatcherInterface extends EventDispatcherInterface
2022
{

src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ public function testGetCalledListeners()
124124
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
125125
}
126126

127+
public function testClearCalledListeners()
128+
{
129+
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
130+
$tdispatcher->addListener('foo', function () {}, 5);
131+
132+
$tdispatcher->dispatch('foo');
133+
$tdispatcher->reset();
134+
135+
$listeners = $tdispatcher->getNotCalledListeners();
136+
$this->assertArrayHasKey('stub', $listeners['foo.closure']);
137+
unset($listeners['foo.closure']['stub']);
138+
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
139+
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
140+
}
141+
127142
public function testGetCalledListenersNested()
128143
{
129144
$tdispatcher = null;

src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,9 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
7272
public function __construct(FormDataExtractorInterface $dataExtractor)
7373
{
7474
$this->dataExtractor = $dataExtractor;
75-
$this->data = array(
76-
'forms' => array(),
77-
'forms_by_hash' => array(),
78-
'nb_errors' => 0,
79-
);
8075
$this->hasVarDumper = class_exists(ClassStub::class);
76+
77+
$this->reset();
8178
}
8279

8380
/**
@@ -87,6 +84,15 @@ public function collect(Request $request, Response $response, \Exception $except
8784
{
8885
}
8986

87+
public function reset()
88+
{
89+
$this->data = array(
90+
'forms' => array(),
91+
'forms_by_hash' => array(),
92+
'nb_errors' => 0,
93+
);
94+
}
95+
9096
/**
9197
* {@inheritdoc}
9298
*/

src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,36 @@ public function testCollectSubmittedDataExpandedFormsErrors()
695695
$this->assertFalse(isset($child21Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
696696
}
697697

698+
public function testReset()
699+
{
700+
$form = $this->createForm('my_form');
701+
702+
$this->dataExtractor->expects($this->any())
703+
->method('extractConfiguration')
704+
->will($this->returnValue(array()));
705+
$this->dataExtractor->expects($this->any())
706+
->method('extractDefaultData')
707+
->will($this->returnValue(array()));
708+
$this->dataExtractor->expects($this->any())
709+
->method('extractSubmittedData')
710+
->with($form)
711+
->will($this->returnValue(array('errors' => array('baz'))));
712+
713+
$this->dataCollector->buildPreliminaryFormTree($form);
714+
$this->dataCollector->collectSubmittedData($form);
715+
716+
$this->dataCollector->reset();
717+
718+
$this->assertSame(
719+
array(
720+
'forms' => array(),
721+
'forms_by_hash' => array(),
722+
'nb_errors' => 0,
723+
),
724+
$this->dataCollector->getData()
725+
);
726+
}
727+
698728
private function createForm($name)
699729
{
700730
$builder = new FormBuilder($name, null, $this->dispatcher, $this->factory);

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ CHANGELOG
1212
* added `AddCacheWarmerPass`
1313
* deprecated `EnvParametersResource`
1414
* added `Symfony\Component\HttpKernel\Client::catchExceptions()`
15+
* added the possibility to reset the profiler to its initial state
16+
* deprecated data collectors without a reset method
17+
* deprecated implementing `DebugLoggerInterface` without a `clear()` method
1518

1619
3.3.0
1720
-----

src/Symfony/Component/HttpKernel/DataCollector/AjaxDataCollector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function collect(Request $request, Response $response, \Exception $except
2626
// all collecting is done client side
2727
}
2828

29+
public function reset()
30+
{
31+
// all collecting is done client side
32+
}
33+
2934
public function getName()
3035
{
3136
return 'ajax';

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public function collect(Request $request, Response $response, \Exception $except
9999
}
100100
}
101101

102+
/**
103+
* {@inheritdoc}
104+
*/
105+
public function reset()
106+
{
107+
$this->data = array();
108+
}
109+
102110
public function lateCollect()
103111
{
104112
$this->data = $this->cloneVar($this->data);

src/Symfony/Component/HttpKernel/DataCollector/DataCollectorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* DataCollectorInterface.
1919
*
2020
* @author Fabien Potencier <fabien@symfony.com>
21+
*
22+
* @method reset() Resets this data collector to its initial state.
2123
*/
2224
interface DataCollectorInterface
2325
{

0 commit comments

Comments
 (0)
0