protected function benchmarkQuery($sql, $callback, $parameters = array())
    {
        if (isset($_REQUEST['showqueries']) && Director::isDev()) {
            $this->queryCount++;
            $starttime = microtime(true);
            $result = $callback($sql);
            $endtime = round(microtime(true) - $starttime, 4);
            // replace parameters as closely as possible to what we'd expect the DB to put in
            if (in_array(strtolower($_REQUEST['showqueries']), ['inline', 'backtrace'])) {
                $sql = DB::inline_parameters($sql, $parameters);
            }
            $queryCount = sprintf("%04d", $this->queryCount);
            Debug::message("\n$queryCount: $sql\n{$endtime}s\n", false);

            // Show a backtrace if ?showqueries=backtrace
            if ($_REQUEST['showqueries'] === 'backtrace') {
                Backtrace::backtrace();
            }
            return $result;
        } else {
            return $callback($sql);
        }
    }