/** * Return a timer function that you may invoke to send the * recorded time between calling Metrics::startTimer and calling * its resulting timer. * * The timer function has this signature: * * @code * $timer = function ($stat, $sampleRate = 1) {...}; * @endcode * * Invoke the timer function using a stat name and an optional * sample rate: * * @code * $timer('core.sampleTiming'); * // or ... * $timer('core.sampleTiming', 0.1); * * @endcode * * @return function the timing function */ public static function startTimer() { $start_time = microtime(true); return function ($stat, $sampleRate = 1) use($start_time) { \Metrics::timing($stat, round(1000 * (microtime(true) - $start_time)), $sampleRate); }; }