diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/profiler/tracked_time.h | 2 | ||||
-rw-r--r-- | base/tracked_objects.cc | 58 | ||||
-rw-r--r-- | base/tracked_objects.h | 49 | ||||
-rw-r--r-- | base/tracked_objects_unittest.cc | 22 |
4 files changed, 66 insertions, 65 deletions
diff --git a/base/profiler/tracked_time.h b/base/profiler/tracked_time.h index e8e6d17..6f4bc7e 100644 --- a/base/profiler/tracked_time.h +++ b/base/profiler/tracked_time.h @@ -12,6 +12,8 @@ namespace tracked_objects { +typedef int DurationInt; + //------------------------------------------------------------------------------ #define USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc index 5403af58..6126a45e1 100644 --- a/base/tracked_objects.cc +++ b/base/tracked_objects.cc @@ -33,18 +33,18 @@ static const ThreadData::Status kInitialStartupState = ThreadData::ACTIVE; //------------------------------------------------------------------------------ // DeathData tallies durations when a death takes place. -void DeathData::RecordDeath(const Duration& queue_duration, - const Duration& run_duration) { +void DeathData::RecordDeath(DurationInt queue_duration, + DurationInt run_duration) { ++count_; queue_time_.AddDuration(queue_duration); run_time_.AddDuration(run_duration); } -int DeathData::AverageMsRunDuration() const { +DurationInt DeathData::AverageMsRunDuration() const { return run_time_.AverageMsDuration(count_); } -int DeathData::AverageMsQueueDuration() const { +DurationInt DeathData::AverageMsQueueDuration() const { return queue_time_.AverageMsDuration(count_); } @@ -70,13 +70,13 @@ base::DictionaryValue* DeathData::ToValue() const { base::DictionaryValue* dictionary = new base::DictionaryValue; dictionary->Set("count", base::Value::CreateIntegerValue(count_)); dictionary->Set("run_ms", - base::Value::CreateIntegerValue(run_time_.duration().InMilliseconds())); + base::Value::CreateIntegerValue(run_time_.duration())); dictionary->Set("queue_ms", - base::Value::CreateIntegerValue(queue_time_.duration().InMilliseconds())); + base::Value::CreateIntegerValue(queue_time_.duration())); dictionary->Set("run_ms_max", - base::Value::CreateIntegerValue(run_time_.max().InMilliseconds())); + base::Value::CreateIntegerValue(run_time_.max())); dictionary->Set("queue_ms_max", - base::Value::CreateIntegerValue(queue_time_.max().InMilliseconds())); + base::Value::CreateIntegerValue(queue_time_.max())); return dictionary; } @@ -93,14 +93,14 @@ void DeathData::Data::WriteHTML(int count, std::string* output) const { // InMilliseconds() may not always be an int, even if it can generally fit // into an int. base::StringAppendF(output, "%dms", - static_cast<int>(duration_.InMilliseconds())); + static_cast<int>(duration_)); if (count == 1) { output->append(" "); return; } base::StringAppendF(output, "(%dms/life,max:%dms) ", - AverageMsDuration(count), - static_cast<int>(max_.InMilliseconds())); + static_cast<int>(AverageMsDuration(count)), + static_cast<int>(max_)); } void DeathData::Data::AddData(const Data& other) { @@ -110,22 +110,22 @@ void DeathData::Data::AddData(const Data& other) { max_ = other.max_; } -void DeathData::Data::AddDuration(const Duration& duration) { +void DeathData::Data::AddDuration(DurationInt duration) { duration_ += duration; if (max_ > duration) return; max_ = duration; } -int DeathData::Data::AverageMsDuration(int count) const { - if (duration_ == Duration() || !count) +DurationInt DeathData::Data::AverageMsDuration(int count) const { + if (duration_ == 0 || !count) return 0; - return static_cast<int>(duration_.InMilliseconds() + count / 2) / count; + return (duration_ + count / 2) / count; } void DeathData::Data::Clear() { - duration_ = Duration(); - max_ = Duration(); + duration_ = 0; + max_ = 0; } //------------------------------------------------------------------------------ BirthOnThread::BirthOnThread(const Location& location, @@ -401,8 +401,8 @@ Births* ThreadData::TallyABirth(const Location& location) { } void ThreadData::TallyADeath(const Births& birth, - const Duration& queue_duration, - const Duration& run_duration) { + DurationInt queue_duration, + DurationInt run_duration) { DeathMap::iterator it = death_map_.find(&birth); DeathData* death_data; if (it != death_map_.end()) { @@ -460,12 +460,12 @@ void ThreadData::TallyRunOnNamedThreadIfTracking( // get a time value since we "weren't tracking" and we were trying to be // efficient by not calling for a genuine time value. For simplicity, we'll // use a default zero duration when we can't calculate a true value. - Duration queue_duration; - Duration run_duration; + DurationInt queue_duration = 0; + DurationInt run_duration = 0; if (!start_of_run.is_null()) { - queue_duration = start_of_run - effective_post_time; + queue_duration = (start_of_run - effective_post_time).InMilliseconds(); if (!end_of_run.is_null()) - run_duration = end_of_run - start_of_run; + run_duration = (end_of_run - start_of_run).InMilliseconds(); } current_thread_data->TallyADeath(*birth, queue_duration, run_duration); } @@ -498,12 +498,12 @@ void ThreadData::TallyRunOnWorkerThreadIfTracking( if (!current_thread_data) return; - Duration queue_duration; - Duration run_duration; + DurationInt queue_duration = 0; + DurationInt run_duration = 0; if (!start_of_run.is_null()) { - queue_duration = start_of_run - time_posted; + queue_duration = (start_of_run - time_posted).InMilliseconds(); if (!end_of_run.is_null()) - run_duration = end_of_run - start_of_run; + run_duration = (end_of_run - start_of_run).InMilliseconds(); } current_thread_data->TallyADeath(*birth, queue_duration, run_duration); } @@ -526,8 +526,8 @@ void ThreadData::TallyRunInAScopedRegionIfTracking( if (!current_thread_data) return; - Duration queue_duration = Duration(); - Duration run_duration = end_of_run - start_of_run; + DurationInt queue_duration = 0; + DurationInt run_duration = (end_of_run - start_of_run).InMilliseconds(); current_thread_data->TallyADeath(*birth, queue_duration, run_duration); } diff --git a/base/tracked_objects.h b/base/tracked_objects.h index 94766ea..5068e6a 100644 --- a/base/tracked_objects.h +++ b/base/tracked_objects.h @@ -232,21 +232,22 @@ class BASE_EXPORT DeathData { // When deaths have not yet taken place, and we gather data from all the // threads, we create DeathData stats that tally the number of births without // a corrosponding death. - explicit DeathData(int count) : count_(count) {} + explicit DeathData(int count) + : count_(count) {} // Update stats for a task destruction (death) that had a Run() time of // |duration|, and has had a queueing delay of |queue_duration|. - void RecordDeath(const Duration& queue_duration, - const Duration& run_duration); + void RecordDeath(DurationInt queue_duration, + DurationInt run_duration); // Metrics accessors. int count() const { return count_; } - Duration run_duration() const { return run_time_.duration(); } - int AverageMsRunDuration() const; - Duration run_duration_max() const { return run_time_.max(); } - Duration queue_duration() const { return queue_time_.duration(); } - int AverageMsQueueDuration() const; - Duration queue_duration_max() const { return queue_time_.max(); } + DurationInt run_duration() const { return run_time_.duration(); } + DurationInt AverageMsRunDuration() const; + DurationInt run_duration_max() const { return run_time_.max(); } + DurationInt queue_duration() const { return queue_time_.duration(); } + DurationInt AverageMsQueueDuration() const; + DurationInt queue_duration_max() const { return queue_time_.max(); } // Accumulate metrics from other into this. This method is never used on // realtime statistics, and only used in snapshots and aggregatinos. @@ -267,11 +268,11 @@ class BASE_EXPORT DeathData { // aggregated, such as queueing times, or run times. class Data { public: - Data() {} + Data() : duration_(0), max_(0) {} ~Data() {} - Duration duration() const { return duration_; } - Duration max() const { return max_; } + DurationInt duration() const { return duration_; } + DurationInt max() const { return max_; } // Emits HTML formated description of members, assuming |count| instances // when calculating averages. @@ -279,18 +280,18 @@ class BASE_EXPORT DeathData { // Agggegate data into our state. void AddData(const Data& other); - void AddDuration(const Duration& duration); + void AddDuration(DurationInt duration); // Central helper function for calculating averages (correctly, in only one // place). - int AverageMsDuration(int count) const; + DurationInt AverageMsDuration(int count) const; // Resets all members to zero. void Clear(); private: - Duration duration_; // Sum of all durations seen. - Duration max_; // Largest singular duration seen. + DurationInt duration_; // Sum of all durations seen. + DurationInt max_; // Largest singular duration seen. }; @@ -323,18 +324,18 @@ class BASE_EXPORT Snapshot { const std::string DeathThreadName() const; int count() const { return death_data_.count(); } - Duration run_duration() const { return death_data_.run_duration(); } - int AverageMsRunDuration() const { + DurationInt run_duration() const { return death_data_.run_duration(); } + DurationInt AverageMsRunDuration() const { return death_data_.AverageMsRunDuration(); } - Duration run_duration_max() const { + DurationInt run_duration_max() const { return death_data_.run_duration_max(); } - Duration queue_duration() const { return death_data_.queue_duration(); } - int AverageMsQueueDuration() const { + DurationInt queue_duration() const { return death_data_.queue_duration(); } + DurationInt AverageMsQueueDuration() const { return death_data_.AverageMsQueueDuration(); } - Duration queue_duration_max() const { + DurationInt queue_duration_max() const { return death_data_.queue_duration_max(); } @@ -692,8 +693,8 @@ class BASE_EXPORT ThreadData { // Find a place to record a death on this thread. void TallyADeath(const Births& birth, - const Duration& queue_duration, - const Duration& duration); + DurationInt queue_duration, + DurationInt duration); // Using our lock to protect the iteration, Clear all birth and death data. void Reset(); diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc index de7451a..fd2f2ad 100644 --- a/base/tracked_objects_unittest.cc +++ b/base/tracked_objects_unittest.cc @@ -118,27 +118,25 @@ TEST_F(TrackedObjectsTest, DeathDataTest) { scoped_ptr<DeathData> data(new DeathData()); ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); - EXPECT_EQ(data->run_duration(), Duration()); - EXPECT_EQ(data->queue_duration(), Duration()); + EXPECT_EQ(data->run_duration(), 0); + EXPECT_EQ(data->queue_duration(), 0); EXPECT_EQ(data->AverageMsRunDuration(), 0); EXPECT_EQ(data->AverageMsQueueDuration(), 0); EXPECT_EQ(data->count(), 0); - int run_ms = 42; - int queue_ms = 8; + DurationInt run_ms = 42; + DurationInt queue_ms = 8; - Duration run_duration = Duration().FromMilliseconds(run_ms); - Duration queue_duration = Duration().FromMilliseconds(queue_ms); - data->RecordDeath(queue_duration, run_duration); - EXPECT_EQ(data->run_duration(), run_duration); - EXPECT_EQ(data->queue_duration(), queue_duration); + data->RecordDeath(queue_ms, run_ms); + EXPECT_EQ(data->run_duration(), run_ms); + EXPECT_EQ(data->queue_duration(), queue_ms); EXPECT_EQ(data->AverageMsRunDuration(), run_ms); EXPECT_EQ(data->AverageMsQueueDuration(), queue_ms); EXPECT_EQ(data->count(), 1); - data->RecordDeath(queue_duration, run_duration); - EXPECT_EQ(data->run_duration(), run_duration + run_duration); - EXPECT_EQ(data->queue_duration(), queue_duration + queue_duration); + data->RecordDeath(queue_ms, run_ms); + EXPECT_EQ(data->run_duration(), run_ms + run_ms); + EXPECT_EQ(data->queue_duration(), queue_ms + queue_ms); EXPECT_EQ(data->AverageMsRunDuration(), run_ms); EXPECT_EQ(data->AverageMsQueueDuration(), queue_ms); EXPECT_EQ(data->count(), 2); |