sliding_counter.cc
1 // Copyright 2013, Beeri 15. All rights reserved.
2 // Author: Roman Gershman (romange@gmail.com)
3 //
4 #include "util/stats/sliding_counter.h"
5 
6 #include "base/walltime.h"
7 #include "base/pthread_utils.h"
8 
9 #include <time.h>
10 #include "base/init.h"
11 #include "base/port.h"
12 
13 namespace util {
14 
15 static uint32 g_test_used = kuint32max;
16 
17 SlidingSecondBase::SlidingSecondBase() {
18 }
19 
20 uint32 SlidingSecondBase::CurrentTime() {
21  if (PREDICT_TRUE(g_test_used == kuint32max)) {
22  return base::GetMonotonicMicrosFast() / base::kNumMicrosPerSecond;
23  }
24  return g_test_used;
25 }
26 
27 
28 void SlidingSecondBase::SetCurrentTime_Test(uint32 time_val) {
29  g_test_used = time_val;
30 }
31 
32 uint32 QPSCount::Get() const {
33  constexpr unsigned kWinSize = decltype(window_)::SIZE - 1;
34 
35  return window_.SumLast(1, kWinSize) / kWinSize; // Average over kWinSize values.
36 }
37 
38 
39 } // namespace util