Hi,
Just had another slow site ;-)
I was wondering if MODx team could modify process function in /core/model/modx/modscript.class.php.
The idea is to create array with snippet call params and run time, and output it with plugin or snippet on the front end during site development. I've tested it (hacking the core) and looks very ok, every snippet run time logged in.
Draft:
public function process($properties= null, $content= null) {
$t = microtime(true);
/* ... original code */
if (_MODX_BENCHMARK_) {
$bench = json_decode($_SESSION['benchmark']);
$b = microtime(true) - $t;
$bench[] = array(
'name' => $this->get('name'),
'props' => $properties,
'time' => $b,
'is_slow' => $b > 0.01 ? true : false
);
$_SESSION['benchmark'] = json_encode($bench); /* $_SESSION used just for testing, I think it would be better to use for e.g setPlaceholder */
}
return $this->_output;
}
and plugin (OnWebPageComplete) to output the data
<?php
if ($modx->context->get('key') == 'mgr') return;
echo '<pre>';
var_dump(json_decode($_SESSION['benchmark']));
echo '</pre>';
die();
(again, above code is my briefly testing ;-) )
I think the output could be done with [[!debug]] snippet at the end of template. This could open popup window similar to the one in Smarty.
I know there is benchmark snippet, but requires modifying every call.
[ed. note: remek555 last edited this post 11 years, 10 months ago.]