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"
|
2017-03-29 09:56:08 +00:00
|
|
|
#include "src/builtins/builtins-definitions.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
|
|
|
|
2017-05-29 18:18:25 +00:00
|
|
|
StatsTable::StatsTable(Counters* counters)
|
2017-10-13 16:33:03 +00:00
|
|
|
: lookup_function_(nullptr),
|
|
|
|
create_histogram_function_(nullptr),
|
|
|
|
add_histogram_sample_function_(nullptr) {}
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2017-05-29 18:18:25 +00:00
|
|
|
void StatsTable::SetCounterFunction(CounterLookupCallback f) {
|
2017-05-24 21:21:04 +00:00
|
|
|
lookup_function_ = f;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2017-05-24 21:21:04 +00:00
|
|
|
int* StatsCounterBase::FindLocationInStatsTable() const {
|
2017-06-08 16:18:32 +00:00
|
|
|
return counters_->FindLocation(name_);
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
|
|
|
|
2017-05-29 18:18:25 +00:00
|
|
|
StatsCounterThreadSafe::StatsCounterThreadSafe(Counters* counters,
|
2017-05-24 21:21:04 +00:00
|
|
|
const char* name)
|
2017-06-08 16:18:32 +00:00
|
|
|
: StatsCounterBase(counters, name) {}
|
2017-05-24 21:21:04 +00:00
|
|
|
|
|
|
|
void StatsCounterThreadSafe::Set(int Value) {
|
|
|
|
if (ptr_) {
|
|
|
|
base::LockGuard<base::Mutex> Guard(&mutex_);
|
|
|
|
SetLoc(ptr_, Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatsCounterThreadSafe::Increment() {
|
|
|
|
if (ptr_) {
|
|
|
|
base::LockGuard<base::Mutex> Guard(&mutex_);
|
|
|
|
IncrementLoc(ptr_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatsCounterThreadSafe::Increment(int value) {
|
|
|
|
if (ptr_) {
|
|
|
|
base::LockGuard<base::Mutex> Guard(&mutex_);
|
|
|
|
IncrementLoc(ptr_, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatsCounterThreadSafe::Decrement() {
|
|
|
|
if (ptr_) {
|
|
|
|
base::LockGuard<base::Mutex> Guard(&mutex_);
|
|
|
|
DecrementLoc(ptr_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatsCounterThreadSafe::Decrement(int value) {
|
|
|
|
if (ptr_) {
|
|
|
|
base::LockGuard<base::Mutex> Guard(&mutex_);
|
|
|
|
DecrementLoc(ptr_, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 12:12:09 +00:00
|
|
|
void Histogram::AddSample(int sample) {
|
|
|
|
if (Enabled()) {
|
2017-06-08 16:18:32 +00:00
|
|
|
counters_->AddHistogramSample(histogram_, sample);
|
2012-07-13 12:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void* Histogram::CreateHistogram() const {
|
2017-06-08 16:18:32 +00:00
|
|
|
return counters_->CreateHistogram(name_, min_, max_, num_buckets_);
|
2012-07-13 12:12:09 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 18:50:38 +00:00
|
|
|
void TimedHistogram::Start(base::ElapsedTimer* timer, Isolate* isolate) {
|
|
|
|
if (Enabled()) timer->Start();
|
|
|
|
if (isolate) Logger::CallEventLogger(isolate, name(), Logger::START, true);
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 18:50:38 +00:00
|
|
|
void TimedHistogram::Stop(base::ElapsedTimer* timer, Isolate* isolate) {
|
2013-04-24 13:52:26 +00:00
|
|
|
if (Enabled()) {
|
2015-01-27 14:08:15 +00:00
|
|
|
// Compute the delta between start and stop, in microseconds.
|
2017-06-27 18:50:38 +00:00
|
|
|
int64_t sample = resolution_ == HistogramTimerResolution::MICROSECOND
|
|
|
|
? timer->Elapsed().InMicroseconds()
|
|
|
|
: timer->Elapsed().InMilliseconds();
|
|
|
|
timer->Stop();
|
2015-01-27 14:08:15 +00:00
|
|
|
AddSample(static_cast<int>(sample));
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
2017-06-27 18:50:38 +00:00
|
|
|
if (isolate != nullptr) {
|
|
|
|
Logger::CallEventLogger(isolate, name(), Logger::END, true);
|
|
|
|
}
|
2009-03-13 16:06:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 21:21:04 +00:00
|
|
|
Counters::Counters(Isolate* isolate)
|
2017-05-29 18:18:25 +00:00
|
|
|
: isolate_(isolate),
|
|
|
|
stats_table_(this),
|
2017-05-24 21:21:04 +00:00
|
|
|
// clang format off
|
2017-05-29 18:18:25 +00:00
|
|
|
#define SC(name, caption) name##_(this, "c:" #caption),
|
2017-05-24 21:21:04 +00:00
|
|
|
STATS_COUNTER_TS_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
// clang format on
|
|
|
|
runtime_call_stats_() {
|
2017-03-21 19:31:14 +00:00
|
|
|
static const struct {
|
|
|
|
Histogram Counters::*member;
|
|
|
|
const char* caption;
|
|
|
|
int min;
|
|
|
|
int max;
|
|
|
|
int num_buckets;
|
|
|
|
} kHistograms[] = {
|
2014-07-28 09:13:33 +00:00
|
|
|
#define HR(name, caption, min, max, num_buckets) \
|
2017-03-21 19:31:14 +00:00
|
|
|
{&Counters::name##_, #caption, min, max, num_buckets},
|
|
|
|
HISTOGRAM_RANGE_LIST(HR)
|
2014-07-28 09:13:33 +00:00
|
|
|
#undef HR
|
2017-03-21 19:31:14 +00:00
|
|
|
};
|
|
|
|
for (const auto& histogram : kHistograms) {
|
|
|
|
this->*histogram.member =
|
|
|
|
Histogram(histogram.caption, histogram.min, histogram.max,
|
2017-05-29 18:18:25 +00:00
|
|
|
histogram.num_buckets, this);
|
2017-03-21 19:31:14 +00:00
|
|
|
}
|
2014-07-28 09:13:33 +00:00
|
|
|
|
2017-06-27 18:50:38 +00:00
|
|
|
const int DefaultTimedHistogramNumBuckets = 50;
|
|
|
|
|
2017-03-21 19:31:14 +00:00
|
|
|
static const struct {
|
|
|
|
HistogramTimer Counters::*member;
|
|
|
|
const char* caption;
|
|
|
|
int max;
|
2017-06-27 18:50:38 +00:00
|
|
|
HistogramTimerResolution res;
|
2017-03-21 19:31:14 +00:00
|
|
|
} kHistogramTimers[] = {
|
2015-01-27 14:08:15 +00:00
|
|
|
#define HT(name, caption, max, res) \
|
2017-06-27 18:50:38 +00:00
|
|
|
{&Counters::name##_, #caption, max, HistogramTimerResolution::res},
|
2017-03-21 19:31:14 +00:00
|
|
|
HISTOGRAM_TIMER_LIST(HT)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef HT
|
2017-03-21 19:31:14 +00:00
|
|
|
};
|
|
|
|
for (const auto& timer : kHistogramTimers) {
|
2017-06-27 18:50:38 +00:00
|
|
|
this->*timer.member = HistogramTimer(timer.caption, 0, timer.max, timer.res,
|
|
|
|
DefaultTimedHistogramNumBuckets, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
TimedHistogram Counters::*member;
|
|
|
|
const char* caption;
|
|
|
|
int max;
|
|
|
|
HistogramTimerResolution res;
|
|
|
|
} kTimedHistograms[] = {
|
|
|
|
#define HT(name, caption, max, res) \
|
|
|
|
{&Counters::name##_, #caption, max, HistogramTimerResolution::res},
|
|
|
|
TIMED_HISTOGRAM_LIST(HT)
|
|
|
|
#undef HT
|
|
|
|
};
|
|
|
|
for (const auto& timer : kTimedHistograms) {
|
|
|
|
this->*timer.member = TimedHistogram(timer.caption, 0, timer.max, timer.res,
|
|
|
|
DefaultTimedHistogramNumBuckets, this);
|
2017-03-21 19:31:14 +00:00
|
|
|
}
|
2014-05-07 07:15:24 +00:00
|
|
|
|
2017-03-21 19:31:14 +00:00
|
|
|
static const struct {
|
|
|
|
AggregatableHistogramTimer Counters::*member;
|
|
|
|
const char* caption;
|
|
|
|
} kAggregatableHistogramTimers[] = {
|
|
|
|
#define AHT(name, caption) {&Counters::name##_, #caption},
|
|
|
|
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
|
2015-01-22 18:38:19 +00:00
|
|
|
#undef AHT
|
2017-03-21 19:31:14 +00:00
|
|
|
};
|
|
|
|
for (const auto& aht : kAggregatableHistogramTimers) {
|
2017-06-27 18:50:38 +00:00
|
|
|
this->*aht.member = AggregatableHistogramTimer(
|
|
|
|
aht.caption, 0, 10000000, DefaultTimedHistogramNumBuckets, this);
|
2017-03-21 19:31:14 +00:00
|
|
|
}
|
2015-01-22 18:38:19 +00:00
|
|
|
|
2017-03-21 19:31:14 +00:00
|
|
|
static const struct {
|
|
|
|
Histogram Counters::*member;
|
|
|
|
const char* caption;
|
|
|
|
} kHistogramPercentages[] = {
|
|
|
|
#define HP(name, caption) {&Counters::name##_, #caption},
|
|
|
|
HISTOGRAM_PERCENTAGE_LIST(HP)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef HP
|
2017-03-21 19:31:14 +00:00
|
|
|
};
|
|
|
|
for (const auto& percentage : kHistogramPercentages) {
|
2017-05-29 18:18:25 +00:00
|
|
|
this->*percentage.member = Histogram(percentage.caption, 0, 101, 100, this);
|
2017-03-21 19:31:14 +00:00
|
|
|
}
|
2014-05-07 07:15:24 +00:00
|
|
|
|
2017-03-21 19:31:14 +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.
|
|
|
|
static const struct {
|
|
|
|
Histogram Counters::*member;
|
|
|
|
const char* caption;
|
|
|
|
} kLegacyMemoryHistograms[] = {
|
|
|
|
#define HM(name, caption) {&Counters::name##_, #caption},
|
|
|
|
HISTOGRAM_LEGACY_MEMORY_LIST(HM)
|
2015-05-07 10:03:35 +00:00
|
|
|
#undef HM
|
2017-03-21 19:31:14 +00:00
|
|
|
};
|
|
|
|
for (const auto& histogram : kLegacyMemoryHistograms) {
|
|
|
|
this->*histogram.member =
|
2017-05-29 18:18:25 +00:00
|
|
|
Histogram(histogram.caption, 1000, 500000, 50, this);
|
2017-03-21 19:31:14 +00:00
|
|
|
}
|
2015-05-07 10:03:35 +00:00
|
|
|
|
2017-03-21 19:31:14 +00:00
|
|
|
// For n = 100, low = 4000, high = 2000000: the factor = 1.06.
|
|
|
|
static const struct {
|
|
|
|
Histogram Counters::*member;
|
|
|
|
AggregatedMemoryHistogram<Histogram> Counters::*aggregated;
|
|
|
|
const char* caption;
|
|
|
|
} kMemoryHistograms[] = {
|
2015-05-07 10:03:35 +00:00
|
|
|
#define HM(name, caption) \
|
2017-03-21 19:31:14 +00:00
|
|
|
{&Counters::name##_, &Counters::aggregated_##name##_, #caption},
|
|
|
|
HISTOGRAM_MEMORY_LIST(HM)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef HM
|
2017-03-21 19:31:14 +00:00
|
|
|
};
|
|
|
|
for (const auto& histogram : kMemoryHistograms) {
|
|
|
|
this->*histogram.member =
|
2017-05-29 18:18:25 +00:00
|
|
|
Histogram(histogram.caption, 4000, 2000000, 100, this);
|
2017-03-21 19:31:14 +00:00
|
|
|
this->*histogram.aggregated =
|
|
|
|
AggregatedMemoryHistogram<Histogram>(&(this->*histogram.member));
|
|
|
|
}
|
2014-05-07 07:15:24 +00:00
|
|
|
|
2017-03-21 19:31:14 +00:00
|
|
|
// clang-format off
|
|
|
|
static const struct {
|
|
|
|
StatsCounter Counters::*member;
|
|
|
|
const char* caption;
|
|
|
|
} kStatsCounters[] = {
|
|
|
|
#define SC(name, caption) {&Counters::name##_, "c:" #caption},
|
|
|
|
STATS_COUNTER_LIST_1(SC) STATS_COUNTER_LIST_2(SC)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef SC
|
2017-03-21 19:31:14 +00:00
|
|
|
#define SC(name) \
|
|
|
|
{&Counters::count_of_##name##_, "c:" "V8.CountOf_" #name}, \
|
|
|
|
{&Counters::size_of_##name##_, "c:" "V8.SizeOf_" #name},
|
|
|
|
INSTANCE_TYPE_LIST(SC)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef SC
|
2017-03-21 19:31:14 +00:00
|
|
|
#define SC(name) \
|
|
|
|
{&Counters::count_of_CODE_TYPE_##name##_, \
|
|
|
|
"c:" "V8.CountOf_CODE_TYPE-" #name}, \
|
|
|
|
{&Counters::size_of_CODE_TYPE_##name##_, \
|
|
|
|
"c:" "V8.SizeOf_CODE_TYPE-" #name},
|
|
|
|
CODE_KIND_LIST(SC)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef SC
|
2017-03-21 19:31:14 +00:00
|
|
|
#define SC(name) \
|
|
|
|
{&Counters::count_of_FIXED_ARRAY_##name##_, \
|
|
|
|
"c:" "V8.CountOf_FIXED_ARRAY-" #name}, \
|
|
|
|
{&Counters::size_of_FIXED_ARRAY_##name##_, \
|
|
|
|
"c:" "V8.SizeOf_FIXED_ARRAY-" #name},
|
|
|
|
FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
|
2014-05-07 07:15:24 +00:00
|
|
|
#undef SC
|
2017-03-21 19:31:14 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
for (const auto& counter : kStatsCounters) {
|
2017-05-29 18:18:25 +00:00
|
|
|
this->*counter.member = StatsCounter(this, counter.caption);
|
2017-03-21 19:31:14 +00:00
|
|
|
}
|
2014-05-07 07:15:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 16:18:32 +00:00
|
|
|
void Counters::ResetCounterFunction(CounterLookupCallback f) {
|
|
|
|
stats_table_.SetCounterFunction(f);
|
|
|
|
|
2014-07-07 07:19:46 +00:00
|
|
|
#define SC(name, caption) name##_.Reset();
|
|
|
|
STATS_COUNTER_LIST_1(SC)
|
|
|
|
STATS_COUNTER_LIST_2(SC)
|
|
|
|
#undef SC
|
|
|
|
|
2017-05-24 21:21:04 +00:00
|
|
|
#define SC(name, caption) name##_.Reset();
|
|
|
|
STATS_COUNTER_TS_LIST(SC)
|
|
|
|
#undef SC
|
|
|
|
|
2014-07-07 07:19:46 +00:00
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
2017-06-08 16:18:32 +00:00
|
|
|
void Counters::ResetCreateHistogramFunction(CreateHistogramCallback f) {
|
|
|
|
stats_table_.SetCreateHistogramFunction(f);
|
2014-07-07 07:19:46 +00:00
|
|
|
|
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
|
|
|
|
|
2017-06-27 18:50:38 +00:00
|
|
|
#define HT(name, caption, max, res) name##_.Reset();
|
|
|
|
TIMED_HISTOGRAM_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)
|
2017-04-10 15:15:40 +00:00
|
|
|
HISTOGRAM_MEMORY_LIST(HM)
|
|
|
|
#undef HM
|
|
|
|
}
|
|
|
|
|
2017-11-09 14:11:50 +00:00
|
|
|
base::TimeTicks (*RuntimeCallTimer::Now)() =
|
|
|
|
&base::TimeTicks::HighResolutionNow;
|
|
|
|
|
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-11-24 10:05:22 +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_;
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:09:39 +00:00
|
|
|
V8_NOINLINE void Print(std::ostream& os) {
|
2016-02-11 12:30:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:09:39 +00:00
|
|
|
V8_NOINLINE 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() {
|
2016-11-24 10:05:22 +00:00
|
|
|
count_ = 0;
|
2017-03-21 19:31:14 +00:00
|
|
|
time_ = 0;
|
2016-02-11 14:47:02 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 14:56:18 +00:00
|
|
|
void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) {
|
2016-11-24 10:05:22 +00:00
|
|
|
value->BeginArray(name_);
|
2016-12-06 18:12:13 +00:00
|
|
|
value->AppendDouble(count_);
|
2017-03-21 19:31:14 +00:00
|
|
|
value->AppendDouble(time_);
|
2016-10-19 14:56:18 +00:00
|
|
|
value->EndArray();
|
2016-08-10 01:18:38 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 16:08:16 +00:00
|
|
|
void RuntimeCallCounter::Add(RuntimeCallCounter* other) {
|
2016-11-24 10:05:22 +00:00
|
|
|
count_ += other->count();
|
2017-03-21 19:31:14 +00:00
|
|
|
time_ += other->time().InMicroseconds();
|
2016-11-24 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RuntimeCallTimer::Snapshot() {
|
|
|
|
base::TimeTicks now = Now();
|
|
|
|
// Pause only / topmost timer in the timer stack.
|
|
|
|
Pause(now);
|
|
|
|
// Commit all the timer's elapsed time to the counters.
|
|
|
|
RuntimeCallTimer* timer = this;
|
|
|
|
while (timer != nullptr) {
|
|
|
|
timer->CommitTimeToCounter();
|
|
|
|
timer = timer->parent();
|
|
|
|
}
|
|
|
|
Resume(now);
|
2016-11-15 16:08:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 00:28:30 +00:00
|
|
|
RuntimeCallStats::RuntimeCallStats() : in_use_(false) {
|
2017-03-21 19:31:14 +00:00
|
|
|
static const char* const kNames[] = {
|
2017-08-01 13:28:52 +00:00
|
|
|
#define CALL_BUILTIN_COUNTER(name) "GC_" #name,
|
|
|
|
FOR_EACH_GC_COUNTER(CALL_BUILTIN_COUNTER) //
|
|
|
|
#undef CALL_BUILTIN_COUNTER
|
2017-03-21 19:31:14 +00:00
|
|
|
#define CALL_RUNTIME_COUNTER(name) #name,
|
|
|
|
FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) //
|
|
|
|
#undef CALL_RUNTIME_COUNTER
|
|
|
|
#define CALL_RUNTIME_COUNTER(name, nargs, ressize) #name,
|
|
|
|
FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) //
|
|
|
|
#undef CALL_RUNTIME_COUNTER
|
|
|
|
#define CALL_BUILTIN_COUNTER(name) #name,
|
|
|
|
BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) //
|
|
|
|
#undef CALL_BUILTIN_COUNTER
|
|
|
|
#define CALL_BUILTIN_COUNTER(name) "API_" #name,
|
|
|
|
FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) //
|
|
|
|
#undef CALL_BUILTIN_COUNTER
|
|
|
|
#define CALL_BUILTIN_COUNTER(name) #name,
|
2017-08-01 13:28:52 +00:00
|
|
|
FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) //
|
2017-03-21 19:31:14 +00:00
|
|
|
#undef CALL_BUILTIN_COUNTER
|
|
|
|
};
|
|
|
|
for (int i = 0; i < counters_count; i++) {
|
|
|
|
this->*(counters[i]) = RuntimeCallCounter(kNames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 16:08:16 +00:00
|
|
|
// static
|
|
|
|
const RuntimeCallStats::CounterId RuntimeCallStats::counters[] = {
|
2017-08-01 13:28:52 +00:00
|
|
|
#define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::GC_##name,
|
|
|
|
FOR_EACH_GC_COUNTER(CALL_BUILTIN_COUNTER) //
|
|
|
|
#undef CALL_BUILTIN_COUNTER
|
2016-11-15 16:08:16 +00:00
|
|
|
#define CALL_RUNTIME_COUNTER(name) &RuntimeCallStats::name,
|
|
|
|
FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) //
|
|
|
|
#undef CALL_RUNTIME_COUNTER
|
|
|
|
#define CALL_RUNTIME_COUNTER(name, nargs, ressize) \
|
|
|
|
&RuntimeCallStats::Runtime_##name, //
|
|
|
|
FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) //
|
|
|
|
#undef CALL_RUNTIME_COUNTER
|
|
|
|
#define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Builtin_##name,
|
|
|
|
BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) //
|
|
|
|
#undef CALL_BUILTIN_COUNTER
|
|
|
|
#define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::API_##name,
|
|
|
|
FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) //
|
|
|
|
#undef CALL_BUILTIN_COUNTER
|
|
|
|
#define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Handler_##name,
|
2017-08-01 13:28:52 +00:00
|
|
|
FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) //
|
2016-11-15 16:08:16 +00:00
|
|
|
#undef CALL_BUILTIN_COUNTER
|
|
|
|
};
|
|
|
|
|
2016-12-02 20:03:22 +00:00
|
|
|
// static
|
|
|
|
const int RuntimeCallStats::counters_count =
|
|
|
|
arraysize(RuntimeCallStats::counters);
|
|
|
|
|
2016-05-11 08:49:33 +00:00
|
|
|
// static
|
2016-09-05 15:39:39 +00:00
|
|
|
void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
|
2016-05-11 08:49:33 +00:00
|
|
|
CounterId counter_id) {
|
2017-10-31 19:01:47 +00:00
|
|
|
DCHECK(stats->IsCalledOnTheSameThread());
|
2016-05-11 08:49:33 +00:00
|
|
|
RuntimeCallCounter* counter = &(stats->*counter_id);
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_NOT_NULL(counter->name());
|
2017-10-23 19:00:23 +00:00
|
|
|
timer->Start(counter, stats->current_timer());
|
2016-11-02 18:49:44 +00:00
|
|
|
stats->current_timer_.SetValue(timer);
|
2017-04-07 15:21:34 +00:00
|
|
|
stats->current_counter_.SetValue(counter);
|
2016-02-23 08:45:52 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 08:49:33 +00:00
|
|
|
// static
|
2016-09-05 15:39:39 +00:00
|
|
|
void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
|
2017-10-31 19:01:47 +00:00
|
|
|
DCHECK(stats->IsCalledOnTheSameThread());
|
2017-10-23 19:00:23 +00:00
|
|
|
RuntimeCallTimer* stack_top = stats->current_timer();
|
|
|
|
if (stack_top == nullptr) return; // Missing timer is a result of Reset().
|
2017-10-31 19:01:47 +00:00
|
|
|
CHECK(stack_top == timer);
|
2017-08-28 08:29:14 +00:00
|
|
|
stats->current_timer_.SetValue(timer->Stop());
|
2017-10-23 19:00:23 +00:00
|
|
|
RuntimeCallTimer* cur_timer = stats->current_timer();
|
2017-08-28 08:29:14 +00:00
|
|
|
stats->current_counter_.SetValue(cur_timer ? cur_timer->counter() : nullptr);
|
2016-02-11 14:47:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 16:08:16 +00:00
|
|
|
void RuntimeCallStats::Add(RuntimeCallStats* other) {
|
|
|
|
for (const RuntimeCallStats::CounterId counter_id :
|
|
|
|
RuntimeCallStats::counters) {
|
|
|
|
RuntimeCallCounter* counter = &(this->*counter_id);
|
|
|
|
RuntimeCallCounter* other_counter = &(other->*counter_id);
|
|
|
|
counter->Add(other_counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 12:37:22 +00:00
|
|
|
// static
|
2016-09-05 15:39:39 +00:00
|
|
|
void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats,
|
2016-05-11 12:37:22 +00:00
|
|
|
CounterId counter_id) {
|
2017-10-31 19:01:47 +00:00
|
|
|
DCHECK(stats->IsCalledOnTheSameThread());
|
2017-10-26 23:18:40 +00:00
|
|
|
// When RCS are enabled dynamically there might be no stats or timer set up.
|
|
|
|
if (stats == nullptr) return;
|
2016-11-08 18:16:33 +00:00
|
|
|
RuntimeCallTimer* timer = stats->current_timer_.Value();
|
|
|
|
if (timer == nullptr) return;
|
2017-04-07 15:21:34 +00:00
|
|
|
RuntimeCallCounter* counter = &(stats->*counter_id);
|
|
|
|
timer->set_counter(counter);
|
|
|
|
stats->current_counter_.SetValue(counter);
|
2016-05-11 12:37:22 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 00:28:30 +00:00
|
|
|
bool RuntimeCallStats::IsCalledOnTheSameThread() {
|
|
|
|
if (!thread_id_.Equals(ThreadId::Invalid()))
|
|
|
|
return thread_id_.Equals(ThreadId::Current());
|
|
|
|
thread_id_ = ThreadId::Current();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-14 09:15:41 +00:00
|
|
|
void RuntimeCallStats::Print() {
|
|
|
|
OFStream os(stdout);
|
|
|
|
Print(os);
|
|
|
|
}
|
|
|
|
|
2016-02-11 12:30:06 +00:00
|
|
|
void RuntimeCallStats::Print(std::ostream& os) {
|
|
|
|
RuntimeCallStatEntries entries;
|
2016-11-02 18:49:44 +00:00
|
|
|
if (current_timer_.Value() != nullptr) {
|
2016-11-24 10:05:22 +00:00
|
|
|
current_timer_.Value()->Snapshot();
|
2016-10-28 18:04:41 +00:00
|
|
|
}
|
2016-11-15 16:08:16 +00:00
|
|
|
for (const RuntimeCallStats::CounterId counter_id :
|
|
|
|
RuntimeCallStats::counters) {
|
|
|
|
RuntimeCallCounter* counter = &(this->*counter_id);
|
|
|
|
entries.Add(counter);
|
|
|
|
}
|
2016-02-11 12:30:06 +00:00
|
|
|
entries.Print(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuntimeCallStats::Reset() {
|
2016-11-04 00:30:44 +00:00
|
|
|
if (V8_LIKELY(FLAG_runtime_stats == 0)) return;
|
|
|
|
|
2016-11-09 17:07:53 +00:00
|
|
|
// In tracing, we only what to trace the time spent on top level trace events,
|
|
|
|
// if runtime counter stack is not empty, we should clear the whole runtime
|
|
|
|
// counter stack, and then reset counters so that we can dump counters into
|
|
|
|
// top level trace events accurately.
|
|
|
|
while (current_timer_.Value()) {
|
|
|
|
current_timer_.SetValue(current_timer_.Value()->Stop());
|
|
|
|
}
|
|
|
|
|
2016-11-15 16:08:16 +00:00
|
|
|
for (const RuntimeCallStats::CounterId counter_id :
|
|
|
|
RuntimeCallStats::counters) {
|
|
|
|
RuntimeCallCounter* counter = &(this->*counter_id);
|
|
|
|
counter->Reset();
|
|
|
|
}
|
2016-09-06 15:48:08 +00:00
|
|
|
|
|
|
|
in_use_ = true;
|
2016-02-11 12:30:06 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 14:56:18 +00:00
|
|
|
void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) {
|
2016-11-15 16:08:16 +00:00
|
|
|
for (const RuntimeCallStats::CounterId counter_id :
|
|
|
|
RuntimeCallStats::counters) {
|
|
|
|
RuntimeCallCounter* counter = &(this->*counter_id);
|
2016-11-24 10:05:22 +00:00
|
|
|
if (counter->count() > 0) counter->Dump(value);
|
2016-11-15 16:08:16 +00:00
|
|
|
}
|
2016-10-19 14:56:18 +00:00
|
|
|
|
2016-09-05 15:39:39 +00:00
|
|
|
in_use_ = false;
|
|
|
|
}
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|