Commit ad99b196 authored by jochen's avatar jochen Committed by Commit bot

Introduce a CompilerDispatcherTracer and track how long jobs take

R=ulan@chromium.org,cbruni@chromium.org,rmcilroy@chromium.org
BUG=v8:5215

Review-Url: https://codereview.chromium.org/2413243002
Cr-Commit-Position: refs/heads/master@{#40295}
parent 4897c357
......@@ -993,6 +993,8 @@ v8_source_set("v8_base") {
"src/compilation-statistics.h",
"src/compiler-dispatcher/compiler-dispatcher-job.cc",
"src/compiler-dispatcher/compiler-dispatcher-job.h",
"src/compiler-dispatcher/compiler-dispatcher-tracer.cc",
"src/compiler-dispatcher/compiler-dispatcher-tracer.h",
"src/compiler-dispatcher/optimizing-compile-dispatcher.cc",
"src/compiler-dispatcher/optimizing-compile-dispatcher.h",
"src/compiler.cc",
......@@ -2237,6 +2239,7 @@ v8_component("v8_libbase") {
"src/base/platform/semaphore.h",
"src/base/platform/time.cc",
"src/base/platform/time.h",
"src/base/ring-buffer.h",
"src/base/safe_conversions.h",
"src/base/safe_conversions_impl.h",
"src/base/safe_math.h",
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_BASE_RING_BUFFER_H_
#define V8_BASE_RING_BUFFER_H_
#include "src/base/macros.h"
namespace v8 {
namespace base {
template <typename T>
class RingBuffer {
public:
RingBuffer() { Reset(); }
static const int kSize = 10;
void Push(const T& value) {
if (count_ == kSize) {
elements_[start_++] = value;
if (start_ == kSize) start_ = 0;
} else {
DCHECK_EQ(start_, 0);
elements_[count_++] = value;
}
}
int Count() const { return count_; }
template <typename Callback>
T Sum(Callback callback, const T& initial) const {
int j = start_ + count_ - 1;
if (j >= kSize) j -= kSize;
T result = initial;
for (int i = 0; i < count_; i++) {
result = callback(result, elements_[j]);
if (--j == -1) j += kSize;
}
return result;
}
void Reset() { start_ = count_ = 0; }
private:
T elements_[kSize];
int start_;
int count_;
DISALLOW_COPY_AND_ASSIGN(RingBuffer);
};
} // namespace base
} // namespace v8
#endif // V8_BASE_RING_BUFFER_H_
......@@ -6,6 +6,7 @@
#include "src/assert-scope.h"
#include "src/compilation-info.h"
#include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
#include "src/compiler.h"
#include "src/global-handles.h"
#include "src/isolate.h"
......@@ -23,6 +24,7 @@ CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate,
Handle<SharedFunctionInfo> shared,
size_t max_stack_size)
: isolate_(isolate),
tracer_(isolate_->compiler_dispatcher_tracer()),
shared_(Handle<SharedFunctionInfo>::cast(
isolate_->global_handles()->Create(*shared))),
max_stack_size_(max_stack_size),
......@@ -45,6 +47,7 @@ CompilerDispatcherJob::~CompilerDispatcherJob() {
void CompilerDispatcherJob::PrepareToParseOnMainThread() {
DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
DCHECK(status() == CompileJobStatus::kInitial);
COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToParse);
HandleScope scope(isolate_);
unicode_cache_.reset(new UnicodeCache());
zone_.reset(new Zone(isolate_->allocator()));
......@@ -92,6 +95,9 @@ void CompilerDispatcherJob::Parse() {
DCHECK(can_parse_on_background_thread_ ||
ThreadId::Current().Equals(isolate_->thread_id()));
DCHECK(status() == CompileJobStatus::kReadyToParse);
COMPILER_DISPATCHER_TRACE_SCOPE_WITH_NUM(
tracer_, kParse,
parse_info_->end_position() - parse_info_->start_position());
DisallowHeapAllocation no_allocation;
DisallowHandleAllocation no_handles;
......@@ -119,6 +125,7 @@ void CompilerDispatcherJob::Parse() {
bool CompilerDispatcherJob::FinalizeParsingOnMainThread() {
DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
DCHECK(status() == CompileJobStatus::kParsed);
COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kFinalizeParsing);
if (!source_.is_null()) {
i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location());
......@@ -170,6 +177,7 @@ bool CompilerDispatcherJob::FinalizeParsingOnMainThread() {
bool CompilerDispatcherJob::PrepareToCompileOnMainThread() {
DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
DCHECK(status() == CompileJobStatus::kReadyToAnalyse);
COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToCompile);
compile_info_.reset(
new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null()));
......@@ -197,6 +205,8 @@ void CompilerDispatcherJob::Compile() {
DCHECK(status() == CompileJobStatus::kReadyToCompile);
DCHECK(can_compile_on_background_thread_ ||
ThreadId::Current().Equals(isolate_->thread_id()));
COMPILER_DISPATCHER_TRACE_SCOPE_WITH_NUM(
tracer_, kCompile, parse_info_->literal()->ast_node_count());
// Disallowing of handle dereference and heap access dealt with in
// CompilationJob::ExecuteJob.
......@@ -215,6 +225,7 @@ void CompilerDispatcherJob::Compile() {
bool CompilerDispatcherJob::FinalizeCompilingOnMainThread() {
DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
DCHECK(status() == CompileJobStatus::kCompiled);
COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kFinalizeCompiling);
if (compile_job_->state() == CompilationJob::State::kFailed ||
!Compiler::FinalizeCompilationJob(compile_job_.release())) {
......
......@@ -14,6 +14,7 @@
namespace v8 {
namespace internal {
class CompilerDispatcherTracer;
class CompilationInfo;
class CompilationJob;
class Isolate;
......@@ -81,6 +82,7 @@ class CompilerDispatcherJob {
CompileJobStatus status_ = CompileJobStatus::kInitial;
Isolate* isolate_;
CompilerDispatcherTracer* tracer_;
Handle<SharedFunctionInfo> shared_; // Global handle.
Handle<String> source_; // Global handle.
size_t max_stack_size_;
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
#include "src/isolate.h"
namespace v8 {
namespace internal {
namespace {
double MonotonicallyIncreasingTimeInMs() {
return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() *
static_cast<double>(base::Time::kMillisecondsPerSecond);
}
} // namespace
CompilerDispatcherTracer::Scope::Scope(CompilerDispatcherTracer* tracer,
ScopeID scope_id, size_t num)
: tracer_(tracer), scope_id_(scope_id), num_(num) {
start_time_ = MonotonicallyIncreasingTimeInMs();
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() ||
FLAG_runtime_call_stats) {
RuntimeCallStats::Enter(tracer_->runtime_call_stats_, &timer_,
&RuntimeCallStats::CompilerDispatcher);
}
}
CompilerDispatcherTracer::Scope::~Scope() {
double elapsed = MonotonicallyIncreasingTimeInMs() - start_time_;
switch (scope_id_) {
case ScopeID::kPrepareToParse:
tracer_->RecordPrepareToParse(elapsed);
break;
case ScopeID::kParse:
tracer_->RecordParse(elapsed, num_);
break;
case ScopeID::kFinalizeParsing:
tracer_->RecordFinalizeParsing(elapsed);
break;
case ScopeID::kPrepareToCompile:
tracer_->RecordPrepareToCompile(elapsed);
break;
case ScopeID::kCompile:
tracer_->RecordCompile(elapsed, num_);
break;
case ScopeID::kFinalizeCompiling:
tracer_->RecordFinalizeCompiling(elapsed);
break;
}
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() ||
FLAG_runtime_call_stats) {
RuntimeCallStats::Leave(tracer_->runtime_call_stats_, &timer_);
}
}
// static
const char* CompilerDispatcherTracer::Scope::Name(ScopeID scope_id) {
switch (scope_id) {
case ScopeID::kPrepareToParse:
return "V8.BackgroundCompile_PrepareToParse";
case ScopeID::kParse:
return "V8.BackgroundCompile_Parse";
case ScopeID::kFinalizeParsing:
return "V8.BackgroundCompile_FinalizeParsing";
case ScopeID::kPrepareToCompile:
return "V8.BackgroundCompile_PrepareToCompile";
case ScopeID::kCompile:
return "V8.BackgroundCompile_Compile";
case ScopeID::kFinalizeCompiling:
return "V8.BackgroundCompile_FinalizeCompiling";
}
UNREACHABLE();
return nullptr;
}
CompilerDispatcherTracer::CompilerDispatcherTracer(Isolate* isolate)
: runtime_call_stats_(nullptr) {
// isolate might be nullptr during unittests.
if (isolate) {
runtime_call_stats_ = isolate->counters()->runtime_call_stats();
}
}
CompilerDispatcherTracer::~CompilerDispatcherTracer() {}
void CompilerDispatcherTracer::RecordPrepareToParse(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
prepare_parse_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordParse(double duration_ms,
size_t source_length) {
base::LockGuard<base::Mutex> lock(&mutex_);
parse_events_.Push(std::make_pair(source_length, duration_ms));
}
void CompilerDispatcherTracer::RecordFinalizeParsing(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
finalize_parsing_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordPrepareToCompile(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
prepare_compile_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordCompile(double duration_ms,
size_t ast_size_in_bytes) {
base::LockGuard<base::Mutex> lock(&mutex_);
compile_events_.Push(std::make_pair(ast_size_in_bytes, duration_ms));
}
void CompilerDispatcherTracer::RecordFinalizeCompiling(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
finalize_compiling_events_.Push(duration_ms);
}
double CompilerDispatcherTracer::EstimatePrepareToParseInMs() const {
base::LockGuard<base::Mutex> lock(&mutex_);
return Average(prepare_parse_events_);
}
double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const {
base::LockGuard<base::Mutex> lock(&mutex_);
return Estimate(parse_events_, source_length);
}
double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() {
base::LockGuard<base::Mutex> lock(&mutex_);
return Average(finalize_parsing_events_);
}
double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() {
base::LockGuard<base::Mutex> lock(&mutex_);
return Average(prepare_compile_events_);
}
double CompilerDispatcherTracer::EstimateCompileInMs(size_t ast_size_in_bytes) {
base::LockGuard<base::Mutex> lock(&mutex_);
return Estimate(compile_events_, ast_size_in_bytes);
}
double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() {
base::LockGuard<base::Mutex> lock(&mutex_);
return Average(finalize_compiling_events_);
}
double CompilerDispatcherTracer::Average(
const base::RingBuffer<double>& buffer) {
if (buffer.Count() == 0) return 0.0;
double sum = buffer.Sum([](double a, double b) { return a + b; }, 0.0);
return sum / buffer.Count();
}
double CompilerDispatcherTracer::Estimate(
const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num) {
if (buffer.Count() == 0) return 0.0;
std::pair<size_t, double> sum = buffer.Sum(
[](std::pair<size_t, double> a, std::pair<size_t, double> b) {
return std::make_pair(a.first + b.first, a.second + b.second);
},
std::make_pair(0, 0.0));
return num * (sum.second / sum.first);
}
} // namespace internal
} // namespace v8
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_TRACER_H_
#define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_TRACER_H_
#include <utility>
#include "src/base/macros.h"
#include "src/base/platform/mutex.h"
#include "src/base/ring-buffer.h"
#include "src/counters.h"
namespace v8 {
namespace internal {
class Isolate;
class RuntimeCallStats;
#define COMPILER_DISPATCHER_TRACE_SCOPE_WITH_NUM(tracer, scope_id, num) \
CompilerDispatcherTracer::ScopeID tracer_scope_id( \
CompilerDispatcherTracer::ScopeID::scope_id); \
CompilerDispatcherTracer::Scope trace_scope(tracer, tracer_scope_id, num); \
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), \
CompilerDispatcherTracer::Scope::Name(tracer_scope_id))
#define COMPILER_DISPATCHER_TRACE_SCOPE(tracer, scope_id) \
COMPILER_DISPATCHER_TRACE_SCOPE_WITH_NUM(tracer, scope_id, 0)
class CompilerDispatcherTracer {
public:
enum class ScopeID {
kPrepareToParse,
kParse,
kFinalizeParsing,
kPrepareToCompile,
kCompile,
kFinalizeCompiling
};
class Scope {
public:
Scope(CompilerDispatcherTracer* tracer, ScopeID scope_id, size_t num = 0);
~Scope();
static const char* Name(ScopeID scoped_id);
private:
CompilerDispatcherTracer* tracer_;
ScopeID scope_id_;
size_t num_;
double start_time_;
RuntimeCallTimer timer_;
DISALLOW_COPY_AND_ASSIGN(Scope);
};
explicit CompilerDispatcherTracer(Isolate* isolate);
~CompilerDispatcherTracer();
void RecordPrepareToParse(double duration_ms);
void RecordParse(double duration_ms, size_t source_length);
void RecordFinalizeParsing(double duration_ms);
void RecordPrepareToCompile(double duration_ms);
void RecordCompile(double duration_ms, size_t ast_size_in_bytes);
void RecordFinalizeCompiling(double duration_ms);
double EstimatePrepareToParseInMs() const;
double EstimateParseInMs(size_t source_length) const;
double EstimateFinalizeParsingInMs();
double EstimatePrepareToCompileInMs();
double EstimateCompileInMs(size_t ast_size_in_bytes);
double EstimateFinalizeCompilingInMs();
private:
static double Average(const base::RingBuffer<double>& buffer);
static double Estimate(
const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num);
mutable base::Mutex mutex_;
base::RingBuffer<double> prepare_parse_events_;
base::RingBuffer<std::pair<size_t, double>> parse_events_;
base::RingBuffer<double> finalize_parsing_events_;
base::RingBuffer<double> prepare_compile_events_;
base::RingBuffer<std::pair<size_t, double>> compile_events_;
base::RingBuffer<double> finalize_compiling_events_;
RuntimeCallStats* runtime_call_stats_;
DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherTracer);
};
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_TRACER_H_
......@@ -678,6 +678,7 @@ class RuntimeCallTimer {
V(CompileEval) \
V(CompileFullCode) \
V(CompileIgnition) \
V(CompilerDispatcher) \
V(CompileSerialize) \
V(DeoptimizeCode) \
V(FunctionCallback) \
......
......@@ -675,7 +675,7 @@ void GCTracer::PrintNVP() const {
}
}
double GCTracer::AverageSpeed(const RingBuffer<BytesAndDuration>& buffer,
double GCTracer::AverageSpeed(const base::RingBuffer<BytesAndDuration>& buffer,
const BytesAndDuration& initial, double time_ms) {
BytesAndDuration sum = buffer.Sum(
[time_ms](BytesAndDuration a, BytesAndDuration b) {
......@@ -694,7 +694,8 @@ double GCTracer::AverageSpeed(const RingBuffer<BytesAndDuration>& buffer,
return speed;
}
double GCTracer::AverageSpeed(const RingBuffer<BytesAndDuration>& buffer) {
double GCTracer::AverageSpeed(
const base::RingBuffer<BytesAndDuration>& buffer) {
return AverageSpeed(buffer, MakeBytesAndDuration(0, 0), 0);
}
......
......@@ -7,6 +7,7 @@
#include "src/base/compiler-specific.h"
#include "src/base/platform/platform.h"
#include "src/base/ring-buffer.h"
#include "src/counters.h"
#include "src/globals.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
......@@ -14,44 +15,6 @@
namespace v8 {
namespace internal {
template <typename T>
class RingBuffer {
public:
RingBuffer() { Reset(); }
static const int kSize = 10;
void Push(const T& value) {
if (count_ == kSize) {
elements_[start_++] = value;
if (start_ == kSize) start_ = 0;
} else {
DCHECK_EQ(start_, 0);
elements_[count_++] = value;
}
}
int Count() const { return count_; }
template <typename Callback>
T Sum(Callback callback, const T& initial) const {
int j = start_ + count_ - 1;
if (j >= kSize) j -= kSize;
T result = initial;
for (int i = 0; i < count_; i++) {
result = callback(result, elements_[j]);
if (--j == -1) j += kSize;
}
return result;
}
void Reset() { start_ = count_ = 0; }
private:
T elements_[kSize];
int start_;
int count_;
DISALLOW_COPY_AND_ASSIGN(RingBuffer);
};
typedef std::pair<uint64_t, double> BytesAndDuration;
inline BytesAndDuration MakeBytesAndDuration(uint64_t bytes, double duration) {
......@@ -377,8 +340,8 @@ class GCTracer {
// Returns the average speed of the events in the buffer.
// If the buffer is empty, the result is 0.
// Otherwise, the result is between 1 byte/ms and 1 GB/ms.
static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer);
static double AverageSpeed(const RingBuffer<BytesAndDuration>& buffer,
static double AverageSpeed(const base::RingBuffer<BytesAndDuration>& buffer);
static double AverageSpeed(const base::RingBuffer<BytesAndDuration>& buffer,
const BytesAndDuration& initial, double time_ms);
void ResetForTesting();
......@@ -453,15 +416,15 @@ class GCTracer {
// Separate timer used for --runtime_call_stats
RuntimeCallTimer timer_;
RingBuffer<BytesAndDuration> recorded_scavenges_total_;
RingBuffer<BytesAndDuration> recorded_scavenges_survived_;
RingBuffer<BytesAndDuration> recorded_compactions_;
RingBuffer<BytesAndDuration> recorded_incremental_mark_compacts_;
RingBuffer<BytesAndDuration> recorded_mark_compacts_;
RingBuffer<BytesAndDuration> recorded_new_generation_allocations_;
RingBuffer<BytesAndDuration> recorded_old_generation_allocations_;
RingBuffer<double> recorded_context_disposal_times_;
RingBuffer<double> recorded_survival_ratios_;
base::RingBuffer<BytesAndDuration> recorded_scavenges_total_;
base::RingBuffer<BytesAndDuration> recorded_scavenges_survived_;
base::RingBuffer<BytesAndDuration> recorded_compactions_;
base::RingBuffer<BytesAndDuration> recorded_incremental_mark_compacts_;
base::RingBuffer<BytesAndDuration> recorded_mark_compacts_;
base::RingBuffer<BytesAndDuration> recorded_new_generation_allocations_;
base::RingBuffer<BytesAndDuration> recorded_old_generation_allocations_;
base::RingBuffer<double> recorded_context_disposal_times_;
base::RingBuffer<double> recorded_survival_ratios_;
DISALLOW_COPY_AND_ASSIGN(GCTracer);
};
......
......@@ -20,6 +20,7 @@
#include "src/codegen.h"
#include "src/compilation-cache.h"
#include "src/compilation-statistics.h"
#include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
#include "src/compiler-dispatcher/optimizing-compile-dispatcher.h"
#include "src/crankshaft/hydrogen.h"
#include "src/debug/debug.h"
......@@ -2234,6 +2235,9 @@ void Isolate::Deinit() {
cancelable_task_manager()->CancelAndWait();
delete compiler_dispatcher_tracer_;
compiler_dispatcher_tracer_ = nullptr;
delete cpu_profiler_;
cpu_profiler_ = NULL;
......@@ -2445,6 +2449,7 @@ bool Isolate::Init(Deserializer* des) {
cpu_profiler_ = new CpuProfiler(this);
heap_profiler_ = new HeapProfiler(heap());
interpreter_ = new interpreter::Interpreter(this);
compiler_dispatcher_tracer_ = new CompilerDispatcherTracer(this);
// Enable logging before setting up the heap
logger_->SetUp(this);
......
......@@ -45,6 +45,7 @@ class CodeRange;
class CodeStubDescriptor;
class CodeTracer;
class CompilationCache;
class CompilerDispatcherTracer;
class CompilationStatistics;
class ContextSlotCache;
class Counters;
......@@ -1162,6 +1163,10 @@ class Isolate {
AccountingAllocator* allocator() { return allocator_; }
CompilerDispatcherTracer* compiler_dispatcher_tracer() const {
return compiler_dispatcher_tracer_;
}
bool IsInAnyContext(Object* object, uint32_t index);
void SetRAILMode(RAILMode rail_mode);
......@@ -1389,6 +1394,8 @@ class Isolate {
interpreter::Interpreter* interpreter_;
CompilerDispatcherTracer* compiler_dispatcher_tracer_;
typedef std::pair<InterruptCallback, void*> InterruptEntry;
std::queue<InterruptEntry> api_interrupts_queue_;
......
......@@ -737,6 +737,8 @@
'compiler/zone-stats.h',
'compiler-dispatcher/compiler-dispatcher-job.cc',
'compiler-dispatcher/compiler-dispatcher-job.h',
'compiler-dispatcher/compiler-dispatcher-tracer.cc',
'compiler-dispatcher/compiler-dispatcher-tracer.h',
'compiler-dispatcher/optimizing-compile-dispatcher.cc',
'compiler-dispatcher/optimizing-compile-dispatcher.h',
'compiler.cc',
......@@ -1825,6 +1827,7 @@
'base/platform/platform.h',
'base/platform/semaphore.cc',
'base/platform/semaphore.h',
'base/ring-buffer.h',
'base/safe_conversions.h',
'base/safe_conversions_impl.h',
'base/safe_math.h',
......
......@@ -29,6 +29,7 @@ v8_executable("unittests") {
"cancelable-tasks-unittest.cc",
"char-predicates-unittest.cc",
"compiler-dispatcher/compiler-dispatcher-job-unittest.cc",
"compiler-dispatcher/compiler-dispatcher-tracer-unittest.cc",
"compiler/branch-elimination-unittest.cc",
"compiler/checkpoint-elimination-unittest.cc",
"compiler/common-operator-reducer-unittest.cc",
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
#include "testing/gtest-support.h"
namespace v8 {
namespace internal {
TEST(CompilerDispatcherTracerTest, EstimateZeroWithoutSamples) {
CompilerDispatcherTracer tracer(nullptr);
EXPECT_EQ(0.0, tracer.EstimatePrepareToParseInMs());
EXPECT_EQ(0.0, tracer.EstimateParseInMs(0));
EXPECT_EQ(0.0, tracer.EstimateParseInMs(42));
EXPECT_EQ(0.0, tracer.EstimateFinalizeParsingInMs());
EXPECT_EQ(0.0, tracer.EstimatePrepareToCompileInMs());
EXPECT_EQ(0.0, tracer.EstimateCompileInMs(0));
EXPECT_EQ(0.0, tracer.EstimateCompileInMs(42));
EXPECT_EQ(0.0, tracer.EstimateFinalizeCompilingInMs());
}
TEST(CompilerDispatcherTracerTest, Average) {
CompilerDispatcherTracer tracer(nullptr);
EXPECT_EQ(0.0, tracer.EstimatePrepareToParseInMs());
tracer.RecordPrepareToParse(1.0);
tracer.RecordPrepareToParse(2.0);
tracer.RecordPrepareToParse(3.0);
EXPECT_EQ((1.0 + 2.0 + 3.0) / 3, tracer.EstimatePrepareToParseInMs());
}
TEST(CompilerDispatcherTracerTest, SizeBasedAverage) {
CompilerDispatcherTracer tracer(nullptr);
EXPECT_EQ(0.0, tracer.EstimateParseInMs(100));
// All three samples parse 100 units/ms.
tracer.RecordParse(1.0, 100);
tracer.RecordParse(2.0, 200);
tracer.RecordParse(3.0, 300);
EXPECT_EQ(1.0, tracer.EstimateParseInMs(100));
EXPECT_EQ(5.0, tracer.EstimateParseInMs(500));
}
} // namespace internal
} // namespace v8
......@@ -17,7 +17,7 @@ namespace internal {
typedef TestWithContext GCTracerTest;
TEST(GCTracer, AverageSpeed) {
RingBuffer<BytesAndDuration> buffer;
base::RingBuffer<BytesAndDuration> buffer;
EXPECT_EQ(100 / 2,
GCTracer::AverageSpeed(buffer, MakeBytesAndDuration(100, 2), 0));
buffer.Push(MakeBytesAndDuration(100, 8));
......
......@@ -81,6 +81,7 @@
'compiler/value-numbering-reducer-unittest.cc',
'compiler/zone-stats-unittest.cc',
'compiler-dispatcher/compiler-dispatcher-job-unittest.cc',
'compiler-dispatcher/compiler-dispatcher-tracer-unittest.cc',
'counters-unittest.cc',
'eh-frame-iterator-unittest.cc',
'eh-frame-writer-unittest.cc',
......
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