Rescale histogram timers.

R=vogelheim@chromium.org

Review URL: https://codereview.chromium.org/875873002

Cr-Commit-Position: refs/heads/master@{#26295}
This commit is contained in:
yangguo 2015-01-27 06:08:15 -08:00 committed by Commit bot
parent 59a02ebdbe
commit 22421bbe9f
3 changed files with 49 additions and 40 deletions

View File

@ -47,8 +47,11 @@ void HistogramTimer::Start() {
// Stop the timer and record the results. // Stop the timer and record the results.
void HistogramTimer::Stop() { void HistogramTimer::Stop() {
if (Enabled()) { if (Enabled()) {
// Compute the delta between start and stop, in milliseconds. int64_t sample = resolution_ == MICROSECOND
AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds())); ? timer_.Elapsed().InMicroseconds()
: timer_.Elapsed().InMilliseconds();
// Compute the delta between start and stop, in microseconds.
AddSample(static_cast<int>(sample));
timer_.Stop(); timer_.Stop();
} }
Logger::CallEventLogger(isolate(), name(), Logger::END, true); Logger::CallEventLogger(isolate(), name(), Logger::END, true);
@ -61,13 +64,13 @@ Counters::Counters(Isolate* isolate) {
HISTOGRAM_RANGE_LIST(HR) HISTOGRAM_RANGE_LIST(HR)
#undef HR #undef HR
#define HT(name, caption) \ #define HT(name, caption, max, res) \
name##_ = HistogramTimer(#caption, 0, 10000, 50, isolate); name##_ = HistogramTimer(#caption, 0, max, HistogramTimer::res, 50, isolate);
HISTOGRAM_TIMER_LIST(HT) HISTOGRAM_TIMER_LIST(HT)
#undef HT #undef HT
#define AHT(name, caption) \ #define AHT(name, caption) \
name##_ = AggregatableHistogramTimer(#caption, 0, 10000, 50, isolate); name##_ = AggregatableHistogramTimer(#caption, 0, 10000000, 50, isolate);
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
#undef AHT #undef AHT
@ -157,7 +160,7 @@ void Counters::ResetHistograms() {
HISTOGRAM_RANGE_LIST(HR) HISTOGRAM_RANGE_LIST(HR)
#undef HR #undef HR
#define HT(name, caption) name##_.Reset(); #define HT(name, caption, max, res) name##_.Reset();
HISTOGRAM_TIMER_LIST(HT) HISTOGRAM_TIMER_LIST(HT)
#undef HT #undef HT

View File

@ -224,13 +224,16 @@ class Histogram {
// A HistogramTimer allows distributions of results to be created. // A HistogramTimer allows distributions of results to be created.
class HistogramTimer : public Histogram { class HistogramTimer : public Histogram {
public: public:
HistogramTimer() { } enum Resolution {
HistogramTimer(const char* name, MILLISECOND,
int min, MICROSECOND
int max, };
int num_buckets,
Isolate* isolate) HistogramTimer() {}
: Histogram(name, min, max, num_buckets, isolate) {} HistogramTimer(const char* name, int min, int max, Resolution resolution,
int num_buckets, Isolate* isolate)
: Histogram(name, min, max, num_buckets, isolate),
resolution_(resolution) {}
// Start the timer. // Start the timer.
void Start(); void Start();
@ -250,6 +253,7 @@ class HistogramTimer : public Histogram {
private: private:
base::ElapsedTimer timer_; base::ElapsedTimer timer_;
Resolution resolution_;
}; };
// Helper class for scoping a HistogramTimer. // Helper class for scoping a HistogramTimer.
@ -315,7 +319,7 @@ class AggregatableHistogramTimer : public Histogram {
// Start/stop the "outer" scope. // Start/stop the "outer" scope.
void Start() { time_ = base::TimeDelta(); } void Start() { time_ = base::TimeDelta(); }
void Stop() { AddSample(static_cast<int>(time_.InMilliseconds())); } void Stop() { AddSample(static_cast<int>(time_.InMicroseconds())); }
// Add a time value ("inner" scope). // Add a time value ("inner" scope).
void Add(base::TimeDelta other) { time_ += other; } void Add(base::TimeDelta other) { time_ += other; }
@ -360,30 +364,33 @@ class AggregatedHistogramTimerScope {
HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \
HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, 101) HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, 101)
#define HISTOGRAM_TIMER_LIST(HT) \ #define HISTOGRAM_TIMER_LIST(HT) \
/* Garbage collection timers. */ \ /* Garbage collection timers. */ \
HT(gc_compactor, V8.GCCompactor) \ HT(gc_compactor, V8.GCCompactor, 10000, MILLISECOND) \
HT(gc_scavenger, V8.GCScavenger) \ HT(gc_scavenger, V8.GCScavenger, 10000, MILLISECOND) \
HT(gc_context, V8.GCContext) /* GC context cleanup time */ \ HT(gc_context, V8.GCContext, 10000, \
HT(gc_idle_notification, V8.GCIdleNotification) \ MILLISECOND) /* GC context cleanup time */ \
HT(gc_incremental_marking, V8.GCIncrementalMarking) \ HT(gc_idle_notification, V8.GCIdleNotification, 10000, MILLISECOND) \
HT(gc_low_memory_notification, V8.GCLowMemoryNotification) \ HT(gc_incremental_marking, V8.GCIncrementalMarking, 10000, MILLISECOND) \
/* Parsing timers. */ \ HT(gc_low_memory_notification, V8.GCLowMemoryNotification, 10000, \
HT(parse, V8.Parse) \ MILLISECOND) \
HT(parse_lazy, V8.ParseLazy) \ /* Parsing timers. */ \
HT(pre_parse, V8.PreParse) \ HT(parse, V8.ParseMicroSeconds, 1000000, MICROSECOND) \
/* Compilation times. */ \ HT(parse_lazy, V8.ParseLazyMicroSeconds, 1000000, MICROSECOND) \
HT(compile, V8.Compile) \ HT(pre_parse, V8.PreParseMicroSeconds, 1000000, MICROSECOND) \
HT(compile_eval, V8.CompileEval) \ /* Compilation times. */ \
/* Serialization as part of compilation (code caching) */ \ HT(compile, V8.CompileMicroSeconds, 1000000, MICROSECOND) \
HT(compile_serialize, V8.CompileSerialize) \ HT(compile_eval, V8.CompileEvalMicroSeconds, 1000000, MICROSECOND) \
HT(compile_deserialize, V8.CompileDeserialize) \ /* Serialization as part of compilation (code caching) */ \
/* Total compilation time incl. caching/parsing */ \ HT(compile_serialize, V8.CompileSerializeMicroSeconds, 100000, MICROSECOND) \
HT(compile_script, V8.CompileScript) HT(compile_deserialize, V8.CompileDeserializeMicroSeconds, 1000000, \
MICROSECOND) \
/* Total compilation time incl. caching/parsing */ \
HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND)
#define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \
AHT(compile_lazy, V8.CompileLazy) AHT(compile_lazy, V8.CompileLazyMicroSeconds)
#define HISTOGRAM_PERCENTAGE_LIST(HP) \ #define HISTOGRAM_PERCENTAGE_LIST(HP) \
@ -631,7 +638,7 @@ class Counters {
HISTOGRAM_RANGE_LIST(HR) HISTOGRAM_RANGE_LIST(HR)
#undef HR #undef HR
#define HT(name, caption) \ #define HT(name, caption, max, res) \
HistogramTimer* name() { return &name##_; } HistogramTimer* name() { return &name##_; }
HISTOGRAM_TIMER_LIST(HT) HISTOGRAM_TIMER_LIST(HT)
#undef HT #undef HT
@ -688,7 +695,7 @@ class Counters {
#undef SC #undef SC
enum Id { enum Id {
#define RATE_ID(name, caption) k_##name, #define RATE_ID(name, caption, max, res) k_##name,
HISTOGRAM_TIMER_LIST(RATE_ID) HISTOGRAM_TIMER_LIST(RATE_ID)
#undef RATE_ID #undef RATE_ID
#define AGGREGATABLE_ID(name, caption) k_##name, #define AGGREGATABLE_ID(name, caption) k_##name,
@ -730,8 +737,7 @@ class Counters {
HISTOGRAM_RANGE_LIST(HR) HISTOGRAM_RANGE_LIST(HR)
#undef HR #undef HR
#define HT(name, caption) \ #define HT(name, caption, max, res) HistogramTimer name##_;
HistogramTimer name##_;
HISTOGRAM_TIMER_LIST(HT) HISTOGRAM_TIMER_LIST(HT)
#undef HT #undef HT

View File

@ -23649,7 +23649,7 @@ TEST(EventLogging) {
v8::Isolate* isolate = CcTest::isolate(); v8::Isolate* isolate = CcTest::isolate();
isolate->SetEventLogger(StoringEventLoggerCallback); isolate->SetEventLogger(StoringEventLoggerCallback);
v8::internal::HistogramTimer histogramTimer( v8::internal::HistogramTimer histogramTimer(
"V8.Test", 0, 10000, 50, "V8.Test", 0, 10000, v8::internal::HistogramTimer::MILLISECOND, 50,
reinterpret_cast<v8::internal::Isolate*>(isolate)); reinterpret_cast<v8::internal::Isolate*>(isolate));
histogramTimer.Start(); histogramTimer.Start();
CHECK_EQ("V8.Test", last_event_message); CHECK_EQ("V8.Test", last_event_message);