Ends the timing for a key and sends it to StatsD

@param string $key
@param int|float $sampleRate the rate (0-1) for sampling.
@return float|null
516085
public function endTiming($key, $sampleRate = 1)
    {
        $end = gettimeofday(true);
        if (isset($this->timings[$key])) {
            $timing = ($end - $this->timings[$key]) * 1000;
            $this->timing($key, $timing, $sampleRate);
            unset($this->timings[$key]);
            return $timing;
        }
        return null;
    }
908975
protected function send($data, $sampleRate=1) {
        $sampledData = array();
        if ($sampleRate < 1) {
            foreach ($data as $stat => $value) {
                if ((mt_rand() / mt_getrandmax()) <= $sampleRate) {
                    $sampledData[$stat] = "$value|@$sampleRate";
                }
            }
        } else {
            $sampledData = $data;
        }
        if (empty($sampledData)) { return; }
        try
        {
            if (!empty($this->host)) // if host is configured, send..
            {
                $fp = fsockopen("udp://{$this->host}", $this->port);
                if (! $fp) { return; }
                // make this a non blocking stream
                stream_set_blocking($fp, false);
                foreach ($sampledData as $stat => $value)
                {
                    if (is_array($value))
                    {
                        foreach ($value as $v)
                        {
                            fwrite($fp, "$stat:$v");
                        }
                    }
                    else
                    {
                        fwrite($fp, "$stat:$value");
                    }
                }
                fclose($fp);
            }
        }
        catch (\Exception $e)
        {
        }
    }
783729
public function rand($key)
    {
        $connection = $this->getConnection($key);
        $this->writeToRemote(array(
            'cmd' => 'rand',
            'key' => $key,
        ), $connection);
        return $this->readFromRemote($connection);
    }
1119211
protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {

        $noteachersindicator = $this->retrieve('\core_course\analytics\indicator\no_teacher', $sampleid);
        $nostudentsindicator = $this->retrieve('\core_course\analytics\indicator\no_student', $sampleid);
        if ($noteachersindicator == \core_course\analytics\indicator\no_teacher::get_min_value() ||
                $nostudentsindicator == \core_course\analytics\indicator\no_student::get_min_value()) {
            // No teachers or no students :(.
            return 1;
        }
        return 0;
    }
1023861
private static boolean sample(Long rootId) {
        if (Double.compare(sampleRate, 1.0d) >= 0)
            return true;
        int mod = (int) (Math.abs(rootId) % PRECISION);
        int threshold = (int) (sampleRate * PRECISION);
        return mod < threshold;
    }
682101
public function getForRange($key, \DateTime $start, \DateTime $end)
    {
        if (!$this->hasForRange($key, $start, $end)) {
            return null;
        }

        return $this->data[$this->keyForRange($key, $start, $end)];
    }
176546
public function timing($stat, $time, $sampleRate = 1, array $tags = null)
    {
        return $this->send(array($stat => "$time|ms"), $sampleRate, $tags);
    }
1291644
public static function get($stat, $key = Stats::DEFAULT_KEY)
    {
        return (int)Redis::instance()->hget($key, $stat);
    }
708870
public static function selectPlayerItem(
        $statisticState,
        $playerKey
    ) {
        $statisticState = (object) $statisticState;
        $playerKey = (string) $playerKey;

        $playerItem = $statisticState->player->$playerKey;

        return $playerItem;
    }
527509
public static function time($key = null) {

		if(null !== $key && false === is_string($key)) {
 			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
		}

		if(count(static :: $time) === 0) {
			static :: $time = [];
		}

		if(null !== $key) {
			
			static :: $time[] = ['time' => microtime(), 'key' => $key];
			return;
		}

		static :: $time[] = ['time' => microtime(), 'key' => 'end'];
		
		$laps = [];

		for($i = 1; $i < count(static :: $time); $i++) {

			$start 	= explode(' ', static :: $time[$i - 1]['time']);
			$end  	= explode(' ', static :: $time[$i]['time']);

			$laps[static :: $time[$i - 1]['key'] . ' - ' . static :: $time[$i]['key']] = number_format((($end[1] + $end[0]) - ($start[1] + $start[0])), 4, '.', '');
		}

		return $laps;
	}
48541
protected void processKey (SoundKey key)
        throws Exception
    {
        switch (key.cmd) {
        case PLAY:
        case LOOP:
            playSound(key);
            break;

        case LOCK:
            if (!isTesting()) {
                synchronized (_clipCache) {
                    try {
                        getClipData(key); // preload
                        // copy cached to lock map
                        _lockedClips.put(key, _clipCache.get(key));
                    } catch (Exception e) {
                        // don't whine about LOCK failures unless we are verbosely logging
                        if (_verbose.getValue()) {
                            throw e;
                        }
                    }
                }
            }
            break;

        case UNLOCK:
            synchronized (_clipCache) {
                _lockedClips.remove(key);
            }
            break;
        }
    }
1331656
static function accumulatorStop( $key, $recursive = false )
    {
        if ( !eZDebug::isDebugEnabled() )
            return;
        $stopTime = microtime( true );
        $debug = eZDebug::instance();
        $key = $key === false ? 'Default Debug-Accumulator' : $key;
        if ( ! array_key_exists( $key, $debug->TimeAccumulatorList ) )
        {
            eZDebug::writeWarning( "Accumulator '$key' does not exist, run eZDebug::accumulatorStart first", __METHOD__ );
            return;
        }
        $accumulator = $debug->TimeAccumulatorList[$key];
        if ( $recursive )
        {
            if ( isset( $accumulator['recursive_counter'] ) )
            {
                if ( $accumulator['recursive_counter'] > 0 )
                {
                    $accumulator['recursive_counter']--;
                    return;
                }
            }
        }
        $diffTime = $stopTime - $accumulator['temp_time'];
        $accumulator['time'] = $accumulator['time'] + $diffTime;
        ++$accumulator['count'];
        $debug->TimeAccumulatorList[$key] = $accumulator;
    }
253563
public function pExpireAt($key, $millisecondsTimestamp) {
        return $this->getHandler($this->judge(__FUNCTION__))->pExpireAt($key, $millisecondsTimestamp);
    }
668877
function (key, timeInterval, limit) {
        //Validate rate limiter settings
        if (!_.isNumber(timeInterval) || parseInt(timeInterval) <= 0 || !_.isNumber(limit) || parseInt(limit) <= 0) {
            return Q.reject();
        }
        var cacheKey = Encryption.md5("MiaJSRateLimit" + key + _calculateCurrentTimeInterval(timeInterval));
        return _validateRateLimit(cacheKey, timeInterval, limit).then(function (value) {
            return Q({
                limit: limit,
                remaining: limit - value,
                timeInterval: timeInterval,
                timeTillReset: _getTimeLeftTillReset(timeInterval)
            });
        });
    }
579787
public function start($key)
    {
        $key = strtolower($key);

        $this->benchmarks[$key] = [
            'start_time'    => microtime(true),
            'stop_time'     => 0.0,
            'avg_time'      => 0.0,
            'start_memory'  => memory_get_usage(true),
            'stop_memory'   => 0,
            'avg_memory'    => 0,
            'peak_memory'   => 0,
            'running'       => true
        ];
    }
382232
public function get($key)
    {
        $key = strtolower($key);

        if (! array_key_exists($key, $this->benchmarks))
        {
            throw new \RuntimeException('No Benchmark exists for: '. $key);
        }

        return $this->benchmarks[$key];
    }
754363
public function zRevRange($key, $start = 0, $stop = -1, $withScores = false) {
        return $this->_zRange('zrevrange', $key, $start, $stop, $withScores);
    }