From fc0c0e335799d3a215f619c5c833025cf878accc Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Wed, 24 Apr 2013 13:52:26 +0000 Subject: [PATCH] Remove Isolate::Current() from histograms. R=svenpanne@chromium.org BUG= Review URL: https://chromiumcodereview.appspot.com/14471007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14416 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/counters.cc | 33 ++++-------------- src/counters.h | 99 ++++++++++++++++++++++++++++-------------------------- src/isolate.cc | 2 +- src/v8-counters.cc | 40 +++++++++------------- src/v8-counters.h | 2 ++ 5 files changed, 76 insertions(+), 100 deletions(-) diff --git a/src/counters.cc b/src/counters.cc index 7c8265e..fa192ba 100644 --- a/src/counters.cc +++ b/src/counters.cc @@ -45,57 +45,38 @@ int* StatsCounter::FindLocationInStatsTable() const { } -// Start the timer. -void StatsCounterTimer::Start() { - if (!counter_.Enabled()) - return; - stop_time_ = 0; - start_time_ = OS::Ticks(); -} - -// Stop the timer and record the results. -void StatsCounterTimer::Stop() { - if (!counter_.Enabled()) - return; - stop_time_ = OS::Ticks(); - - // Compute the delta between start and stop, in milliseconds. - int milliseconds = static_cast(stop_time_ - start_time_) / 1000; - counter_.Increment(milliseconds); -} - void Histogram::AddSample(int sample) { if (Enabled()) { - Isolate::Current()->stats_table()->AddHistogramSample(histogram_, sample); + isolate()->stats_table()->AddHistogramSample(histogram_, sample); } } void* Histogram::CreateHistogram() const { - return Isolate::Current()->stats_table()-> + return isolate()->stats_table()-> CreateHistogram(name_, min_, max_, num_buckets_); } // Start the timer. void HistogramTimer::Start() { - if (histogram_.Enabled()) { + if (Enabled()) { stop_time_ = 0; start_time_ = OS::Ticks(); } if (FLAG_log_internal_timer_events) { - LOG(Isolate::Current(), TimerEvent(Logger::START, histogram_.name_)); + LOG(isolate(), TimerEvent(Logger::START, name())); } } // Stop the timer and record the results. void HistogramTimer::Stop() { - if (histogram_.Enabled()) { + if (Enabled()) { stop_time_ = OS::Ticks(); // Compute the delta between start and stop, in milliseconds. int milliseconds = static_cast(stop_time_ - start_time_) / 1000; - histogram_.AddSample(milliseconds); + AddSample(milliseconds); } if (FLAG_log_internal_timer_events) { - LOG(Isolate::Current(), TimerEvent(Logger::END, histogram_.name_)); + LOG(isolate(), TimerEvent(Logger::END, name())); } } diff --git a/src/counters.h b/src/counters.h index 577280f..a633fea 100644 --- a/src/counters.h +++ b/src/counters.h @@ -113,14 +113,11 @@ class StatsTable { // The row has a 32bit value for each process/thread in the table and also // a name (stored in the table metadata). Since the storage location can be // thread-specific, this class cannot be shared across threads. -// -// This class is designed to be POD initialized. It will be registered with -// the counter system on first use. For example: -// StatsCounter c = { "c:myctr", NULL, false }; -struct StatsCounter { - const char* name_; - int* ptr_; - bool lookup_done_; +class StatsCounter { + public: + StatsCounter() { } + explicit StatsCounter(const char* name) + : name_(name), ptr_(NULL), lookup_done_(false) { } // Sets the counter to a specific value. void Set(int value) { @@ -177,39 +174,29 @@ struct StatsCounter { private: int* FindLocationInStatsTable() const; -}; - -// StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 }; -struct StatsCounterTimer { - StatsCounter counter_; - - int64_t start_time_; - int64_t stop_time_; - - // Start the timer. - void Start(); - - // Stop the timer and record the results. - void Stop(); - // Returns true if the timer is running. - bool Running() { - return counter_.Enabled() && start_time_ != 0 && stop_time_ == 0; - } + const char* name_; + int* ptr_; + bool lookup_done_; }; // A Histogram represents a dynamically created histogram in the StatsTable. -// -// This class is designed to be POD initialized. It will be registered with -// the histogram system on first use. For example: -// Histogram h = { "myhist", 0, 10000, 50, NULL, false }; -struct Histogram { - const char* name_; - int min_; - int max_; - int num_buckets_; - void* histogram_; - bool lookup_done_; +// It will be registered with the histogram system on first use. +class Histogram { + public: + Histogram() { } + Histogram(const char* name, + int min, + int max, + int num_buckets, + Isolate* isolate) + : name_(name), + min_(min), + max_(max), + num_buckets_(num_buckets), + histogram_(NULL), + lookup_done_(false), + isolate_(isolate) { } // Add a single sample to this histogram. void AddSample(int sample); @@ -234,17 +221,33 @@ struct Histogram { return histogram_; } + const char* name() { return name_; } + Isolate* isolate() const { return isolate_; } + private: void* CreateHistogram() const; -}; -// A HistogramTimer allows distributions of results to be created -// HistogramTimer t = { {L"foo", 0, 10000, 50, NULL, false}, 0, 0 }; -struct HistogramTimer { - Histogram histogram_; + const char* name_; + int min_; + int max_; + int num_buckets_; + void* histogram_; + bool lookup_done_; + Isolate* isolate_; +}; - int64_t start_time_; - int64_t stop_time_; +// A HistogramTimer allows distributions of results to be created. +class HistogramTimer : public Histogram { + public: + HistogramTimer() { } + HistogramTimer(const char* name, + int min, + int max, + int num_buckets, + Isolate* isolate) + : Histogram(name, min, max, num_buckets, isolate), + start_time_(0), + stop_time_(0) { } // Start the timer. void Start(); @@ -254,12 +257,12 @@ struct HistogramTimer { // Returns true if the timer is running. bool Running() { - return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0); + return Enabled() && (start_time_ != 0) && (stop_time_ == 0); } - void Reset() { - histogram_.Reset(); - } + private: + int64_t start_time_; + int64_t stop_time_; }; // Helper class for scoping a HistogramTimer. diff --git a/src/isolate.cc b/src/isolate.cc index 9ac7c78..8dbf514 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -2051,7 +2051,7 @@ void Isolate::InitializeLoggingAndCounters() { logger_ = new Logger(this); } if (counters_ == NULL) { - counters_ = new Counters; + counters_ = new Counters(this); } } diff --git a/src/v8-counters.cc b/src/v8-counters.cc index 4107dd3..ca83e38 100644 --- a/src/v8-counters.cc +++ b/src/v8-counters.cc @@ -32,58 +32,48 @@ namespace v8 { namespace internal { -Counters::Counters() { +Counters::Counters(Isolate* isolate) { #define HT(name, caption) \ - HistogramTimer name = { {#caption, 0, 10000, 50, NULL, false}, 0, 0 }; \ - name##_ = name; + name##_ = HistogramTimer(#caption, 0, 10000, 50, isolate); HISTOGRAM_TIMER_LIST(HT) #undef HT #define HP(name, caption) \ - Histogram name = { #caption, 0, 101, 100, NULL, false }; \ - name##_ = name; + name##_ = Histogram(#caption, 0, 101, 100, isolate); HISTOGRAM_PERCENTAGE_LIST(HP) #undef HP #define HM(name, caption) \ - Histogram name = { #caption, 1000, 500000, 50, NULL, false }; \ - name##_ = name; + name##_ = Histogram(#caption, 1000, 500000, 50, isolate); HISTOGRAM_MEMORY_LIST(HM) #undef HM #define SC(name, caption) \ - StatsCounter name = { "c:" #caption, NULL, false };\ - name##_ = name; + name##_ = StatsCounter("c:" #caption); STATS_COUNTER_LIST_1(SC) STATS_COUNTER_LIST_2(SC) #undef SC #define SC(name) \ - StatsCounter count_of_##name = { "c:" "V8.CountOf_" #name, NULL, false };\ - count_of_##name##_ = count_of_##name; \ - StatsCounter size_of_##name = { "c:" "V8.SizeOf_" #name, NULL, false };\ - size_of_##name##_ = size_of_##name; + count_of_##name##_ = StatsCounter("c:" "V8.CountOf_" #name); \ + size_of_##name##_ = StatsCounter("c:" "V8.SizeOf_" #name); INSTANCE_TYPE_LIST(SC) #undef SC #define SC(name) \ - StatsCounter count_of_CODE_TYPE_##name = { \ - "c:" "V8.CountOf_CODE_TYPE-" #name, NULL, false }; \ - count_of_CODE_TYPE_##name##_ = count_of_CODE_TYPE_##name; \ - StatsCounter size_of_CODE_TYPE_##name = { \ - "c:" "V8.SizeOf_CODE_TYPE-" #name, NULL, false }; \ - size_of_CODE_TYPE_##name##_ = size_of_CODE_TYPE_##name; + count_of_CODE_TYPE_##name##_ = \ + StatsCounter("c:" "V8.CountOf_CODE_TYPE-" #name); \ + size_of_CODE_TYPE_##name##_ = \ + StatsCounter("c:" "V8.SizeOf_CODE_TYPE-" #name); CODE_KIND_LIST(SC) #undef SC #define SC(name) \ - StatsCounter count_of_FIXED_ARRAY_##name = { \ - "c:" "V8.CountOf_FIXED_ARRAY-" #name, NULL, false }; \ - count_of_FIXED_ARRAY_##name##_ = count_of_FIXED_ARRAY_##name; \ - StatsCounter size_of_FIXED_ARRAY_##name = { \ - "c:" "V8.SizeOf_FIXED_ARRAY-" #name, NULL, false }; \ - size_of_FIXED_ARRAY_##name##_ = size_of_FIXED_ARRAY_##name; + count_of_FIXED_ARRAY_##name##_ = \ + StatsCounter("c:" "V8.CountOf_FIXED_ARRAY-" #name); \ + size_of_FIXED_ARRAY_##name##_ = \ + StatsCounter("c:" "V8.SizeOf_FIXED_ARRAY-" #name); \ FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) #undef SC } diff --git a/src/v8-counters.h b/src/v8-counters.h index 374ebbc..c810cba 100644 --- a/src/v8-counters.h +++ b/src/v8-counters.h @@ -420,6 +420,8 @@ class Counters { friend class Isolate; + explicit Counters(Isolate* isolate); + DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); }; -- 2.7.4