15 #ifndef IMPALA_UTIL_STREAMING_SAMPLER_H
16 #define IMPALA_UTIL_STREAMING_SAMPLER_H
31 template<
typename T,
int MAX_SAMPLES>
62 boost::lock_guard<SpinLock> l(
lock_);
76 for (
int i = 0; i < MAX_SAMPLES / 2; ++i) {
99 void SetSamples(
int period,
const std::vector<T>& samples) {
100 DCHECK_LE(samples.size(), MAX_SAMPLES);
102 boost::lock_guard<SpinLock> l(
lock_);
112 boost::lock_guard<SpinLock> l(
lock_);
113 std::stringstream ss;
114 ss << prefix <<
"Period = " <<
period_ << std::endl
116 << prefix <<
"Samples = {";
120 ss << prefix <<
"}" << std::endl;
StreamingSampler(int initial_period=500)
int samples_collected_
Number of samples collected <= MAX_SAMPLES.
int period_
Storage period in ms.
void lock()
Acquires the lock, spins until the lock becomes available.
int current_sample_total_time_
The total time that current_sample_sum_ represents.
int current_sample_count_
The number of input samples that contribute to current_sample_sum_.
void SetSamples(int period, const std::vector< T > &samples)
Set the underlying data to period/samples.
const T * GetSamples(int *num_samples, int *period, SpinLock **lock=NULL) const
T current_sample_sum_
The sum of input samples that makes up the next stored sample.
void AddSample(T sample, int ms)
StreamingSampler(int period, const std::vector< T > &initial_samples)
Initialize the sampler with values.
std::string DebugString(const std::string &prefix="") const