Profiling and DB Profiling with DooPHP


If you have read the previous tutorial on logging you will find that profiling with DooPHP framework is relatively similar to the way you log messages.

Performance profiling can be used to measure the time & memory needed for the specified code blocks and find out what the performance bottleneck is. Instead of calling log() you change it to beginProfile() and endProfile(). We need to mark the beginning and the end of each code block by inserting the following methods:

1.
Doo::logger()->beginProfile(‘block_id_here’);
2.
//…everything here will be profiled
3.
Doo::logger()->endProfile(‘block_id_here’);
Code blocks need to be nested properly. A code block cannot intersect with another. It must be either at a parallel level or be completely enclosed by the other code block.

All of the profiled results can be organized in category, simply pass in another parameter at the end of the method beginProfile():

1.
//default category is ‘application’
2.
Doo::logger()->beginProfile(‘id’, ‘editpost’);
3.
//…everything here will be profiled
4.
Doo::logger()->endProfile(‘id’);
To retrieve the profiled results, you called getProfileResult(). You have to pass in the block ID as parameter and you will get an associative array which shows you the time and memory used when processing the code block.

1.
Doo::logger()->beginProfile(‘block_id’);
2.
//…everything here will be profiled
3.
Doo::logger()->endProfile(‘block_id’);
4.
$result = Doo::logger()->getProfileResult(‘block_id’);
To view the profiled results, you just have to call showLogs(). By default it will return a neatly

Previous PostNextNext Post

Leave a Reply

Your email address will not be published.