summaryrefslogtreecommitdiffstats
path: root/chromium/cc/base/rolling_time_delta_history.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/base/rolling_time_delta_history.h')
-rw-r--r--chromium/cc/base/rolling_time_delta_history.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/chromium/cc/base/rolling_time_delta_history.h b/chromium/cc/base/rolling_time_delta_history.h
new file mode 100644
index 00000000000..e51fb86ba96
--- /dev/null
+++ b/chromium/cc/base/rolling_time_delta_history.h
@@ -0,0 +1,44 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_
+#define CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_
+
+#include <deque>
+#include <set>
+
+#include "base/time/time.h"
+#include "cc/base/cc_export.h"
+
+namespace cc {
+
+// Stores a limited number of samples. When the maximum size is reached, each
+// insertion results in the deletion of the oldest remaining sample.
+class CC_EXPORT RollingTimeDeltaHistory {
+ public:
+ explicit RollingTimeDeltaHistory(size_t max_size);
+
+ ~RollingTimeDeltaHistory();
+
+ void InsertSample(base::TimeDelta time);
+
+ void Clear();
+
+ // Returns the smallest sample that is greater than or equal to the specified
+ // percent of samples. If there aren't any samples, returns base::TimeDelta().
+ base::TimeDelta Percentile(double percent) const;
+
+ private:
+ typedef std::multiset<base::TimeDelta> TimeDeltaMultiset;
+
+ TimeDeltaMultiset sample_set_;
+ std::deque<TimeDeltaMultiset::iterator> chronological_sample_deque_;
+ size_t max_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(RollingTimeDeltaHistory);
+};
+
+} // namespace cc
+
+#endif // CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_