Skip to content

Commit b79e348

Browse files
committed
Added docs for JProfiler class.
1 parent 29e019b commit b79e348

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## The Profiler Package
2+
3+
The Joomla Platform provides you a simple utility class called `JProfiler` to profile the time that it takes to do certain tasks or reach various milestones as your extension runs.
4+
5+
To use the profiler we create an instance. There is a global instance of the profiler that can be used anywhere.
6+
7+
```php
8+
$profiler = JProfiler::getInstance();
9+
```
10+
11+
Note that if you use this, it could already have been used by the application or its sub-elements. You can create a local instance for testing an individual plugin, component or module by passing a label to the method like this:
12+
13+
```php
14+
$profiler = JProfiler::getInstance('Notes');
15+
```
16+
17+
The profiler class will record the time that it was created. To mark milestones in the execution in your code, you can use the mark method, passing it a label to describe where it happened.
18+
19+
```php
20+
$profiler = JProfiler::getInstance('Notes');
21+
22+
$profiler->mark('Start');
23+
24+
// Execute some code
25+
26+
$profiler->mark('Finish');
27+
```
28+
29+
You can mark any number of times but it is always a good idea to mark the start and the finish even if you have intermediate steps.
30+
31+
When you have finished, you can output the results using the `getBuffer` method. This returns an array of the marks you have made.
32+
33+
```php
34+
// Execute previous code
35+
$profiler->mark('Finish');
36+
$buffer = $profile->getBuffer();
37+
echo implode('<br />', $buffer);
38+
```
39+
40+
The output could look something like the following:
41+
42+
```
43+
Notes 0.015 seconds (+0.015); 0.96 MB (+0.960) - Start
44+
Notes 1.813 seconds (+1.798); 6.24 MB (+5.280) - Finished
45+
```
46+
47+
You can see each line is qualified by the label you used when you created the profiler object, and then the label you used for the mark. Following that is the time difference from when the profiler object was created down to the millisecond level. Lastly is the amount of memory that is being usage by PHP.

manual/en-US/menu.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [JKeychain](chapters/packages/keychain.md)
1010
- [JLog](chapters/packages/log.md)
1111
- [MVC](chapters/packages/mvc.md)
12+
- [JProfiler](chapters/packages/profiler.md)
1213
- [Testing](chapters/testing.md)
1314

1415
- Coding Standards

0 commit comments

Comments
 (0)