JProfiler: Difference between revisions
From Joomla! Documentation
No edit summary |
m clean up |
||
| Line 1: | Line 1: | ||
[[JProfiler]] is a class for performance analysis of your code. It allows to trace: | |||
* execution time of a particular code part; | |||
* memory amount used by your script at a specific program point. | |||
A JProfiler object allows you to make performance marks at specified parts of your script. It stores this marks in a buffer and provides operations for accessing it. | |||
Mark is a string with the following structure: | |||
<pre> | |||
Application Start: 0.000 seconds, 0.10 MB | |||
\_________/ \___/ \___________/ \_____/ | |||
| | | | | |||
prefix label time memory | |||
</pre> | |||
Where: | |||
*prefix -- serves as an identifier for distinct JProfiler objects (see below); | |||
*label -- the name of a performance mark; | |||
*time -- time from a JProfiler object creation to a mark setting; | |||
*memory -- memory allocated to your script in a moment when a performance mark is setting. | |||
The JProfiler class provides getInstance method that we can call statically. It serves for organisation of a global access point for distinct JProfiler objects. It stores an array of created objects and gives access to them on the grounds of a prefix which can be provided as an argument. Also, if an object with demanded prefix is absent, then getInstance method will create it. | |||
===Defined in=== | ===Defined in=== | ||
| Line 34: | Line 51: | ||
<source lang="php">jimport( 'joomla.error.profiler' );</source> | <source lang="php">jimport( 'joomla.error.profiler' );</source> | ||
{{subst:SeeAlso:JProfiler}} | |||
{{SeeAlso:JProfiler}} | |||
===Examples=== | ===Examples=== | ||
Revision as of 13:24, 24 March 2017
JProfiler is a class for performance analysis of your code. It allows to trace:
- execution time of a particular code part;
- memory amount used by your script at a specific program point.
A JProfiler object allows you to make performance marks at specified parts of your script. It stores this marks in a buffer and provides operations for accessing it. Mark is a string with the following structure:
Application Start: 0.000 seconds, 0.10 MB
\_________/ \___/ \___________/ \_____/
| | | |
prefix label time memory
Where:
- prefix -- serves as an identifier for distinct JProfiler objects (see below);
- label -- the name of a performance mark;
- time -- time from a JProfiler object creation to a mark setting;
- memory -- memory allocated to your script in a moment when a performance mark is setting.
The JProfiler class provides getInstance method that we can call statically. It serves for organisation of a global access point for distinct JProfiler objects. It stores an array of created objects and gives access to them on the grounds of a prefix which can be provided as an argument. Also, if an object with demanded prefix is absent, then getInstance method will create it.
Defined in
libraries/joomla/error/profiler.php
Methods
| Method name | Description |
|---|---|
| __construct | Constructor |
| getInstance | Returns a reference to the global Profiler object, only creating it if it doesn't already exist. |
| mark | Output a time mark |
| getmicrotime | Get the current time. |
| getMemory | Get information about current memory usage. |
| getBuffer | Get all profiler marks. |
Importing
jimport( 'joomla.error.profiler' );
{{subst:SeeAlso:JProfiler}}
Examples
<CodeExamplesForm />
Example
JProfiler is a class for performance analysis of your code. It allows to trace:
- execution time of a particular code part;
- memory amount used by your script at a specific program point.
A JProfiler object allows you to make performance marks at specified parts of your script. It stores this marks in a buffer and provides operations for accessing it. Mark is a string with the following structure:
Application Start: 0.000 seconds, 0.10 MB
\_________/ \___/ \___________/ \_____/
| | | |
prefix label time memory
Where:
- prefix -- serves as an identifier for distinct JProfiler objects (see below);
- label -- the name of a performance mark;
- time -- time from a JProfiler object creation to a mark setting;
- memory -- memory allocated to your script in a moment when a performance mark is setting.
The JProfiler class provides getInstance method that we can call statically. It serves for organisation of a global access point for distinct JProfiler objects. It stores an array of created objects and gives access to them on the grounds of a prefix which can be provided as an argument. Also, if an object with demanded prefix is absent, then getInstance method will create it.
Defined in
libraries/joomla/error/profiler.php
Methods
| Method name | Description |
|---|---|
| __construct | Constructor |
| mark | Output a time mark |
| getMemory | Get information about current memory usage. |
| getBuffer | Get all profiler marks. |
| getInstance | Returns the global Profiler object, only creating it if it doesn't already exist. |
| getmicrotime | Get the current time. |
Importing
jimport( 'joomla.error.profiler' );
Examples
Code Examples
Example
$p = JProfiler::getInstance('Application');
$p->mark('Start');
$a = str_repeat("hello world!\n", 100000);
$p->mark('Middle');
unset($a);
$p->mark('Stop');
print_r($p->getBuffer());
would output
Array
(
[0] => Application Start: 0.000 seconds, 0.10 MB
[1] => Application Middle: 0.005 seconds, 1.34 MB
[2] => Application Stop: 0.005 seconds, 0.10 MB
)
This example was originally contributed by User:Artyom.
would output
Array ( [0] => Application Start: 0.000 seconds, 0.10 MB [1] => Application Middle: 0.005 seconds, 1.34 MB [2] => Application Stop: 0.005 seconds, 0.10 MB )This example was originally contributed by User:Artyom.