2012-07-13 12:12:09 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/counters.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2016-02-11 12:30:06 +00:00
|
|
|
#include <iomanip>
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/isolate.h"
|
2014-10-14 14:45:03 +00:00
|
|
|
#include "src/log-inl.h"
|
2016-06-10 09:16:03 +00:00
|
|
|
#include "src/log.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
StatsTable::StatsTable()
|
|
|
|
: lookup_function_(NULL),
|
|
|
|
create_histogram_function_(NULL),
|
|
|
|
add_histogram_sample_function_(NULL) {}
|
|
|
|
|
|
|
|
|
|
|
|
int* StatsCounter::FindLocationInStatsTable() const {
|
2013-09-03 06:57:16 +00:00
|
|
|
return isolate_->stats_table()->FindLocation(name_);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-07-13 12:12:09 +00:00
|
|
|
void Histogram::AddSample(int sample) {
|
|
|
|
if (Enabled()) {
|
2013-04-24 13:52:26 +00:00
|
|
|
isolate()->stats_table()->AddHistogramSample(histogram_, sample);
|
2012-07-13 12:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void* Histogram::CreateHistogram() const {
|
2013-04-24 13:52:26 +00:00
|
|
|
return isolate()->stats_table()->
|
2012-07-13 12:12:09 +00:00
|
|
|
CreateHistogram(name_, min_, max_, num_buckets_);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2009-03-13 16:06:31 +00:00
|
|
|
// Start the timer.
|
|
|
|
void HistogramTimer::Start() {
|
2013-04-24 13:52:26 +00:00
|
|
|
if (Enabled()) {
|
2013-08-29 09:15:13 +00:00
|
|
|
timer_.Start();
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
2014-10-14 14:45:03 +00:00
|
|
|
Logger::CallEventLogger(isolate(), name(), Logger::START, true);
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2009-03-13 16:06:31 +00:00
|
|
|
// Stop the timer and record the results.
|
|
|
|
void HistogramTimer::Stop() {
|
2013-04-24 13:52:26 +00:00
|
|
|
if (Enabled()) {
|
2015-01-27 14:08:15 +00:00
|
|
|
int64_t sample = resolution_ == MICROSECOND
|
|
|
|
? timer_.Elapsed().InMicroseconds()
|
|
|
|
: timer_.Elapsed().InMilliseconds();
|
|
|
|
// Compute the delta between start and stop, in microseconds.
|
|
|
|
AddSample(static_cast<int>(sample));
|
2013-08-29 09:15:13 +00:00
|
|
|
timer_.Stop();
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
2014-10-14 14:45:03 +00:00
|
|
|
Logger::CallEventLogger(isolate(), name(), Logger::END, true);
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 07:15:24 +00:00
|
|
|
|
|
|
|
Counters::Counters(Isolate* isolate) {
|
2014-07-28 09:13:33 +00:00
|
|
|
#define HR(name, caption, min, max, num_buckets) \
|
|
|
|
name##_ = Histogram(#caption, min, max, num_buckets, isolate);
|
|
|
|
HISTOGRAM_RANGE_LIST(HR)
|
|
|
|
#undef HR
|
|
|
|
|
2015-01-27 14:08:15 +00:00
|
|
|
#define HT(name, caption, max, res) \
|
|
|
|
name##_ = HistogramTimer(#caption, 0, max, HistogramTimer::res, 50, isolate);
|
2014-05-07 07:15:24 +00:00
|
|
|
HISTOGRAM_TIMER_LIST(HT)
|
|
|
|
#undef HT
|
|
|
|
|
2015-01-22 18:38:19 +00:00
|
|
|
#define AHT(name, caption) \
|
2015-01-27 14:08:15 +00:00
|
|
|
name##_ = AggregatableHistogramTimer(#caption, 0, 10000000, 50, isolate);
|
2015-01-22 18:38:19 +00:00
|
|
|
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
|
|
|
|
#undef AHT
|
|
|
|
|
2014-05-07 07:15:24 +00:00
|
|
|
#define HP(name, caption) \
|
|
|
|
name##_ = Histogram(#caption, 0, 101, 100, isolate);
|
|
|
|
HISTOGRAM_PERCENTAGE_LIST(HP)
|
|
|
|
#undef HP
|
|
|
|
|
2015-05-07 10:03:35 +00:00
|
|
|
|
|
|
|
// Exponential histogram assigns bucket limits to points
|
|
|
|
// p[1], p[2], ... p[n] such that p[i+1] / p[i] = constant.
|
|
|
|
// The constant factor is equal to the n-th root of (high / low),
|
|
|
|
// where the n is the number of buckets, the low is the lower limit,
|
|
|
|
// the high is the upper limit.
|
|
|
|
// For n = 50, low = 1000, high = 500000: the factor = 1.13.
|
2014-05-07 07:15:24 +00:00
|
|
|
#define HM(name, caption) \
|
|
|
|
name##_ = Histogram(#caption, 1000, 500000, 50, isolate);
|
2015-05-07 10:03:35 +00:00
|
|
|
HISTOGRAM_LEGACY_MEMORY_LIST(HM)
|
|
|
|
#undef HM
|
|
|
|
// For n = 100, low = 4000, high = 2000000: the factor = 1.06.
|
|
|
|
#define HM(name, caption) \
|
|
|
|
name##_ = Histogram(#caption, 4000, 2000000, 100, isolate);
|
|
|
|
HISTOGRAM_MEMORY_LIST(HM)
|
|
|
|
#undef HM
|
|
|
|
|
|
|
|
#define HM(name, caption) \
|
|
|
|
aggregated_##name##_ = AggregatedMemoryHistogram<Histogram>(&name##_);
|
2014-05-07 07:15:24 +00:00
|
|
|
HISTOGRAM_MEMORY_LIST(HM)
|
|
|
|
#undef HM
|
|
|
|
|
|
|
|
#define SC(name, caption) \
|
|
|
|
name##_ = StatsCounter(isolate, "c:" #caption);
|
|
|
|
|
|
|
|
STATS_COUNTER_LIST_1(SC)
|
|
|
|
STATS_COUNTER_LIST_2(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_##name##_ = StatsCounter(isolate, "c:" "V8.CountOf_" #name); \
|
|
|
|
size_of_##name##_ = StatsCounter(isolate, "c:" "V8.SizeOf_" #name);
|
|
|
|
INSTANCE_TYPE_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_CODE_TYPE_##name##_ = \
|
|
|
|
StatsCounter(isolate, "c:" "V8.CountOf_CODE_TYPE-" #name); \
|
|
|
|
size_of_CODE_TYPE_##name##_ = \
|
|
|
|
StatsCounter(isolate, "c:" "V8.SizeOf_CODE_TYPE-" #name);
|
|
|
|
CODE_KIND_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_FIXED_ARRAY_##name##_ = \
|
|
|
|
StatsCounter(isolate, "c:" "V8.CountOf_FIXED_ARRAY-" #name); \
|
|
|
|
size_of_FIXED_ARRAY_##name##_ = \
|
|
|
|
StatsCounter(isolate, "c:" "V8.SizeOf_FIXED_ARRAY-" #name);
|
|
|
|
FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_CODE_AGE_##name##_ = \
|
|
|
|
StatsCounter(isolate, "c:" "V8.CountOf_CODE_AGE-" #name); \
|
|
|
|
size_of_CODE_AGE_##name##_ = \
|
|
|
|
StatsCounter(isolate, "c:" "V8.SizeOf_CODE_AGE-" #name);
|
|
|
|
CODE_AGE_LIST_COMPLETE(SC)
|
|
|
|
#undef SC
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-07 07:19:46 +00:00
|
|
|
void Counters::ResetCounters() {
|
|
|
|
#define SC(name, caption) name##_.Reset();
|
|
|
|
STATS_COUNTER_LIST_1(SC)
|
|
|
|
STATS_COUNTER_LIST_2(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_##name##_.Reset(); \
|
|
|
|
size_of_##name##_.Reset();
|
|
|
|
INSTANCE_TYPE_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_CODE_TYPE_##name##_.Reset(); \
|
|
|
|
size_of_CODE_TYPE_##name##_.Reset();
|
|
|
|
CODE_KIND_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_FIXED_ARRAY_##name##_.Reset(); \
|
|
|
|
size_of_FIXED_ARRAY_##name##_.Reset();
|
|
|
|
FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
|
|
|
|
#define SC(name) \
|
|
|
|
count_of_CODE_AGE_##name##_.Reset(); \
|
|
|
|
size_of_CODE_AGE_##name##_.Reset();
|
|
|
|
CODE_AGE_LIST_COMPLETE(SC)
|
|
|
|
#undef SC
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-07 07:15:24 +00:00
|
|
|
void Counters::ResetHistograms() {
|
2014-07-28 09:13:33 +00:00
|
|
|
#define HR(name, caption, min, max, num_buckets) name##_.Reset();
|
|
|
|
HISTOGRAM_RANGE_LIST(HR)
|
|
|
|
#undef HR
|
|
|
|
|
2015-01-27 14:08:15 +00:00
|
|
|
#define HT(name, caption, max, res) name##_.Reset();
|
2014-05-07 07:15:24 +00:00
|
|
|
HISTOGRAM_TIMER_LIST(HT)
|
|
|
|
#undef HT
|
|
|
|
|
2015-01-22 18:38:19 +00:00
|
|
|
#define AHT(name, caption) name##_.Reset();
|
|
|
|
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
|
|
|
|
#undef AHT
|
|
|
|
|
2014-05-07 07:15:24 +00:00
|
|
|
#define HP(name, caption) name##_.Reset();
|
|
|
|
HISTOGRAM_PERCENTAGE_LIST(HP)
|
|
|
|
#undef HP
|
|
|
|
|
|
|
|
#define HM(name, caption) name##_.Reset();
|
2015-05-07 10:03:35 +00:00
|
|
|
HISTOGRAM_LEGACY_MEMORY_LIST(HM)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef HM
|
|
|
|
}
|
|
|
|
|
2016-02-11 12:30:06 +00:00
|
|
|
class RuntimeCallStatEntries {
|
|
|
|
public:
|
|
|
|
void Print(std::ostream& os) {
|
2016-02-23 08:45:52 +00:00
|
|
|
if (total_call_count == 0) return;
|
|
|
|
std::sort(entries.rbegin(), entries.rend());
|
2016-05-30 11:30:29 +00:00
|
|
|
os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(12)
|
2016-02-23 08:45:52 +00:00
|
|
|
<< "Time" << std::setw(18) << "Count" << std::endl
|
2016-05-30 11:30:29 +00:00
|
|
|
<< std::string(88, '=') << std::endl;
|
2016-02-23 08:45:52 +00:00
|
|
|
for (Entry& entry : entries) {
|
|
|
|
entry.SetTotal(total_time, total_call_count);
|
|
|
|
entry.Print(os);
|
2016-02-11 12:30:06 +00:00
|
|
|
}
|
2016-05-30 11:30:29 +00:00
|
|
|
os << std::string(88, '-') << std::endl;
|
2016-02-23 08:45:52 +00:00
|
|
|
Entry("Total", total_time, total_call_count).Print(os);
|
2016-02-11 12:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 15:29:17 +00:00
|
|
|
// By default, the compiler will usually inline this, which results in a large
|
|
|
|
// binary size increase: std::vector::push_back expands to a large amount of
|
|
|
|
// instructions, and this function is invoked repeatedly by macros.
|
|
|
|
V8_NOINLINE void Add(RuntimeCallCounter* counter) {
|
2016-02-23 08:45:52 +00:00
|
|
|
if (counter->count == 0) return;
|
|
|
|
entries.push_back(Entry(counter->name, counter->time, counter->count));
|
|
|
|
total_time += counter->time;
|
|
|
|
total_call_count += counter->count;
|
2016-02-11 12:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Entry {
|
|
|
|
public:
|
|
|
|
Entry(const char* name, base::TimeDelta time, uint64_t count)
|
|
|
|
: name_(name),
|
2016-05-30 11:30:29 +00:00
|
|
|
time_(time.InMicroseconds()),
|
2016-02-11 12:30:06 +00:00
|
|
|
count_(count),
|
|
|
|
time_percent_(100),
|
|
|
|
count_percent_(100) {}
|
|
|
|
|
|
|
|
bool operator<(const Entry& other) const {
|
|
|
|
if (time_ < other.time_) return true;
|
|
|
|
if (time_ > other.time_) return false;
|
|
|
|
return count_ < other.count_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Print(std::ostream& os) {
|
|
|
|
os.precision(2);
|
2016-05-30 11:30:29 +00:00
|
|
|
os << std::fixed << std::setprecision(2);
|
2016-02-11 12:30:06 +00:00
|
|
|
os << std::setw(50) << name_;
|
2016-05-30 11:30:29 +00:00
|
|
|
os << std::setw(10) << static_cast<double>(time_) / 1000 << "ms ";
|
2016-02-11 12:30:06 +00:00
|
|
|
os << std::setw(6) << time_percent_ << "%";
|
|
|
|
os << std::setw(10) << count_ << " ";
|
|
|
|
os << std::setw(6) << count_percent_ << "%";
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTotal(base::TimeDelta total_time, uint64_t total_count) {
|
2016-05-30 11:30:29 +00:00
|
|
|
if (total_time.InMicroseconds() == 0) {
|
2016-02-23 08:45:52 +00:00
|
|
|
time_percent_ = 0;
|
|
|
|
} else {
|
2016-05-30 11:30:29 +00:00
|
|
|
time_percent_ = 100.0 * time_ / total_time.InMicroseconds();
|
2016-02-23 08:45:52 +00:00
|
|
|
}
|
2016-02-11 12:30:06 +00:00
|
|
|
count_percent_ = 100.0 * count_ / total_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* name_;
|
|
|
|
int64_t time_;
|
|
|
|
uint64_t count_;
|
|
|
|
double time_percent_;
|
|
|
|
double count_percent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint64_t total_call_count = 0;
|
|
|
|
base::TimeDelta total_time;
|
|
|
|
std::vector<Entry> entries;
|
|
|
|
};
|
|
|
|
|
2016-02-11 14:47:02 +00:00
|
|
|
void RuntimeCallCounter::Reset() {
|
|
|
|
count = 0;
|
|
|
|
time = base::TimeDelta();
|
|
|
|
}
|
|
|
|
|
2016-05-11 08:49:33 +00:00
|
|
|
// static
|
|
|
|
void RuntimeCallStats::Enter(Isolate* isolate, RuntimeCallTimer* timer,
|
|
|
|
CounterId counter_id) {
|
|
|
|
RuntimeCallStats* stats = isolate->counters()->runtime_call_stats();
|
|
|
|
RuntimeCallCounter* counter = &(stats->*counter_id);
|
|
|
|
timer->Start(counter, stats->current_timer_);
|
|
|
|
stats->current_timer_ = timer;
|
2016-02-23 08:45:52 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 08:49:33 +00:00
|
|
|
// static
|
|
|
|
void RuntimeCallStats::Leave(Isolate* isolate, RuntimeCallTimer* timer) {
|
|
|
|
RuntimeCallStats* stats = isolate->counters()->runtime_call_stats();
|
2016-06-13 12:11:48 +00:00
|
|
|
|
|
|
|
if (stats->current_timer_ == timer) {
|
|
|
|
stats->current_timer_ = timer->Stop();
|
|
|
|
} else {
|
|
|
|
// Must be a Threading cctest. Walk the chain of Timers to find the
|
|
|
|
// buried one that's leaving. We don't care about keeping nested timings
|
|
|
|
// accurate, just avoid crashing by keeping the chain intact.
|
|
|
|
RuntimeCallTimer* next = stats->current_timer_;
|
|
|
|
while (next->parent_ != timer) next = next->parent_;
|
|
|
|
next->parent_ = timer->Stop();
|
|
|
|
}
|
2016-02-11 14:47:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 12:37:22 +00:00
|
|
|
// static
|
|
|
|
void RuntimeCallStats::CorrectCurrentCounterId(Isolate* isolate,
|
|
|
|
CounterId counter_id) {
|
|
|
|
RuntimeCallStats* stats = isolate->counters()->runtime_call_stats();
|
|
|
|
DCHECK_NOT_NULL(stats->current_timer_);
|
|
|
|
RuntimeCallCounter* counter = &(stats->*counter_id);
|
|
|
|
stats->current_timer_->counter_ = counter;
|
|
|
|
}
|
|
|
|
|
2016-02-11 12:30:06 +00:00
|
|
|
void RuntimeCallStats::Print(std::ostream& os) {
|
|
|
|
RuntimeCallStatEntries entries;
|
|
|
|
|
2016-05-11 12:59:46 +00:00
|
|
|
#define PRINT_COUNTER(name) entries.Add(&this->name);
|
|
|
|
FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER)
|
|
|
|
#undef PRINT_COUNTER
|
|
|
|
|
2016-02-23 08:45:52 +00:00
|
|
|
#define PRINT_COUNTER(name, nargs, ressize) entries.Add(&this->Runtime_##name);
|
2016-02-11 12:30:06 +00:00
|
|
|
FOR_EACH_INTRINSIC(PRINT_COUNTER)
|
|
|
|
#undef PRINT_COUNTER
|
2016-02-23 08:45:52 +00:00
|
|
|
|
2016-07-14 12:45:56 +00:00
|
|
|
#define PRINT_COUNTER(name) entries.Add(&this->Builtin_##name);
|
2016-02-11 12:30:06 +00:00
|
|
|
BUILTIN_LIST_C(PRINT_COUNTER)
|
|
|
|
#undef PRINT_COUNTER
|
2016-02-23 08:45:52 +00:00
|
|
|
|
2016-05-13 15:53:27 +00:00
|
|
|
#define PRINT_COUNTER(name) entries.Add(&this->API_##name);
|
|
|
|
FOR_EACH_API_COUNTER(PRINT_COUNTER)
|
|
|
|
#undef PRINT_COUNTER
|
|
|
|
|
2016-05-11 12:37:22 +00:00
|
|
|
#define PRINT_COUNTER(name) entries.Add(&this->Handler_##name);
|
|
|
|
FOR_EACH_HANDLER_COUNTER(PRINT_COUNTER)
|
|
|
|
#undef PRINT_COUNTER
|
|
|
|
|
2016-02-11 12:30:06 +00:00
|
|
|
entries.Print(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuntimeCallStats::Reset() {
|
2016-02-29 19:11:58 +00:00
|
|
|
if (!FLAG_runtime_call_stats) return;
|
2016-05-13 15:53:27 +00:00
|
|
|
#define RESET_COUNTER(name) this->name.Reset();
|
|
|
|
FOR_EACH_MANUAL_COUNTER(RESET_COUNTER)
|
|
|
|
#undef RESET_COUNTER
|
|
|
|
|
|
|
|
#define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset();
|
2016-02-11 12:30:06 +00:00
|
|
|
FOR_EACH_INTRINSIC(RESET_COUNTER)
|
|
|
|
#undef RESET_COUNTER
|
2016-05-13 15:53:27 +00:00
|
|
|
|
2016-07-14 12:45:56 +00:00
|
|
|
#define RESET_COUNTER(name) this->Builtin_##name.Reset();
|
2016-02-11 12:30:06 +00:00
|
|
|
BUILTIN_LIST_C(RESET_COUNTER)
|
|
|
|
#undef RESET_COUNTER
|
2016-05-13 15:53:27 +00:00
|
|
|
|
|
|
|
#define RESET_COUNTER(name) this->API_##name.Reset();
|
|
|
|
FOR_EACH_API_COUNTER(RESET_COUNTER)
|
|
|
|
#undef RESET_COUNTER
|
|
|
|
|
|
|
|
#define RESET_COUNTER(name) this->Handler_##name.Reset();
|
|
|
|
FOR_EACH_HANDLER_COUNTER(RESET_COUNTER)
|
|
|
|
#undef RESET_COUNTER
|
2016-02-11 12:30:06 +00:00
|
|
|
}
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|