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

Side by Side Diff: base/tracked_objects.cc

Issue 8888004: Minor cleanup preparing for recording parent-child data (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « base/tracked_objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/tracked_objects.h" 5 #include "base/tracked_objects.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 25 matching lines...) Expand all
36 36
37 DeathData::DeathData() { 37 DeathData::DeathData() {
38 Clear(); 38 Clear();
39 } 39 }
40 40
41 DeathData::DeathData(int count) { 41 DeathData::DeathData(int count) {
42 Clear(); 42 Clear();
43 count_ = count; 43 count_ = count;
44 } 44 }
45 45
46 // TODO(jar): I need to see if this macro to optimize branching is worth it. 46 // TODO(jar): I need to see if this macro to optimize branching is worth using.
47 // 47 //
48 // This macro has no branching, so it is surely fast, and is equivalent to: 48 // This macro has no branching, so it is surely fast, and is equivalent to:
49 // if (assign_it) 49 // if (assign_it)
50 // target = source; 50 // target = source;
51 // We use a macro rather than a template to force this to inline. 51 // We use a macro rather than a template to force this to inline.
52 // Related code for calculating max is discussed on the web. 52 // Related code for calculating max is discussed on the web.
53 #define CONDITIONAL_ASSIGN(assign_it, target, source) \ 53 #define CONDITIONAL_ASSIGN(assign_it, target, source) \
54 ((target) ^= ((target) ^ (source)) & -static_cast<DurationInt>(assign_it)) 54 ((target) ^= ((target) ^ (source)) & -static_cast<DurationInt>(assign_it))
55 55
56 void DeathData::RecordDeath(const DurationInt queue_duration, 56 void DeathData::RecordDeath(const DurationInt queue_duration,
57 const DurationInt run_duration, 57 const DurationInt run_duration,
58 int32 random_number) { 58 int32 random_number) {
59 ++count_;
59 queue_duration_sum_ += queue_duration; 60 queue_duration_sum_ += queue_duration;
60 run_duration_sum_ += run_duration; 61 run_duration_sum_ += run_duration;
61 ++count_; 62
63 if (queue_duration_max_ < queue_duration)
64 queue_duration_max_ = queue_duration;
65 if (run_duration_max_ < run_duration)
66 run_duration_max_ = run_duration;
62 67
63 // Take a uniformly distributed sample over all durations ever supplied. 68 // Take a uniformly distributed sample over all durations ever supplied.
64 // The probability that we (instead) use this new sample is 1/count_. This 69 // The probability that we (instead) use this new sample is 1/count_. This
65 // results in a completely uniform selection of the sample. 70 // results in a completely uniform selection of the sample.
66 // We ignore the fact that we correlated our selection of a sample of run 71 // We ignore the fact that we correlated our selection of a sample of run
67 // and queue times. 72 // and queue times.
68 bool take_sample = 0 == (random_number % count_); 73 if (0 == (random_number % count_)) {
69 CONDITIONAL_ASSIGN(take_sample, queue_duration_sample_, queue_duration); 74 queue_duration_sample_ = queue_duration;
70 CONDITIONAL_ASSIGN(take_sample, run_duration_sample_, run_duration); 75 run_duration_sample_ = run_duration;
71 76 }
72 CONDITIONAL_ASSIGN(queue_duration_max_ < queue_duration, queue_duration_max_,
73 queue_duration);
74 CONDITIONAL_ASSIGN(run_duration_max_ < run_duration, run_duration_max_,
75 run_duration);
76 // Ensure we got the macros right.
77 DCHECK_GE(queue_duration_max_, queue_duration);
78 DCHECK_GE(run_duration_max_, run_duration);
79 DCHECK(!take_sample || run_duration_sample_ == run_duration);
80 DCHECK(!take_sample || queue_duration_sample_ == queue_duration);
81 } 77 }
82 78
83 int DeathData::count() const { return count_; } 79 int DeathData::count() const { return count_; }
84 80
85 DurationInt DeathData::run_duration_sum() const { return run_duration_sum_; } 81 DurationInt DeathData::run_duration_sum() const { return run_duration_sum_; }
86 82
87 DurationInt DeathData::run_duration_max() const { return run_duration_max_; } 83 DurationInt DeathData::run_duration_max() const { return run_duration_max_; }
88 84
89 DurationInt DeathData::run_duration_sample() const { 85 DurationInt DeathData::run_duration_sample() const {
90 return run_duration_sample_; 86 return run_duration_sample_;
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 738
743 base::ListValue* DataCollector::ToValue() const { 739 base::ListValue* DataCollector::ToValue() const {
744 base::ListValue* list = new base::ListValue; 740 base::ListValue* list = new base::ListValue;
745 for (size_t i = 0; i < collection_.size(); ++i) { 741 for (size_t i = 0; i < collection_.size(); ++i) {
746 list->Append(collection_[i].ToValue()); 742 list->Append(collection_[i].ToValue());
747 } 743 }
748 return list; 744 return list;
749 } 745 }
750 746
751 } // namespace tracked_objects 747 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « base/tracked_objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698