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

Unified Diff: cc/scheduler/rolling_sample_window.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
Index: cc/scheduler/rolling_sample_window.h
diff --git a/cc/scheduler/rolling_sample_window.h b/cc/scheduler/rolling_sample_window.h
new file mode 100644
index 0000000000000000000000000000000000000000..5e7aa4695ee13e31fc1b35cb5bfadb8f87d4c8a2
--- /dev/null
+++ b/cc/scheduler/rolling_sample_window.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_SAMPLE_WINDOW_H_
+#define CC_SCHEDULER_ROLLING_SAMPLE_WINDOW_H_
+
+#include <list>
+#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 RollingSampleWindow {
brianderson 2013/05/31 18:42:05 If we are going to use a generic class name like t
ajuma 2013/05/31 20:41:11 Renamed to RollingTimeDeltaHistory.
+ public:
+ explicit RollingSampleWindow(size_t max_size);
+
+ ~RollingSampleWindow();
+
+ void InsertSample(base::TimeDelta time);
+
+ void Clear();
+
+ // Returns the smallest base::TimeDelta that is greater than or equal to
+ // the specified percent of samples.
+ base::TimeDelta Percentile(double percent) const;
+
+ private:
+ typedef std::multiset<base::TimeDelta> TimeDeltaMultiset;
+
+ TimeDeltaMultiset sample_set_;
+ std::list<TimeDeltaMultiset::iterator> chronological_sample_list_;
brianderson 2013/05/31 18:42:05 Would a std::deque be more efficient? Once it reac
ajuma 2013/05/31 20:41:11 Changed to a deque.
+ size_t max_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(RollingSampleWindow);
+};
+
+} // namespace cc
+
+#endif // CC_SCHEDULER_ROLLING_SAMPLE_WINDOW_H_

Powered by Google App Engine
This is Rietveld 408576698