/usr/lib/python2.7/dist-packages/aws_xray_sdk/core/sampling/reservoir.py is in python-aws-xray-sdk 0.95-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import time
import threading
class Reservoir(object):
"""
Keeps track of the number of sampled segments within
a single second. This class is implemented to be
thread-safe to achieve accurate sampling.
"""
def __init__(self, traces_per_sec=0):
"""
:param int traces_per_sec: number of guranteed
sampled segments.
"""
self._lock = threading.Lock()
self.traces_per_sec = traces_per_sec
self.used_this_sec = 0
self.this_sec = int(time.time())
def take(self):
"""
Returns True if there are segments left within the
current second, otherwise return False.
"""
with self._lock:
now = int(time.time())
if now != self.this_sec:
self.used_this_sec = 0
self.this_sec = now
if self.used_this_sec >= self.traces_per_sec:
return False
self.used_this_sec = self.used_this_sec + 1
return True
|