Commit fc0c0e33 authored by yangguo@chromium.org's avatar yangguo@chromium.org

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
parent 23f39546
...@@ -45,57 +45,38 @@ int* StatsCounter::FindLocationInStatsTable() const { ...@@ -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<int>(stop_time_ - start_time_) / 1000;
counter_.Increment(milliseconds);
}
void Histogram::AddSample(int sample) { void Histogram::AddSample(int sample) {
if (Enabled()) { if (Enabled()) {
Isolate::Current()->stats_table()->AddHistogramSample(histogram_, sample); isolate()->stats_table()->AddHistogramSample(histogram_, sample);
} }
} }
void* Histogram::CreateHistogram() const { void* Histogram::CreateHistogram() const {
return Isolate::Current()->stats_table()-> return isolate()->stats_table()->
CreateHistogram(name_, min_, max_, num_buckets_); CreateHistogram(name_, min_, max_, num_buckets_);
} }
// Start the timer. // Start the timer.
void HistogramTimer::Start() { void HistogramTimer::Start() {
if (histogram_.Enabled()) { if (Enabled()) {
stop_time_ = 0; stop_time_ = 0;
start_time_ = OS::Ticks(); start_time_ = OS::Ticks();
} }
if (FLAG_log_internal_timer_events) { 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. // Stop the timer and record the results.
void HistogramTimer::Stop() { void HistogramTimer::Stop() {
if (histogram_.Enabled()) { if (Enabled()) {
stop_time_ = OS::Ticks(); stop_time_ = OS::Ticks();
// Compute the delta between start and stop, in milliseconds. // Compute the delta between start and stop, in milliseconds.
int milliseconds = static_cast<int>(stop_time_ - start_time_) / 1000; int milliseconds = static_cast<int>(stop_time_ - start_time_) / 1000;
histogram_.AddSample(milliseconds); AddSample(milliseconds);
} }
if (FLAG_log_internal_timer_events) { if (FLAG_log_internal_timer_events) {
LOG(Isolate::Current(), TimerEvent(Logger::END, histogram_.name_)); LOG(isolate(), TimerEvent(Logger::END, name()));
} }
} }
......
...@@ -113,14 +113,11 @@ class StatsTable { ...@@ -113,14 +113,11 @@ class StatsTable {
// The row has a 32bit value for each process/thread in the table and also // 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 // a name (stored in the table metadata). Since the storage location can be
// thread-specific, this class cannot be shared across threads. // thread-specific, this class cannot be shared across threads.
// class StatsCounter {
// This class is designed to be POD initialized. It will be registered with public:
// the counter system on first use. For example: StatsCounter() { }
// StatsCounter c = { "c:myctr", NULL, false }; explicit StatsCounter(const char* name)
struct StatsCounter { : name_(name), ptr_(NULL), lookup_done_(false) { }
const char* name_;
int* ptr_;
bool lookup_done_;
// Sets the counter to a specific value. // Sets the counter to a specific value.
void Set(int value) { void Set(int value) {
...@@ -177,39 +174,29 @@ struct StatsCounter { ...@@ -177,39 +174,29 @@ struct StatsCounter {
private: private:
int* FindLocationInStatsTable() const; 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. const char* name_;
void Stop(); int* ptr_;
bool lookup_done_;
// Returns true if the timer is running.
bool Running() {
return counter_.Enabled() && start_time_ != 0 && stop_time_ == 0;
}
}; };
// A Histogram represents a dynamically created histogram in the StatsTable. // A Histogram represents a dynamically created histogram in the StatsTable.
// // It will be registered with the histogram system on first use.
// This class is designed to be POD initialized. It will be registered with class Histogram {
// the histogram system on first use. For example: public:
// Histogram h = { "myhist", 0, 10000, 50, NULL, false }; Histogram() { }
struct Histogram { Histogram(const char* name,
const char* name_; int min,
int min_; int max,
int max_; int num_buckets,
int num_buckets_; Isolate* isolate)
void* histogram_; : name_(name),
bool lookup_done_; min_(min),
max_(max),
num_buckets_(num_buckets),
histogram_(NULL),
lookup_done_(false),
isolate_(isolate) { }
// Add a single sample to this histogram. // Add a single sample to this histogram.
void AddSample(int sample); void AddSample(int sample);
...@@ -234,17 +221,33 @@ struct Histogram { ...@@ -234,17 +221,33 @@ struct Histogram {
return histogram_; return histogram_;
} }
const char* name() { return name_; }
Isolate* isolate() const { return isolate_; }
private: private:
void* CreateHistogram() const; void* CreateHistogram() const;
};
// A HistogramTimer allows distributions of results to be created const char* name_;
// HistogramTimer t = { {L"foo", 0, 10000, 50, NULL, false}, 0, 0 }; int min_;
struct HistogramTimer { int max_;
Histogram histogram_; int num_buckets_;
void* histogram_;
bool lookup_done_;
Isolate* isolate_;
};
int64_t start_time_; // A HistogramTimer allows distributions of results to be created.
int64_t stop_time_; 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. // Start the timer.
void Start(); void Start();
...@@ -254,12 +257,12 @@ struct HistogramTimer { ...@@ -254,12 +257,12 @@ struct HistogramTimer {
// Returns true if the timer is running. // Returns true if the timer is running.
bool Running() { bool Running() {
return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0); return Enabled() && (start_time_ != 0) && (stop_time_ == 0);
} }
void Reset() { private:
histogram_.Reset(); int64_t start_time_;
} int64_t stop_time_;
}; };
// Helper class for scoping a HistogramTimer. // Helper class for scoping a HistogramTimer.
......
...@@ -2051,7 +2051,7 @@ void Isolate::InitializeLoggingAndCounters() { ...@@ -2051,7 +2051,7 @@ void Isolate::InitializeLoggingAndCounters() {
logger_ = new Logger(this); logger_ = new Logger(this);
} }
if (counters_ == NULL) { if (counters_ == NULL) {
counters_ = new Counters; counters_ = new Counters(this);
} }
} }
......
...@@ -32,58 +32,48 @@ ...@@ -32,58 +32,48 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
Counters::Counters() { Counters::Counters(Isolate* isolate) {
#define HT(name, caption) \ #define HT(name, caption) \
HistogramTimer name = { {#caption, 0, 10000, 50, NULL, false}, 0, 0 }; \ name##_ = HistogramTimer(#caption, 0, 10000, 50, isolate);
name##_ = name;
HISTOGRAM_TIMER_LIST(HT) HISTOGRAM_TIMER_LIST(HT)
#undef HT #undef HT
#define HP(name, caption) \ #define HP(name, caption) \
Histogram name = { #caption, 0, 101, 100, NULL, false }; \ name##_ = Histogram(#caption, 0, 101, 100, isolate);
name##_ = name;
HISTOGRAM_PERCENTAGE_LIST(HP) HISTOGRAM_PERCENTAGE_LIST(HP)
#undef HP #undef HP
#define HM(name, caption) \ #define HM(name, caption) \
Histogram name = { #caption, 1000, 500000, 50, NULL, false }; \ name##_ = Histogram(#caption, 1000, 500000, 50, isolate);
name##_ = name;
HISTOGRAM_MEMORY_LIST(HM) HISTOGRAM_MEMORY_LIST(HM)
#undef HM #undef HM
#define SC(name, caption) \ #define SC(name, caption) \
StatsCounter name = { "c:" #caption, NULL, false };\ name##_ = StatsCounter("c:" #caption);
name##_ = name;
STATS_COUNTER_LIST_1(SC) STATS_COUNTER_LIST_1(SC)
STATS_COUNTER_LIST_2(SC) STATS_COUNTER_LIST_2(SC)
#undef SC #undef SC
#define SC(name) \ #define SC(name) \
StatsCounter count_of_##name = { "c:" "V8.CountOf_" #name, NULL, false };\ count_of_##name##_ = StatsCounter("c:" "V8.CountOf_" #name); \
count_of_##name##_ = count_of_##name; \ size_of_##name##_ = StatsCounter("c:" "V8.SizeOf_" #name);
StatsCounter size_of_##name = { "c:" "V8.SizeOf_" #name, NULL, false };\
size_of_##name##_ = size_of_##name;
INSTANCE_TYPE_LIST(SC) INSTANCE_TYPE_LIST(SC)
#undef SC #undef SC
#define SC(name) \ #define SC(name) \
StatsCounter count_of_CODE_TYPE_##name = { \ count_of_CODE_TYPE_##name##_ = \
"c:" "V8.CountOf_CODE_TYPE-" #name, NULL, false }; \ StatsCounter("c:" "V8.CountOf_CODE_TYPE-" #name); \
count_of_CODE_TYPE_##name##_ = count_of_CODE_TYPE_##name; \ size_of_CODE_TYPE_##name##_ = \
StatsCounter size_of_CODE_TYPE_##name = { \ StatsCounter("c:" "V8.SizeOf_CODE_TYPE-" #name);
"c:" "V8.SizeOf_CODE_TYPE-" #name, NULL, false }; \
size_of_CODE_TYPE_##name##_ = size_of_CODE_TYPE_##name;
CODE_KIND_LIST(SC) CODE_KIND_LIST(SC)
#undef SC #undef SC
#define SC(name) \ #define SC(name) \
StatsCounter count_of_FIXED_ARRAY_##name = { \ count_of_FIXED_ARRAY_##name##_ = \
"c:" "V8.CountOf_FIXED_ARRAY-" #name, NULL, false }; \ StatsCounter("c:" "V8.CountOf_FIXED_ARRAY-" #name); \
count_of_FIXED_ARRAY_##name##_ = count_of_FIXED_ARRAY_##name; \ size_of_FIXED_ARRAY_##name##_ = \
StatsCounter size_of_FIXED_ARRAY_##name = { \ StatsCounter("c:" "V8.SizeOf_FIXED_ARRAY-" #name); \
"c:" "V8.SizeOf_FIXED_ARRAY-" #name, NULL, false }; \
size_of_FIXED_ARRAY_##name##_ = size_of_FIXED_ARRAY_##name;
FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
#undef SC #undef SC
} }
......
...@@ -420,6 +420,8 @@ class Counters { ...@@ -420,6 +420,8 @@ class Counters {
friend class Isolate; friend class Isolate;
explicit Counters(Isolate* isolate);
DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment