Particletree.com Php Quick Profiler Wrapper
Its a Web Log Router that will help you profile your application, its database profiling feature allows you to quickly find duplicated queries, see which queries are taking too long, the memory tab allows you to find memory leaks, and it also looks beautiful!
Requirements ¶
Developed using Yii Framework 1.1.8 but it may work with other versions.
Usage ¶
- Download and extract the contents of the zip to your extensions folder
- Configure the LogRoute in your application configuration
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
array(
'class' => 'application.extensions.pqp.PQPLogRoute',
'categories' => 'application.*, exception.*',
),
),
),
Note: if you plan to use phpunit and for some reason you are using a config file that includes PQP you'll get errors about assets folder, to solve this you can set up you log route in the following way as suggested by thefsb
'log'=>array(
'class'=>'CLogRouter',
'routes' => array_merge(
array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning, info',
),
),
array(php_sapi_name() !== 'cli'
? array(
'class' => 'application.extensions.pqp.PQPLogRoute',
'categories' => 'application.*, exception.*, system.*',
'levels'=>'error, warning, info',
)
: array('class'=>'CWebLogRoute', 'enabled'=>false)
)
),
),
- Enable Database Profiling and param loggin:
'db'=>array(
'connectionString' => '...',
'enableProfiling' => true,
'enableParamLogging' => true,
),
- Log as you normaly would with Yii using Yii::trace, Yii::log, Yii::beginProfile and Yii::endProfile, use PQPLogRoute::logMemory to log memory, you can use it to log objects to know its memory consumption, if you pass a string it will tell you know much memory has been used to that point.
/**
* Logs a memory message.
* @param mixed $obj any type of variable to profile memory
* @param string $msg message to be logged
* @param string $category category of the message (e.g. 'system.web'). It is case-insensitive.
*/
public static function logMemory($obj, $msg = '', $category='application'){
PQPLogRoute::logMemory("memory used after action call");
try {
Yii::beginProfile('Execution time');
Yii::log('Begin logging data');
PQPLogRoute::logMemory($this, "the site controller");
$arr = array('Name' => 'Ryan', 'Last' => 'Campbell');
Yii::log(CVarDumper::dumpAsString($arr));
PQPLogRoute::logMemory($arr, "Normal array");
$users = User::model()->findAll();
PQPLogRoute::logMemory($users, "Users array");
Yii::endProfile('Execution time');
throw new Exception('Unable to write to log!');
}
catch(Exception $e) {
Yii::log($e, CLogger::LEVEL_ERROR);
}
PQPLogRoute::logMemory("memory used before render");
Resources ¶
- Project page
- Demo: in the downloads
- Forum Post your questions there, avoid posting questions in the extension page.
- Screenshots :
what url to see the log as in screenshots ?
Hi
sounds interesting
but what's the url to see the log as in screenshots ?
great extension ! looks nice
thanks for sharing , the class is worth reading , good skills
@oceatoon
Hi,
Its a Web log route, meaning it will show up in every page, if you are not seeing anything, try to log something, or add system.* to your categories.
Lovely. Works like a charm
This is a nice improvement over the built in profiling and web logger.
And it looks impressive too.
super
reading yii log has never been that easy !!! thanks for this great extension ....
unfortunately
It really is a nice piece of software but unfortunately i can't seem to get it to work properly, i've even copied it from the svn on google code and it still doesn't show anything...
@webscriptz
Please check this post
Please try to keep your questions in the forum.
the screenshots are on this page
@oceatoon the screenshots are right above these comments
Idea
IT's great now that i got it to work correctly!
Maybe we could adapt it to be the default profiler and log utility for the whole application.
Enable/Disable Extension Automatically
Thanks for providing a very useful extension.
Is there any easy way to enable the extension only on 127.0.0.1(localhost) and disable automatically if it is not on localhost.
About Persistence Logging
Is there any way to keep log history on each refresh?
Suppose we have a submit form and when we submit the form it sends the values a action file and page is suddenly redirected to success page. So your logging system logs of success page but not of the action page.
If we want to show the form value in log while processing the action before redirecting the success page then how we can do this?
We can achieve this in file logging because all logged data are appended every time logger is called.
If you implement the history system then your extension will be best among all.
thanks for providing a great extension.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.