Skip to content

Instantly share code, notes, and snippets.

@opengeek
Created October 1, 2010 19:09
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save opengeek/606684 to your computer and use it in GitHub Desktop.
Save opengeek/606684 to your computer and use it in GitHub Desktop.
<?php
$output = '';
$tElementClass = !empty($tElementClass) ? $tElementClass : 'modSnippet';
$tStart = $modx->getMicroTime();
if (!empty($tElement)) {
switch ($tElementClass) {
case 'modChunk':
$output = $modx->getChunk($tElement, $scriptProperties);
break;
case 'modSnippet':
$output = $modx->runSnippet($tElement, $scriptProperties);
break;
default:
$tElementObj = $modx->getObject($tElementClass, array('name' => $tElement));
if ($tElementObj && $tElementObj instanceof modElement) {
$tElementObj->setCacheable(false);
$output = $tElementObj->process($scriptProperties);
} else {
$modx->log(modX::LOG_LEVEL_ERROR, "{$tElementClass}: {$tElement} is not a valid MODx Element");
}
break;
}
}
$tEnd = $modx->getMicroTime();
$modx->log(modX::LOG_LEVEL_ERROR, "{$tElementClass}: {$tElement} executed in " . sprintf("%2.4f s", $tEnd - $tStart));
return $output;
?>
@opengeek
Copy link
Author

opengeek commented Oct 1, 2010

An quick MODx Snippet you can use to wrap other Snippets, Chunks, or Template Variables and get log messages indicating how long it took to execute each element. For instance, a getResources call that looks like:

[[!getResources? &parents=`4` &where=`{"template:IN":[1,2,3]}` &sortbyTV=`eventDate` &sortdirTV=`ASC` &sortby=`` &tpl=`getResourcesTpl`]]

would become:

[[!Executioner? &tElement=`getResources` &parents=`4` &where=`{"template:IN":[1,2,3]}` &sortbyTV=`eventDate` &sortdirTV=`ASC` &sortby=`` &tpl=`getResourcesTpl`]]

Then in your error.log you will see messages like:

[2010-10-01 13:06:21] (ERROR @ /revo-master/index.php) modSnippet: getResources executed in 0.0524 s

@zaigham
Copy link

zaigham commented Nov 11, 2010

Jason, how can I use propertyset enabled call with executioner? eg. [[getResources@inTheNews? &parents=[[*id]]]]

@opengeek
Copy link
Author

You simply do:
[[!Executioner@inTheNews? &parents=[[*id]]]]

You will have to attach the Executioner snippet to the Property Set though.

@blueeyeddevil
Copy link

is this snippet still in development? If so, wouldn't be possible to add an option for automatically wrapping all snippets or chunks and displaying execution time for each element at the end of its code on the page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment