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

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

Issue 833283003: Reland "Add new latency_info for tracking browser composite time." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments Created 5 years, 11 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 #include <cmath> 5 #include <cmath>
6 6
7 #include "cc/base/rolling_time_delta_history.h" 7 #include "cc/base/rolling_time_delta_history.h"
8 8
9 namespace cc { 9 namespace cc {
10 10
11 RollingTimeDeltaHistory::RollingTimeDeltaHistory(size_t max_size) 11 RollingTimeDeltaHistory::RollingTimeDeltaHistory(size_t max_size)
12 : max_size_(max_size) {} 12 : max_size_(max_size) {}
13 13
14 RollingTimeDeltaHistory::~RollingTimeDeltaHistory() {} 14 RollingTimeDeltaHistory::~RollingTimeDeltaHistory() {}
15 15
16 void RollingTimeDeltaHistory::InsertSample(base::TimeDelta time) { 16 void RollingTimeDeltaHistory::InsertSample(base::TimeDelta time) {
17 if (max_size_ == 0) 17 if (max_size_ == 0)
18 return; 18 return;
19 19
20 if (sample_set_.size() == max_size_) { 20 if (sample_set_.size() == max_size_) {
21 sample_set_.erase(chronological_sample_deque_.front()); 21 sample_set_.erase(chronological_sample_deque_.front());
22 chronological_sample_deque_.pop_front(); 22 chronological_sample_deque_.pop_front();
23 } 23 }
24 24
25 TimeDeltaMultiset::iterator it = sample_set_.insert(time); 25 TimeDeltaMultiset::iterator it = sample_set_.insert(time);
26 chronological_sample_deque_.push_back(it); 26 chronological_sample_deque_.push_back(it);
27 } 27 }
28 28
29 size_t RollingTimeDeltaHistory::SampleCount() {
30 return sample_set_.size();
31 }
32
29 void RollingTimeDeltaHistory::Clear() { 33 void RollingTimeDeltaHistory::Clear() {
30 chronological_sample_deque_.clear(); 34 chronological_sample_deque_.clear();
31 sample_set_.clear(); 35 sample_set_.clear();
32 } 36 }
33 37
34 base::TimeDelta RollingTimeDeltaHistory::Percentile(double percent) const { 38 base::TimeDelta RollingTimeDeltaHistory::Percentile(double percent) const {
35 if (sample_set_.size() == 0) 39 if (sample_set_.size() == 0)
36 return base::TimeDelta(); 40 return base::TimeDelta();
37 41
38 double fraction = percent / 100.0; 42 double fraction = percent / 100.0;
(...skipping 15 matching lines...) Expand all
54 return *it; 58 return *it;
55 } 59 }
56 60
57 TimeDeltaMultiset::const_iterator it = sample_set_.begin(); 61 TimeDeltaMultiset::const_iterator it = sample_set_.begin();
58 for (size_t i = 0; i < num_smaller_samples; i++) 62 for (size_t i = 0; i < num_smaller_samples; i++)
59 it++; 63 it++;
60 return *it; 64 return *it;
61 } 65 }
62 66
63 } // namespace cc 67 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698