Skip to content

Instantly share code, notes, and snippets.

@Luxato
Last active August 20, 2021 11:39
Show Gist options
  • Save Luxato/f723a195161c6fc7d82a36704e0740c2 to your computer and use it in GitHub Desktop.
Save Luxato/f723a195161c6fc7d82a36704e0740c2 to your computer and use it in GitHub Desktop.
Magento 1 get profiler ordered by elapsed time
<?php
/*
* Don't forget that in order for profiler to work it has to be enabled, else you will get empty profiles.
*/
$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')->getProfiler();
$queryProfiles = $profiler->getQueryProfiles();
$profiles = [];
foreach ($queryProfiles as $profile) {
$tmp = (array) $profile;
$tmp['total'] = number_format($profile->getElapsedSecs(), 5);
$profiles[] = $tmp;
}
$total = array_column($profiles, 'total');
array_multisort($total, SORT_DESC, $profiles);
echo '<pre>';
print_r( $profiles );
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment