@@ -7,6 +7,10 @@ The Stopwatch Component
7
7
8
8
Stopwatch component provides a way to profile code.
9
9
10
+ .. versionadded :: 2.2
11
+ The Stopwatch Component is new to Symfony 2.2. Previously, the ``Stopwatch ``
12
+ class was located in the ``HttpKernel `` component.
13
+
10
14
Installation
11
15
------------
12
16
19
23
-----
20
24
21
25
The Stopwatch component provides an easy and consistent way to measure execution
22
- time of certain parts of code, so that you don't constantly have to parse
23
- microtime by yourself. The basic usage is as simple as this::
26
+ time of certain parts of code so that you don't constantly have to parse
27
+ microtime by yourself. Instead, use the simple
28
+ :class: `Symfony\\ Component\\ Stopwatch\\ Stopwatch ` class::
24
29
25
30
use Symfony\Component\Stopwatch\Stopwatch;
26
31
@@ -35,14 +40,15 @@ You also can provide a category name to an event::
35
40
$stopwatch->start('eventName', 'categoryName');
36
41
37
42
You can consider categories as a way of tagging events. The Symfony Profiler
38
- tool uses categories to nicely colorcode different events.
43
+ tool, for example, uses categories to nicely color-code different events.
39
44
40
45
Periods
41
46
-------
42
47
43
- As we all know from the real world, all stopwatches come with two buttons.
48
+ As you know from the real world, all stopwatches come with two buttons.
44
49
One for starting and stopping the stopwatch, another to measure the lap time.
45
- And that's exactly what lap method does. ::
50
+ This is exactly what the :method: `Symfony\\ Component\\ Stopwatch\\ Stopwatch::lap` `
51
+ method does::
46
52
47
53
$stopwatch = new Stopwatch();
48
54
// Start event named 'foo'
@@ -54,39 +60,39 @@ And that's exactly what lap method does. ::
54
60
// some other code goes here
55
61
$event = $stopwatch->stop('foo');
56
62
57
- Lap information is stored in periods within the event. To get lap information aka periods call ::
63
+ Lap information is stored in periods within the event. To get lap information
64
+ (aka periods) call::
58
65
59
66
$event->getPeriods();
60
67
61
- Besides getting periods, we can get other useful information from the event object. E.g::
68
+ Besides getting periods, you can get other useful information from the event object.
69
+ For example::
62
70
63
71
$event->getCategory(); // Returns the category the evenent was started in
64
72
$event->getOrigin(); // Returns the start time of the Event in milliseconds
65
- $event->ensureStopped(); // Stops all non already stopped periods
73
+ $event->ensureStopped(); // Stops all not- already- stopped periods
66
74
$event->getStartTime(); // Returns the start of the very first period
67
75
$event->getEndTime(); // Returns the end time of the very last period
68
76
$event->getDuration(); // Gets the duration (including all periods) of the event
69
77
$event->getMemory(); // Gets the max memory usage of all periods
70
78
71
-
72
79
Sections
73
80
--------
74
81
75
82
Sections are a way to logically split the timeline into groups. You can see
76
83
how Symfony uses sections to nicely visualize framework lifecycle in the
77
- Symfony Profiler tool. Here is a basic usage of sections. ::
84
+ Symfony Profiler tool. Here is a basic usage of sections::
78
85
79
86
$stopwatch = new Stopwatch();
80
87
81
88
$stopwatch->openSection();
82
- $stopwatch->start('parisng_config_file ', 'filesystem_operations');
89
+ $stopwatch->start('parsing_config_file ', 'filesystem_operations');
83
90
$stopwatch->stopSection('routing');
84
91
85
- $events = $stopwatch->getSectionEvents('section');
86
-
92
+ $events = $stopwatch->getSectionEvents('routing');
87
93
88
94
You can reopen a closed section by calling the openSection method and specifying
89
- an id of the section to be reopened. e.g. ::
95
+ an id of the section to be reopened::
90
96
91
97
$stopwatch->openSection('routing');
92
98
$stopwatch->start('building_config_tree');
0 commit comments