. */ 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(array &$versions) { $versions[] = array('name' => 'SQLProfile', 'version' => GNUSOCIAL_VERSION, 'author' => 'Brion Vibber', 'homepage' => 'http://status.net/wiki/Plugin:SQLProfile', 'rawdescription' => // TRANS: Plugin description. _m('Debug tool to watch for poorly indexed DB queries.')); return true; } function onStartDBQuery($obj, $query, &$result) { if (!$this->recursionGuard && preg_match('/\bselect\b/i', $query)) { $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; } }