. */ if (!defined('STATUSNET')) { exit(1); } /** * Check DB queries for filesorts and such and log em. * * @package SQLProfilePlugin * @maintainer Brion Vibber */ class SQLProfilePlugin extends Plugin { private $recursionGuard = false; function onPluginVersion(&$versions) { $versions[] = array('name' => 'SQLProfile', 'version' => STATUSNET_VERSION, 'author' => 'Brion Vibber', 'homepage' => 'http://status.net/wiki/Plugin:SQLProfile', 'rawdescription' => _m('Debug tool to watch for poorly indexed DB queries')); return true; } function onStartDBQuery($obj, $query, &$result) { if (!$this->recursionGuard) { $this->recursionGuard = true; $xobj = clone($obj); $explain = $xobj->query('EXPLAIN ' . $query); $this->recursionGuard = false; while ($xobj->fetch()) { $extra = $xobj->Extra; $evil = (strpos($extra, 'Using filesort') !== false) || (strpos($extra, 'Using temporary') !== false); if ($evil) { $xquery = $xobj->sanitizeQuery($query); common_log(LOG_DEBUG, "$extra | $xquery"); } } } return true; } }