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

Side by Side Diff: cc/base/rolling_time_delta_history.h

Issue 2127003002: Switch cc::RollingTimeDeltaHistory to use a vector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replace modulo with a branch Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_ 5 #ifndef CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_
6 #define CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_ 6 #define CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <deque> 10 #include <vector>
11 #include <set>
12 11
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/time/time.h" 13 #include "base/time/time.h"
15 #include "cc/base/cc_export.h" 14 #include "cc/base/cc_export.h"
16 15
17 namespace cc { 16 namespace cc {
18 17
19 // Stores a limited number of samples. When the maximum size is reached, each 18 // Stores a limited number of samples. When the maximum size is reached, each
20 // insertion results in the deletion of the oldest remaining sample. 19 // insertion results in the deletion of the oldest remaining sample.
21 class CC_EXPORT RollingTimeDeltaHistory { 20 class CC_EXPORT RollingTimeDeltaHistory {
22 public: 21 public:
23 explicit RollingTimeDeltaHistory(size_t max_size); 22 explicit RollingTimeDeltaHistory(size_t max_size);
24 23
25 ~RollingTimeDeltaHistory(); 24 ~RollingTimeDeltaHistory();
26 25
27 void InsertSample(base::TimeDelta time); 26 void InsertSample(base::TimeDelta time);
28 27
29 void Clear(); 28 void Clear();
30 29
31 // Returns the smallest sample that is greater than or equal to the specified 30 // Returns the smallest sample that is greater than or equal to the specified
32 // percent of samples. If there aren't any samples, returns base::TimeDelta(). 31 // percent of samples. If there aren't any samples, returns base::TimeDelta().
33 base::TimeDelta Percentile(double percent) const; 32 base::TimeDelta Percentile(double percent) const;
34 33
35 private: 34 private:
36 typedef std::multiset<base::TimeDelta> TimeDeltaMultiset; 35 std::vector<base::TimeDelta> sample_vector_;
37 36 size_t next_index_;
38 TimeDeltaMultiset sample_set_;
39 std::deque<TimeDeltaMultiset::iterator> chronological_sample_deque_;
40 size_t max_size_; 37 size_t max_size_;
41 38
42 DISALLOW_COPY_AND_ASSIGN(RollingTimeDeltaHistory); 39 DISALLOW_COPY_AND_ASSIGN(RollingTimeDeltaHistory);
43 }; 40 };
44 41
45 } // namespace cc 42 } // namespace cc
46 43
47 #endif // CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_ 44 #endif // CC_BASE_ROLLING_TIME_DELTA_HISTORY_H_
OLDNEW
« no previous file with comments | « no previous file | cc/base/rolling_time_delta_history.cc » ('j') | cc/base/rolling_time_delta_history.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698