Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2432)

Unified Diff: cc/scheduler/rolling_time_delta_history.h

Issue 15647015: Support computing percentiles on a rolling window of samples (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/scheduler/rolling_time_delta_history.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/scheduler/rolling_time_delta_history.h
diff --git a/cc/scheduler/rolling_time_delta_history.h b/cc/scheduler/rolling_time_delta_history.h
new file mode 100644
index 0000000000000000000000000000000000000000..947fb9855062b5b5d0c8c05af52b7cd8ef69d2c8
--- /dev/null
+++ b/cc/scheduler/rolling_time_delta_history.h
@@ -0,0 +1,44 @@
+// Copyright 2013 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_SCHEDULER_ROLLING_TIME_DELTA_HISTORY_H_
+#define CC_SCHEDULER_ROLLING_TIME_DELTA_HISTORY_H_
+
+#include <deque>
+#include <set>
+
+#include "base/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_SCHEDULER_ROLLING_TIME_DELTA_HISTORY_H_
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/scheduler/rolling_time_delta_history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698