Commit 231ae291 authored by alph's avatar alph Committed by Commit bot

Remove Isolate::cpu_profiler() usage in api.cc

Driveby: some surrounding code refactoring/cleanup.

BUG=v8:4789

Review-Url: https://codereview.chromium.org/2056253003
Cr-Commit-Position: refs/heads/master@{#36993}
parent 9d12ad0d
...@@ -8252,9 +8252,8 @@ const std::vector<CpuProfileDeoptInfo>& CpuProfileNode::GetDeoptInfos() const { ...@@ -8252,9 +8252,8 @@ const std::vector<CpuProfileDeoptInfo>& CpuProfileNode::GetDeoptInfos() const {
void CpuProfile::Delete() { void CpuProfile::Delete() {
i::CpuProfile* profile = reinterpret_cast<i::CpuProfile*>(this); i::CpuProfile* profile = reinterpret_cast<i::CpuProfile*>(this);
i::Isolate* isolate = profile->top_down()->isolate(); i::CpuProfiler* profiler = profile->cpu_profiler();
i::CpuProfiler* profiler = isolate->cpu_profiler(); DCHECK(profiler != nullptr);
DCHECK(profiler != NULL);
profiler->DeleteProfile(profile); profiler->DeleteProfile(profile);
} }
......
...@@ -499,15 +499,12 @@ CpuProfiler::CpuProfiler(Isolate* isolate) ...@@ -499,15 +499,12 @@ CpuProfiler::CpuProfiler(Isolate* isolate)
: isolate_(isolate), : isolate_(isolate),
sampling_interval_(base::TimeDelta::FromMicroseconds( sampling_interval_(base::TimeDelta::FromMicroseconds(
FLAG_cpu_profiler_sampling_interval)), FLAG_cpu_profiler_sampling_interval)),
profiles_(new CpuProfilesCollection(isolate->heap())), profiles_(new CpuProfilesCollection(isolate)),
generator_(NULL),
processor_(NULL),
is_profiling_(false) { is_profiling_(false) {
profiles_->set_cpu_profiler(this);
} }
CpuProfiler::CpuProfiler(Isolate* isolate, CpuProfilesCollection* test_profiles,
CpuProfiler::CpuProfiler(Isolate* isolate,
CpuProfilesCollection* test_profiles,
ProfileGenerator* test_generator, ProfileGenerator* test_generator,
ProfilerEventsProcessor* test_processor) ProfilerEventsProcessor* test_processor)
: isolate_(isolate), : isolate_(isolate),
...@@ -517,28 +514,25 @@ CpuProfiler::CpuProfiler(Isolate* isolate, ...@@ -517,28 +514,25 @@ CpuProfiler::CpuProfiler(Isolate* isolate,
generator_(test_generator), generator_(test_generator),
processor_(test_processor), processor_(test_processor),
is_profiling_(false) { is_profiling_(false) {
profiles_->set_cpu_profiler(this);
} }
CpuProfiler::~CpuProfiler() { CpuProfiler::~CpuProfiler() {
DCHECK(!is_profiling_); DCHECK(!is_profiling_);
delete profiles_;
} }
void CpuProfiler::set_sampling_interval(base::TimeDelta value) { void CpuProfiler::set_sampling_interval(base::TimeDelta value) {
DCHECK(!is_profiling_); DCHECK(!is_profiling_);
sampling_interval_ = value; sampling_interval_ = value;
} }
void CpuProfiler::ResetProfiles() { void CpuProfiler::ResetProfiles() {
delete profiles_; profiles_.reset(new CpuProfilesCollection(isolate_));
profiles_ = new CpuProfilesCollection(isolate()->heap()); profiles_->set_cpu_profiler(this);
} }
void CpuProfiler::CollectSample() { void CpuProfiler::CollectSample() {
if (processor_ != NULL) { if (processor_) {
processor_->AddCurrentStack(isolate_); processor_->AddCurrentStack(isolate_);
} }
} }
...@@ -557,7 +551,7 @@ void CpuProfiler::StartProfiling(String* title, bool record_samples) { ...@@ -557,7 +551,7 @@ void CpuProfiler::StartProfiling(String* title, bool record_samples) {
void CpuProfiler::StartProcessorIfNotStarted() { void CpuProfiler::StartProcessorIfNotStarted() {
if (processor_ != NULL) { if (processor_) {
processor_->AddCurrentStack(isolate_); processor_->AddCurrentStack(isolate_);
return; return;
} }
...@@ -565,10 +559,10 @@ void CpuProfiler::StartProcessorIfNotStarted() { ...@@ -565,10 +559,10 @@ void CpuProfiler::StartProcessorIfNotStarted() {
// Disable logging when using the new implementation. // Disable logging when using the new implementation.
saved_is_logging_ = logger->is_logging_; saved_is_logging_ = logger->is_logging_;
logger->is_logging_ = false; logger->is_logging_ = false;
generator_ = new ProfileGenerator(profiles_);
sampler::Sampler* sampler = logger->sampler(); sampler::Sampler* sampler = logger->sampler();
processor_ = new ProfilerEventsProcessor( generator_.reset(new ProfileGenerator(profiles_.get()));
generator_, sampler, sampling_interval_); processor_.reset(new ProfilerEventsProcessor(generator_.get(), sampler,
sampling_interval_));
is_profiling_ = true; is_profiling_ = true;
isolate_->set_is_profiling(true); isolate_->set_is_profiling(true);
// Enumerate stuff we already have in the heap. // Enumerate stuff we already have in the heap.
...@@ -588,10 +582,10 @@ void CpuProfiler::StartProcessorIfNotStarted() { ...@@ -588,10 +582,10 @@ void CpuProfiler::StartProcessorIfNotStarted() {
CpuProfile* CpuProfiler::StopProfiling(const char* title) { CpuProfile* CpuProfiler::StopProfiling(const char* title) {
if (!is_profiling_) return NULL; if (!is_profiling_) return nullptr;
StopProcessorIfLastProfile(title); StopProcessorIfLastProfile(title);
CpuProfile* result = profiles_->StopProfiling(title); CpuProfile* result = profiles_->StopProfiling(title);
if (result != NULL) { if (result) {
result->Print(); result->Print();
} }
return result; return result;
...@@ -599,7 +593,7 @@ CpuProfile* CpuProfiler::StopProfiling(const char* title) { ...@@ -599,7 +593,7 @@ CpuProfile* CpuProfiler::StopProfiling(const char* title) {
CpuProfile* CpuProfiler::StopProfiling(String* title) { CpuProfile* CpuProfiler::StopProfiling(String* title) {
if (!is_profiling_) return NULL; if (!is_profiling_) return nullptr;
const char* profile_title = profiles_->GetName(title); const char* profile_title = profiles_->GetName(title);
StopProcessorIfLastProfile(profile_title); StopProcessorIfLastProfile(profile_title);
return profiles_->StopProfiling(profile_title); return profiles_->StopProfiling(profile_title);
...@@ -607,7 +601,9 @@ CpuProfile* CpuProfiler::StopProfiling(String* title) { ...@@ -607,7 +601,9 @@ CpuProfile* CpuProfiler::StopProfiling(String* title) {
void CpuProfiler::StopProcessorIfLastProfile(const char* title) { void CpuProfiler::StopProcessorIfLastProfile(const char* title) {
if (profiles_->IsLastProfile(title)) StopProcessor(); if (profiles_->IsLastProfile(title)) {
StopProcessor();
}
} }
...@@ -618,10 +614,8 @@ void CpuProfiler::StopProcessor() { ...@@ -618,10 +614,8 @@ void CpuProfiler::StopProcessor() {
is_profiling_ = false; is_profiling_ = false;
isolate_->set_is_profiling(false); isolate_->set_is_profiling(false);
processor_->StopSynchronously(); processor_->StopSynchronously();
delete processor_; processor_.reset();
delete generator_; generator_.reset();
processor_ = NULL;
generator_ = NULL;
sampler->SetHasProcessingThread(false); sampler->SetHasProcessingThread(false);
sampler->DecreaseProfilingDepth(); sampler->DecreaseProfilingDepth();
logger->is_logging_ = saved_is_logging_; logger->is_logging_ = saved_is_logging_;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef V8_PROFILER_CPU_PROFILER_H_ #ifndef V8_PROFILER_CPU_PROFILER_H_
#define V8_PROFILER_CPU_PROFILER_H_ #define V8_PROFILER_CPU_PROFILER_H_
#include <memory>
#include "src/allocation.h" #include "src/allocation.h"
#include "src/base/atomic-utils.h" #include "src/base/atomic-utils.h"
#include "src/base/atomicops.h" #include "src/base/atomicops.h"
...@@ -193,8 +195,7 @@ class CpuProfiler : public CodeEventListener { ...@@ -193,8 +195,7 @@ class CpuProfiler : public CodeEventListener {
public: public:
explicit CpuProfiler(Isolate* isolate); explicit CpuProfiler(Isolate* isolate);
CpuProfiler(Isolate* isolate, CpuProfiler(Isolate* isolate, CpuProfilesCollection* profiles,
CpuProfilesCollection* test_collection,
ProfileGenerator* test_generator, ProfileGenerator* test_generator,
ProfilerEventsProcessor* test_processor); ProfilerEventsProcessor* test_processor);
...@@ -241,8 +242,8 @@ class CpuProfiler : public CodeEventListener { ...@@ -241,8 +242,8 @@ class CpuProfiler : public CodeEventListener {
bool is_profiling() const { return is_profiling_; } bool is_profiling() const { return is_profiling_; }
ProfileGenerator* generator() const { return generator_; } ProfileGenerator* generator() const { return generator_.get(); }
ProfilerEventsProcessor* processor() const { return processor_; } ProfilerEventsProcessor* processor() const { return processor_.get(); }
Isolate* isolate() const { return isolate_; } Isolate* isolate() const { return isolate_; }
private: private:
...@@ -255,11 +256,11 @@ class CpuProfiler : public CodeEventListener { ...@@ -255,11 +256,11 @@ class CpuProfiler : public CodeEventListener {
void RecordDeoptInlinedFrames(CodeEntry* entry, AbstractCode* abstract_code); void RecordDeoptInlinedFrames(CodeEntry* entry, AbstractCode* abstract_code);
Name* InferScriptName(Name* name, SharedFunctionInfo* info); Name* InferScriptName(Name* name, SharedFunctionInfo* info);
Isolate* isolate_; Isolate* const isolate_;
base::TimeDelta sampling_interval_; base::TimeDelta sampling_interval_;
CpuProfilesCollection* profiles_; std::unique_ptr<CpuProfilesCollection> profiles_;
ProfileGenerator* generator_; std::unique_ptr<ProfileGenerator> generator_;
ProfilerEventsProcessor* processor_; std::unique_ptr<ProfilerEventsProcessor> processor_;
bool saved_is_logging_; bool saved_is_logging_;
bool is_profiling_; bool is_profiling_;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/deoptimizer.h" #include "src/deoptimizer.h"
#include "src/global-handles.h" #include "src/global-handles.h"
#include "src/profiler/cpu-profiler.h"
#include "src/profiler/profile-generator-inl.h" #include "src/profiler/profile-generator-inl.h"
#include "src/profiler/tick-sample.h" #include "src/profiler/tick-sample.h"
#include "src/unicode.h" #include "src/unicode.h"
...@@ -365,12 +366,13 @@ void ProfileTree::TraverseDepthFirst(Callback* callback) { ...@@ -365,12 +366,13 @@ void ProfileTree::TraverseDepthFirst(Callback* callback) {
} }
} }
CpuProfile::CpuProfile(CpuProfiler* profiler, const char* title,
CpuProfile::CpuProfile(Isolate* isolate, const char* title, bool record_samples) bool record_samples)
: title_(title), : title_(title),
record_samples_(record_samples), record_samples_(record_samples),
start_time_(base::TimeTicks::HighResolutionNow()), start_time_(base::TimeTicks::HighResolutionNow()),
top_down_(isolate) {} top_down_(profiler->isolate()),
profiler_(profiler) {}
void CpuProfile::AddPath(base::TimeTicks timestamp, void CpuProfile::AddPath(base::TimeTicks timestamp,
const std::vector<CodeEntry*>& path, int src_line, const std::vector<CodeEntry*>& path, int src_line,
...@@ -432,12 +434,11 @@ void CodeMap::Print() { ...@@ -432,12 +434,11 @@ void CodeMap::Print() {
} }
} }
CpuProfilesCollection::CpuProfilesCollection(Heap* heap) CpuProfilesCollection::CpuProfilesCollection(Isolate* isolate)
: function_and_resource_names_(heap), : function_and_resource_names_(isolate->heap()),
isolate_(heap->isolate()), profiler_(nullptr),
current_profiles_semaphore_(1) {} current_profiles_semaphore_(1) {}
static void DeleteCodeEntry(CodeEntry** entry_ptr) { static void DeleteCodeEntry(CodeEntry** entry_ptr) {
delete *entry_ptr; delete *entry_ptr;
} }
...@@ -470,7 +471,7 @@ bool CpuProfilesCollection::StartProfiling(const char* title, ...@@ -470,7 +471,7 @@ bool CpuProfilesCollection::StartProfiling(const char* title,
return true; return true;
} }
} }
current_profiles_.Add(new CpuProfile(isolate_, title, record_samples)); current_profiles_.Add(new CpuProfile(profiler_, title, record_samples));
current_profiles_semaphore_.Signal(); current_profiles_semaphore_.Signal();
return true; return true;
} }
......
...@@ -228,7 +228,7 @@ class ProfileTree { ...@@ -228,7 +228,7 @@ class ProfileTree {
class CpuProfile { class CpuProfile {
public: public:
CpuProfile(Isolate* isolate, const char* title, bool record_samples); CpuProfile(CpuProfiler* profiler, const char* title, bool record_samples);
// Add pc -> ... -> main() call path to the profile. // Add pc -> ... -> main() call path to the profile.
void AddPath(base::TimeTicks timestamp, const std::vector<CodeEntry*>& path, void AddPath(base::TimeTicks timestamp, const std::vector<CodeEntry*>& path,
...@@ -246,6 +246,7 @@ class CpuProfile { ...@@ -246,6 +246,7 @@ class CpuProfile {
base::TimeTicks start_time() const { return start_time_; } base::TimeTicks start_time() const { return start_time_; }
base::TimeTicks end_time() const { return end_time_; } base::TimeTicks end_time() const { return end_time_; }
CpuProfiler* cpu_profiler() const { return profiler_; }
void UpdateTicksScale(); void UpdateTicksScale();
...@@ -259,6 +260,7 @@ class CpuProfile { ...@@ -259,6 +260,7 @@ class CpuProfile {
List<ProfileNode*> samples_; List<ProfileNode*> samples_;
List<base::TimeTicks> timestamps_; List<base::TimeTicks> timestamps_;
ProfileTree top_down_; ProfileTree top_down_;
CpuProfiler* const profiler_;
DISALLOW_COPY_AND_ASSIGN(CpuProfile); DISALLOW_COPY_AND_ASSIGN(CpuProfile);
}; };
...@@ -289,9 +291,10 @@ class CodeMap { ...@@ -289,9 +291,10 @@ class CodeMap {
class CpuProfilesCollection { class CpuProfilesCollection {
public: public:
explicit CpuProfilesCollection(Heap* heap); explicit CpuProfilesCollection(Isolate* isolate);
~CpuProfilesCollection(); ~CpuProfilesCollection();
void set_cpu_profiler(CpuProfiler* profiler) { profiler_ = profiler; }
bool StartProfiling(const char* title, bool record_samples); bool StartProfiling(const char* title, bool record_samples);
CpuProfile* StopProfiling(const char* title); CpuProfile* StopProfiling(const char* title);
List<CpuProfile*>* profiles() { return &finished_profiles_; } List<CpuProfile*>* profiles() { return &finished_profiles_; }
...@@ -330,8 +333,7 @@ class CpuProfilesCollection { ...@@ -330,8 +333,7 @@ class CpuProfilesCollection {
StringsStorage function_and_resource_names_; StringsStorage function_and_resource_names_;
List<CodeEntry*> code_entries_; List<CodeEntry*> code_entries_;
List<CpuProfile*> finished_profiles_; List<CpuProfile*> finished_profiles_;
CpuProfiler* profiler_;
Isolate* isolate_;
// Accessed by VM thread and profile generator thread. // Accessed by VM thread and profile generator thread.
List<CpuProfile*> current_profiles_; List<CpuProfile*> current_profiles_;
......
...@@ -31,12 +31,12 @@ ...@@ -31,12 +31,12 @@
#include "include/v8-profiler.h" #include "include/v8-profiler.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/base/smart-pointers.h"
#include "src/deoptimizer.h" #include "src/deoptimizer.h"
#include "src/profiler/cpu-profiler-inl.h" #include "src/profiler/cpu-profiler-inl.h"
#include "src/utils.h" #include "src/utils.h"
#include "test/cctest/cctest.h" #include "test/cctest/cctest.h"
#include "test/cctest/profiler-extension.h" #include "test/cctest/profiler-extension.h"
using i::CodeEntry; using i::CodeEntry;
using i::CpuProfile; using i::CpuProfile;
using i::CpuProfiler; using i::CpuProfiler;
...@@ -47,8 +47,6 @@ using i::ProfileNode; ...@@ -47,8 +47,6 @@ using i::ProfileNode;
using i::ProfilerEventsProcessor; using i::ProfilerEventsProcessor;
using i::ScopedVector; using i::ScopedVector;
using i::Vector; using i::Vector;
using v8::base::SmartPointer;
// Helper methods // Helper methods
static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env, static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env,
...@@ -57,30 +55,26 @@ static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env, ...@@ -57,30 +55,26 @@ static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env,
env->Global()->Get(env, v8_str(name)).ToLocalChecked()); env->Global()->Get(env, v8_str(name)).ToLocalChecked());
} }
static size_t offset(const char* src, const char* substring) { static size_t offset(const char* src, const char* substring) {
const char* it = strstr(src, substring); const char* it = strstr(src, substring);
CHECK(it); CHECK(it);
return static_cast<size_t>(it - src); return static_cast<size_t>(it - src);
} }
static const char* reason(const i::Deoptimizer::DeoptReason reason) { static const char* reason(const i::Deoptimizer::DeoptReason reason) {
return i::Deoptimizer::GetDeoptReason(reason); return i::Deoptimizer::GetDeoptReason(reason);
} }
TEST(StartStop) { TEST(StartStop) {
i::Isolate* isolate = CcTest::i_isolate(); CpuProfilesCollection profiles(CcTest::i_isolate());
CpuProfilesCollection profiles(isolate->heap());
ProfileGenerator generator(&profiles); ProfileGenerator generator(&profiles);
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( std::unique_ptr<ProfilerEventsProcessor> processor(
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); new ProfilerEventsProcessor(&generator, nullptr,
v8::base::TimeDelta::FromMicroseconds(100)));
processor->Start(); processor->Start();
processor->StopSynchronously(); processor->StopSynchronously();
} }
static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
i::Address frame1, i::Address frame1,
i::Address frame2 = NULL, i::Address frame2 = NULL,
...@@ -157,13 +151,13 @@ TEST(CodeEvents) { ...@@ -157,13 +151,13 @@ TEST(CodeEvents) {
i::AbstractCode* args3_code = CreateCode(&env); i::AbstractCode* args3_code = CreateCode(&env);
i::AbstractCode* args4_code = CreateCode(&env); i::AbstractCode* args4_code = CreateCode(&env);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(
generator, nullptr, v8::base::TimeDelta::FromMicroseconds(100));
CpuProfiler profiler(isolate, profiles, generator, processor);
profiles->StartProfiling("", false); profiles->StartProfiling("", false);
ProfileGenerator generator(profiles);
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
processor->Start(); processor->Start();
CpuProfiler profiler(isolate, profiles, &generator, processor.get());
// Enqueue code creation events. // Enqueue code creation events.
const char* aaa_str = "aaa"; const char* aaa_str = "aaa";
...@@ -177,26 +171,27 @@ TEST(CodeEvents) { ...@@ -177,26 +171,27 @@ TEST(CodeEvents) {
profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4); profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4);
// Enqueue a tick event to enable code events processing. // Enqueue a tick event to enable code events processing.
EnqueueTickSampleEvent(processor.get(), aaa_code->address()); EnqueueTickSampleEvent(processor, aaa_code->address());
processor->StopSynchronously(); processor->StopSynchronously();
// Check the state of profile generator. // Check the state of profile generator.
CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address()); CodeEntry* aaa = generator->code_map()->FindEntry(aaa_code->address());
CHECK(aaa); CHECK(aaa);
CHECK_EQ(0, strcmp(aaa_str, aaa->name())); CHECK_EQ(0, strcmp(aaa_str, aaa->name()));
CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address()); CodeEntry* comment =
generator->code_map()->FindEntry(comment_code->address());
CHECK(comment); CHECK(comment);
CHECK_EQ(0, strcmp("comment", comment->name())); CHECK_EQ(0, strcmp("comment", comment->name()));
CodeEntry* args5 = generator.code_map()->FindEntry(args5_code->address()); CodeEntry* args5 = generator->code_map()->FindEntry(args5_code->address());
CHECK(args5); CHECK(args5);
CHECK_EQ(0, strcmp("5", args5->name())); CHECK_EQ(0, strcmp("5", args5->name()));
CHECK(!generator.code_map()->FindEntry(comment2_code->address())); CHECK(!generator->code_map()->FindEntry(comment2_code->address()));
CodeEntry* comment2 = generator.code_map()->FindEntry(moved_code->address()); CodeEntry* comment2 = generator->code_map()->FindEntry(moved_code->address());
CHECK(comment2); CHECK(comment2);
CHECK_EQ(0, strcmp("comment2", comment2->name())); CHECK_EQ(0, strcmp("comment2", comment2->name()));
} }
...@@ -216,26 +211,24 @@ TEST(TickEvents) { ...@@ -216,26 +211,24 @@ TEST(TickEvents) {
i::AbstractCode* frame2_code = CreateCode(&env); i::AbstractCode* frame2_code = CreateCode(&env);
i::AbstractCode* frame3_code = CreateCode(&env); i::AbstractCode* frame3_code = CreateCode(&env);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(
generator, nullptr, v8::base::TimeDelta::FromMicroseconds(100));
CpuProfiler profiler(isolate, profiles, generator, processor);
profiles->StartProfiling("", false); profiles->StartProfiling("", false);
ProfileGenerator generator(profiles);
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
processor->Start(); processor->Start();
CpuProfiler profiler(isolate, profiles, &generator, processor.get());
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb");
profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5);
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd");
EnqueueTickSampleEvent(processor.get(), frame1_code->instruction_start()); EnqueueTickSampleEvent(processor, frame1_code->instruction_start());
EnqueueTickSampleEvent( EnqueueTickSampleEvent(
processor.get(), processor,
frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2,
frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2);
EnqueueTickSampleEvent( EnqueueTickSampleEvent(processor, frame3_code->instruction_end() - 1,
processor.get(),
frame3_code->instruction_end() - 1,
frame2_code->instruction_end() - 1, frame2_code->instruction_end() - 1,
frame1_code->instruction_end() - 1); frame1_code->instruction_end() - 1);
...@@ -283,13 +276,13 @@ TEST(Issue1398) { ...@@ -283,13 +276,13 @@ TEST(Issue1398) {
i::AbstractCode* code = CreateCode(&env); i::AbstractCode* code = CreateCode(&env);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(
generator, nullptr, v8::base::TimeDelta::FromMicroseconds(100));
CpuProfiler profiler(isolate, profiles, generator, processor);
profiles->StartProfiling("", false); profiles->StartProfiling("", false);
ProfileGenerator generator(profiles);
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
processor->Start(); processor->Start();
CpuProfiler profiler(isolate, profiles, &generator, processor.get());
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
...@@ -1021,13 +1014,13 @@ static void TickLines(bool optimize) { ...@@ -1021,13 +1014,13 @@ static void TickLines(bool optimize) {
i::Address code_address = code->instruction_start(); i::Address code_address = code->instruction_start();
CHECK(code_address); CHECK(code_address);
CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate);
ProfileGenerator* generator = new ProfileGenerator(profiles);
ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(
generator, nullptr, v8::base::TimeDelta::FromMicroseconds(100));
CpuProfiler profiler(isolate, profiles, generator, processor);
profiles->StartProfiling("", false); profiles->StartProfiling("", false);
ProfileGenerator generator(profiles);
SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
&generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
processor->Start(); processor->Start();
CpuProfiler profiler(isolate, profiles, &generator, processor.get());
// Enqueue code creation events. // Enqueue code creation events.
i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name); i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name);
...@@ -1037,7 +1030,7 @@ static void TickLines(bool optimize) { ...@@ -1037,7 +1030,7 @@ static void TickLines(bool optimize) {
line, column); line, column);
// Enqueue a tick event to enable code events processing. // Enqueue a tick event to enable code events processing.
EnqueueTickSampleEvent(processor.get(), code_address); EnqueueTickSampleEvent(processor, code_address);
processor->StopSynchronously(); processor->StopSynchronously();
...@@ -1045,7 +1038,7 @@ static void TickLines(bool optimize) { ...@@ -1045,7 +1038,7 @@ static void TickLines(bool optimize) {
CHECK(profile); CHECK(profile);
// Check the state of profile generator. // Check the state of profile generator.
CodeEntry* func_entry = generator.code_map()->FindEntry(code_address); CodeEntry* func_entry = generator->code_map()->FindEntry(code_address);
CHECK(func_entry); CHECK(func_entry);
CHECK_EQ(0, strcmp(func_name, func_entry->name())); CHECK_EQ(0, strcmp(func_name, func_entry->name()));
const i::JITLineInfoTable* line_info = func_entry->line_info(); const i::JITLineInfoTable* line_info = func_entry->line_info();
......
...@@ -344,7 +344,8 @@ class TestSetup { ...@@ -344,7 +344,8 @@ class TestSetup {
TEST(RecordTickSample) { TEST(RecordTickSample) {
TestSetup test_setup; TestSetup test_setup;
CpuProfilesCollection profiles(CcTest::heap()); CpuProfilesCollection profiles(CcTest::i_isolate());
profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
profiles.StartProfiling("", false); profiles.StartProfiling("", false);
ProfileGenerator generator(&profiles); ProfileGenerator generator(&profiles);
CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
...@@ -410,7 +411,8 @@ static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) { ...@@ -410,7 +411,8 @@ static void CheckNodeIds(ProfileNode* node, unsigned* expectedId) {
TEST(SampleIds) { TEST(SampleIds) {
TestSetup test_setup; TestSetup test_setup;
CpuProfilesCollection profiles(CcTest::heap()); CpuProfilesCollection profiles(CcTest::i_isolate());
profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
profiles.StartProfiling("", true); profiles.StartProfiling("", true);
ProfileGenerator generator(&profiles); ProfileGenerator generator(&profiles);
CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
...@@ -461,7 +463,8 @@ TEST(SampleIds) { ...@@ -461,7 +463,8 @@ TEST(SampleIds) {
TEST(NoSamples) { TEST(NoSamples) {
TestSetup test_setup; TestSetup test_setup;
CpuProfilesCollection profiles(CcTest::heap()); CpuProfilesCollection profiles(CcTest::i_isolate());
profiles.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
profiles.StartProfiling("", false); profiles.StartProfiling("", false);
ProfileGenerator generator(&profiles); ProfileGenerator generator(&profiles);
CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa"); CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
...@@ -544,7 +547,8 @@ TEST(RecordStackTraceAtStartProfiling) { ...@@ -544,7 +547,8 @@ TEST(RecordStackTraceAtStartProfiling) {
TEST(Issue51919) { TEST(Issue51919) {
CpuProfilesCollection collection(CcTest::heap()); CpuProfilesCollection collection(CcTest::i_isolate());
collection.set_cpu_profiler(CcTest::i_isolate()->cpu_profiler());
i::EmbeddedVector<char*, i::EmbeddedVector<char*,
CpuProfilesCollection::kMaxSimultaneousProfiles> titles; CpuProfilesCollection::kMaxSimultaneousProfiles> titles;
for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) { for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) {
...@@ -618,16 +622,12 @@ TEST(ProfileNodeScriptId) { ...@@ -618,16 +622,12 @@ TEST(ProfileNodeScriptId) {
CHECK_EQ(script_a->GetUnboundScript()->GetId(), current->GetScriptId()); CHECK_EQ(script_a->GetUnboundScript()->GetId(), current->GetScriptId());
} }
static const char* line_number_test_source_existing_functions = static const char* line_number_test_source_existing_functions =
"function foo_at_the_first_line() {\n" "function foo_at_the_first_line() {\n"
"}\n" "}\n"
"foo_at_the_first_line();\n" "foo_at_the_first_line();\n"
"function lazy_func_at_forth_line() {}\n"; "function lazy_func_at_forth_line() {}\n";
static const char* line_number_test_source_profile_time_functions = static const char* line_number_test_source_profile_time_functions =
"// Empty first line\n" "// Empty first line\n"
"function bar_at_the_second_line() {\n" "function bar_at_the_second_line() {\n"
...@@ -652,7 +652,6 @@ int GetFunctionLineNumber(LocalContext* env, const char* name) { ...@@ -652,7 +652,6 @@ int GetFunctionLineNumber(LocalContext* env, const char* name) {
return func_entry->line_number(); return func_entry->line_number();
} }
TEST(LineNumber) { TEST(LineNumber) {
i::FLAG_use_inlining = false; i::FLAG_use_inlining = false;
...@@ -683,8 +682,6 @@ TEST(LineNumber) { ...@@ -683,8 +682,6 @@ TEST(LineNumber) {
profiler->StopProfiling("LineNumber"); profiler->StopProfiling("LineNumber");
} }
TEST(BailoutReason) { TEST(BailoutReason) {
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
......
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