CpuProfiler: eliminate 2 layers of 4 for CodeCreateEvent calls.

The bodies of methods in ProfilerEventProcessor were moved into CpuProfiler.
Multiple NewCodeEntry methods in CpuProfilesCollection were replaced with one which
simply passes arguments to the CodeEntry constructor.
And CpuProfiler just calls this method when it needs a CodeEntry object.

This NewCodeEntry method is required because CpuProfilesCollection keeps ownership of CodeEntry objects.

BUG=255392
TEST=existing tests
R=yangguo@chromium.org, yurys@chromium.org

Committed: https://code.google.com/p/v8/source/detail?r=15405

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15407 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
loislo@chromium.org 2013-07-01 10:12:03 +00:00
parent baa3a7e47b
commit ca90f4b058
8 changed files with 339 additions and 369 deletions

View File

@ -64,16 +64,6 @@ TickSample* ProfilerEventsProcessor::TickSampleEvent() {
} }
bool ProfilerEventsProcessor::FilterOutCodeCreateEvent(
Logger::LogEventsAndTags tag) {
return FLAG_prof_browser_mode
&& (tag != Logger::CALLBACK_TAG
&& tag != Logger::FUNCTION_TAG
&& tag != Logger::LAZY_COMPILE_TAG
&& tag != Logger::REG_EXP_TAG
&& tag != Logger::SCRIPT_TAG);
}
} } // namespace v8::internal } } // namespace v8::internal
#endif // V8_CPU_PROFILER_INL_H_ #endif // V8_CPU_PROFILER_INL_H_

View File

@ -58,120 +58,9 @@ ProfilerEventsProcessor::ProfilerEventsProcessor(
} }
void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) {
const char* prefix, event.generic.order = ++enqueue_order_;
Name* name, events_buffer_.Enqueue(event);
Address start) {
if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec;
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->type = CodeEventRecord::CODE_CREATION;
rec->order = ++enqueue_order_;
rec->start = start;
rec->entry = profiles_->NewCodeEntry(tag, prefix, name);
rec->size = 1;
rec->shared = NULL;
events_buffer_.Enqueue(evt_rec);
}
void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag,
Name* name,
String* resource_name,
int line_number,
Address start,
unsigned size,
Address shared,
CompilationInfo* info) {
if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec;
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->type = CodeEventRecord::CODE_CREATION;
rec->order = ++enqueue_order_;
rec->start = start;
rec->entry = profiles_->NewCodeEntry(tag, name, resource_name, line_number);
if (info) {
rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
}
rec->size = size;
rec->shared = shared;
events_buffer_.Enqueue(evt_rec);
}
void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag,
const char* name,
Address start,
unsigned size) {
if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec;
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->type = CodeEventRecord::CODE_CREATION;
rec->order = ++enqueue_order_;
rec->start = start;
rec->entry = profiles_->NewCodeEntry(tag, name);
rec->size = size;
rec->shared = NULL;
events_buffer_.Enqueue(evt_rec);
}
void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag,
int args_count,
Address start,
unsigned size) {
if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec;
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->type = CodeEventRecord::CODE_CREATION;
rec->order = ++enqueue_order_;
rec->start = start;
rec->entry = profiles_->NewCodeEntry(tag, args_count);
rec->size = size;
rec->shared = NULL;
events_buffer_.Enqueue(evt_rec);
}
void ProfilerEventsProcessor::CodeMoveEvent(Address from, Address to) {
CodeEventsContainer evt_rec;
CodeMoveEventRecord* rec = &evt_rec.CodeMoveEventRecord_;
rec->type = CodeEventRecord::CODE_MOVE;
rec->order = ++enqueue_order_;
rec->from = from;
rec->to = to;
events_buffer_.Enqueue(evt_rec);
}
void ProfilerEventsProcessor::SharedFunctionInfoMoveEvent(Address from,
Address to) {
CodeEventsContainer evt_rec;
SharedFunctionInfoMoveEventRecord* rec =
&evt_rec.SharedFunctionInfoMoveEventRecord_;
rec->type = CodeEventRecord::SHARED_FUNC_MOVE;
rec->order = ++enqueue_order_;
rec->from = from;
rec->to = to;
events_buffer_.Enqueue(evt_rec);
}
void ProfilerEventsProcessor::RegExpCodeCreateEvent(
Logger::LogEventsAndTags tag,
const char* prefix,
String* name,
Address start,
unsigned size) {
if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec;
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->type = CodeEventRecord::CODE_CREATION;
rec->order = ++enqueue_order_;
rec->start = start;
rec->entry = profiles_->NewCodeEntry(tag, prefix, name);
rec->size = size;
events_buffer_.Enqueue(evt_rec);
} }
@ -305,30 +194,56 @@ bool CpuProfiler::HasDetachedProfiles() {
} }
static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag) {
return FLAG_prof_browser_mode
&& (tag != Logger::CALLBACK_TAG
&& tag != Logger::FUNCTION_TAG
&& tag != Logger::LAZY_COMPILE_TAG
&& tag != Logger::REG_EXP_TAG
&& tag != Logger::SCRIPT_TAG);
}
void CpuProfiler::CallbackEvent(Name* name, Address entry_point) { void CpuProfiler::CallbackEvent(Name* name, Address entry_point) {
processor_->CallbackCreateEvent( if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return;
Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point); CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->start = entry_point;
rec->entry = profiles_->NewCodeEntry(
Logger::CALLBACK_TAG,
profiles_->GetName(name),
TokenEnumerator::kInheritsSecurityToken);
rec->size = 1;
rec->shared = NULL;
processor_->Enqueue(evt_rec);
} }
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, const char* comment) { Code* code,
processor_->CodeCreateEvent( const char* name) {
tag, comment, code->address(), code->ExecutableSize()); if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->start = code->address();
rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name));
rec->size = code->ExecutableSize();
rec->shared = NULL;
processor_->Enqueue(evt_rec);
} }
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, Name* name) { Code* code,
processor_->CodeCreateEvent( Name* name) {
tag, if (FilterOutCodeCreateEvent(tag)) return;
name, CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
isolate_->heap()->empty_string(), CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
v8::CpuProfileNode::kNoLineNumberInfo, rec->start = code->address();
code->address(), rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name));
code->ExecutableSize(), rec->size = code->ExecutableSize();
NULL, rec->shared = NULL;
NULL); processor_->Enqueue(evt_rec);
} }
@ -337,15 +252,17 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
SharedFunctionInfo* shared, SharedFunctionInfo* shared,
CompilationInfo* info, CompilationInfo* info,
Name* name) { Name* name) {
processor_->CodeCreateEvent( if (FilterOutCodeCreateEvent(tag)) return;
tag, CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
name, CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
isolate_->heap()->empty_string(), rec->start = code->address();
v8::CpuProfileNode::kNoLineNumberInfo, rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name));
code->address(), rec->entry->set_no_frame_ranges(info ?
code->ExecutableSize(), info->ReleaseNoFrameRanges() :
shared->address(), NULL);
info); rec->size = code->ExecutableSize();
rec->shared = shared->address();
processor_->Enqueue(evt_rec);
} }
@ -354,30 +271,50 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
SharedFunctionInfo* shared, SharedFunctionInfo* shared,
CompilationInfo* info, CompilationInfo* info,
String* source, int line) { String* source, int line) {
processor_->CodeCreateEvent( if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->start = code->address();
rec->entry = profiles_->NewCodeEntry(
tag, tag,
shared->DebugName(), profiles_->GetFunctionName(shared->DebugName()),
source, TokenEnumerator::kNoSecurityToken,
line, CodeEntry::kEmptyNamePrefix,
code->address(), profiles_->GetName(source),
code->ExecutableSize(), line);
shared->address(), rec->entry->set_no_frame_ranges(info ?
info); info->ReleaseNoFrameRanges() :
NULL);
rec->size = code->ExecutableSize();
rec->shared = shared->address();
processor_->Enqueue(evt_rec);
} }
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, int args_count) { Code* code,
processor_->CodeCreateEvent( int args_count) {
if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->start = code->address();
rec->entry = profiles_->NewCodeEntry(
tag, tag,
args_count, profiles_->GetName(args_count),
code->address(), TokenEnumerator::kInheritsSecurityToken,
code->ExecutableSize()); "args_count: ");
rec->size = code->ExecutableSize();
rec->shared = NULL;
processor_->Enqueue(evt_rec);
} }
void CpuProfiler::CodeMoveEvent(Address from, Address to) { void CpuProfiler::CodeMoveEvent(Address from, Address to) {
processor_->CodeMoveEvent(from, to); CodeEventsContainer evt_rec(CodeEventRecord::CODE_MOVE);
CodeMoveEventRecord* rec = &evt_rec.CodeMoveEventRecord_;
rec->from = from;
rec->to = to;
processor_->Enqueue(evt_rec);
} }
@ -386,29 +323,59 @@ void CpuProfiler::CodeDeleteEvent(Address from) {
void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) { void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) {
processor_->SharedFunctionInfoMoveEvent(from, to); CodeEventsContainer evt_rec(CodeEventRecord::SHARED_FUNC_MOVE);
SharedFunctionInfoMoveEventRecord* rec =
&evt_rec.SharedFunctionInfoMoveEventRecord_;
rec->from = from;
rec->to = to;
processor_->Enqueue(evt_rec);
} }
void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) { void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) {
processor_->CallbackCreateEvent( if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return;
Logger::CALLBACK_TAG, "get ", name, entry_point); CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->start = entry_point;
rec->entry = profiles_->NewCodeEntry(
Logger::CALLBACK_TAG,
profiles_->GetName(name),
TokenEnumerator::kInheritsSecurityToken,
"get ");
rec->size = 1;
rec->shared = NULL;
processor_->Enqueue(evt_rec);
} }
void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) {
processor_->RegExpCodeCreateEvent( if (FilterOutCodeCreateEvent(Logger::REG_EXP_TAG)) return;
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->start = code->address();
rec->entry = profiles_->NewCodeEntry(
Logger::REG_EXP_TAG, Logger::REG_EXP_TAG,
"RegExp: ", profiles_->GetName(source),
source, TokenEnumerator::kInheritsSecurityToken,
code->address(), "RegExp: ");
code->ExecutableSize()); rec->size = code->ExecutableSize();
processor_->Enqueue(evt_rec);
} }
void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) { void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) {
processor_->CallbackCreateEvent( if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return;
Logger::CALLBACK_TAG, "set ", name, entry_point); CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->start = entry_point;
rec->entry = profiles_->NewCodeEntry(
Logger::CALLBACK_TAG,
profiles_->GetName(name),
TokenEnumerator::kInheritsSecurityToken,
"set ");
rec->size = 1;
rec->shared = NULL;
processor_->Enqueue(evt_rec);
} }
@ -424,6 +391,21 @@ CpuProfiler::CpuProfiler(Isolate* isolate)
} }
CpuProfiler::CpuProfiler(Isolate* isolate,
CpuProfilesCollection* test_profiles,
ProfileGenerator* test_generator,
ProfilerEventsProcessor* test_processor)
: isolate_(isolate),
profiles_(test_profiles),
next_profile_uid_(1),
token_enumerator_(new TokenEnumerator()),
generator_(test_generator),
processor_(test_processor),
need_to_stop_sampler_(false),
is_profiling_(false) {
}
CpuProfiler::~CpuProfiler() { CpuProfiler::~CpuProfiler() {
delete token_enumerator_; delete token_enumerator_;
delete profiles_; delete profiles_;

View File

@ -63,7 +63,7 @@ class CodeEventRecord {
#undef DECLARE_TYPE #undef DECLARE_TYPE
Type type; Type type;
unsigned order; mutable unsigned order;
}; };
@ -122,6 +122,21 @@ class TickSampleEventRecord {
}; };
class CodeEventsContainer {
public:
explicit CodeEventsContainer(
CodeEventRecord::Type type = CodeEventRecord::NONE) {
generic.type = type;
}
union {
CodeEventRecord generic;
#define DECLARE_CLASS(ignore, type) type type##_;
CODE_EVENTS_TYPE_LIST(DECLARE_CLASS)
#undef DECLARE_TYPE
};
};
// This class implements both the profile events processor thread and // This class implements both the profile events processor thread and
// methods called by event producers: VM and stack sampler threads. // methods called by event producers: VM and stack sampler threads.
class ProfilerEventsProcessor : public Thread { class ProfilerEventsProcessor : public Thread {
@ -134,29 +149,8 @@ class ProfilerEventsProcessor : public Thread {
virtual void Run(); virtual void Run();
inline void Stop() { running_ = false; } inline void Stop() { running_ = false; }
INLINE(bool running()) { return running_; } INLINE(bool running()) { return running_; }
void Enqueue(const CodeEventsContainer& event);
// Events adding methods. Called by VM threads.
void CallbackCreateEvent(Logger::LogEventsAndTags tag,
const char* prefix, Name* name,
Address start);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
Name* name,
String* resource_name, int line_number,
Address start, unsigned size,
Address shared,
CompilationInfo* info);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
const char* name,
Address start, unsigned size);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
int args_count,
Address start, unsigned size);
void CodeMoveEvent(Address from, Address to);
void CodeDeleteEvent(Address from);
void SharedFunctionInfoMoveEvent(Address from, Address to);
void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag,
const char* prefix, String* name,
Address start, unsigned size);
// Puts current stack into tick sample events buffer. // Puts current stack into tick sample events buffer.
void AddCurrentStack(); void AddCurrentStack();
@ -167,19 +161,10 @@ class ProfilerEventsProcessor : public Thread {
INLINE(TickSample* TickSampleEvent()); INLINE(TickSample* TickSampleEvent());
private: private:
union CodeEventsContainer {
CodeEventRecord generic;
#define DECLARE_CLASS(ignore, type) type type##_;
CODE_EVENTS_TYPE_LIST(DECLARE_CLASS)
#undef DECLARE_TYPE
};
// Called from events processing thread (Run() method.) // Called from events processing thread (Run() method.)
bool ProcessCodeEvent(unsigned* dequeue_order); bool ProcessCodeEvent(unsigned* dequeue_order);
bool ProcessTicks(unsigned dequeue_order); bool ProcessTicks(unsigned dequeue_order);
INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag));
ProfileGenerator* generator_; ProfileGenerator* generator_;
CpuProfilesCollection* profiles_; CpuProfilesCollection* profiles_;
bool running_; bool running_;
@ -204,6 +189,12 @@ class ProfilerEventsProcessor : public Thread {
class CpuProfiler { class CpuProfiler {
public: public:
explicit CpuProfiler(Isolate* isolate); explicit CpuProfiler(Isolate* isolate);
CpuProfiler(Isolate* isolate,
CpuProfilesCollection* test_collection,
ProfileGenerator* test_generator,
ProfilerEventsProcessor* test_processor);
~CpuProfiler(); ~CpuProfiler();
void StartProfiling(const char* title, bool record_samples = false); void StartProfiling(const char* title, bool record_samples = false);

View File

@ -44,9 +44,9 @@ const char* StringsStorage::GetFunctionName(const char* name) {
CodeEntry::CodeEntry(Logger::LogEventsAndTags tag, CodeEntry::CodeEntry(Logger::LogEventsAndTags tag,
const char* name_prefix,
const char* name, const char* name,
int security_token_id, int security_token_id,
const char* name_prefix,
const char* resource_name, const char* resource_name,
int line_number) int line_number)
: tag_(tag), : tag_(tag),

View File

@ -298,7 +298,7 @@ class DeleteNodesCallback {
ProfileTree::ProfileTree() ProfileTree::ProfileTree()
: root_entry_(Logger::FUNCTION_TAG, "", "(root)"), : root_entry_(Logger::FUNCTION_TAG, "(root)"),
next_node_id_(1), next_node_id_(1),
root_(new ProfileNode(this, &root_entry_)) { root_(new ProfileNode(this, &root_entry_)) {
} }
@ -787,54 +787,6 @@ List<CpuProfile*>* CpuProfilesCollection::Profiles(int security_token_id) {
} }
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
Name* name,
String* resource_name,
int line_number) {
CodeEntry* entry = new CodeEntry(tag,
CodeEntry::kEmptyNamePrefix,
GetFunctionName(name),
TokenEnumerator::kNoSecurityToken,
GetName(resource_name),
line_number);
code_entries_.Add(entry);
return entry;
}
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
const char* name) {
CodeEntry* entry = new CodeEntry(tag,
CodeEntry::kEmptyNamePrefix,
GetFunctionName(name));
code_entries_.Add(entry);
return entry;
}
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
const char* name_prefix,
Name* name) {
CodeEntry* entry = new CodeEntry(tag,
name_prefix,
GetName(name),
TokenEnumerator::kInheritsSecurityToken);
code_entries_.Add(entry);
return entry;
}
CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
int args_count) {
CodeEntry* entry = new CodeEntry(tag,
"args_count: ",
GetName(args_count),
TokenEnumerator::kInheritsSecurityToken);
code_entries_.Add(entry);
return entry;
}
void CpuProfilesCollection::AddPathToCurrentProfiles( void CpuProfilesCollection::AddPathToCurrentProfiles(
const Vector<CodeEntry*>& path) { const Vector<CodeEntry*>& path) {
// As starting / stopping profiles is rare relatively to this // As starting / stopping profiles is rare relatively to this
@ -848,6 +800,24 @@ void CpuProfilesCollection::AddPathToCurrentProfiles(
} }
CodeEntry* CpuProfilesCollection::NewCodeEntry(
Logger::LogEventsAndTags tag,
const char* name,
int security_token_id,
const char* name_prefix,
const char* resource_name,
int line_number) {
CodeEntry* code_entry = new CodeEntry(tag,
name,
security_token_id,
name_prefix,
resource_name,
line_number);
code_entries_.Add(code_entry);
return code_entry;
}
void SampleRateCalculator::Tick() { void SampleRateCalculator::Tick() {
if (--wall_time_query_countdown_ == 0) if (--wall_time_query_countdown_ == 0)
UpdateMeasurements(OS::TimeCurrentMillis()); UpdateMeasurements(OS::TimeCurrentMillis());

View File

@ -97,9 +97,9 @@ class CodeEntry {
public: public:
// CodeEntry doesn't own name strings, just references them. // CodeEntry doesn't own name strings, just references them.
INLINE(CodeEntry(Logger::LogEventsAndTags tag, INLINE(CodeEntry(Logger::LogEventsAndTags tag,
const char* name_prefix,
const char* name, const char* name,
int security_token_id = TokenEnumerator::kNoSecurityToken, int security_token_id = TokenEnumerator::kNoSecurityToken,
const char* name_prefix = CodeEntry::kEmptyNamePrefix,
const char* resource_name = CodeEntry::kEmptyResourceName, const char* resource_name = CodeEntry::kEmptyResourceName,
int line_number = v8::CpuProfileNode::kNoLineNumberInfo)); int line_number = v8::CpuProfileNode::kNoLineNumberInfo));
~CodeEntry(); ~CodeEntry();
@ -318,18 +318,24 @@ class CpuProfilesCollection {
const char* GetName(int args_count) { const char* GetName(int args_count) {
return function_and_resource_names_.GetName(args_count); return function_and_resource_names_.GetName(args_count);
} }
const char* GetFunctionName(Name* name) {
return function_and_resource_names_.GetFunctionName(name);
}
const char* GetFunctionName(const char* name) {
return function_and_resource_names_.GetFunctionName(name);
}
CpuProfile* GetProfile(int security_token_id, unsigned uid); CpuProfile* GetProfile(int security_token_id, unsigned uid);
bool IsLastProfile(const char* title); bool IsLastProfile(const char* title);
void RemoveProfile(CpuProfile* profile); void RemoveProfile(CpuProfile* profile);
bool HasDetachedProfiles() { return detached_profiles_.length() > 0; } bool HasDetachedProfiles() { return detached_profiles_.length() > 0; }
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, CodeEntry* NewCodeEntry(
Name* name, String* resource_name, int line_number); Logger::LogEventsAndTags tag,
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, const char* name); const char* name,
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, int security_token_id = TokenEnumerator::kNoSecurityToken,
const char* name_prefix, Name* name); const char* name_prefix = CodeEntry::kEmptyNamePrefix,
CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, int args_count); const char* resource_name = CodeEntry::kEmptyResourceName,
CodeEntry* NewCodeEntry(int security_token_id); int line_number = v8::CpuProfileNode::kNoLineNumberInfo);
// Called from profile generator thread. // Called from profile generator thread.
void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path); void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path);
@ -338,12 +344,6 @@ class CpuProfilesCollection {
static const int kMaxSimultaneousProfiles = 100; static const int kMaxSimultaneousProfiles = 100;
private: private:
const char* GetFunctionName(Name* name) {
return function_and_resource_names_.GetFunctionName(name);
}
const char* GetFunctionName(const char* name) {
return function_and_resource_names_.GetFunctionName(name);
}
int GetProfileIndex(unsigned uid); int GetProfileIndex(unsigned uid);
List<CpuProfile*>* GetProfilesList(int security_token_id); List<CpuProfile*>* GetProfilesList(int security_token_id);
int TokenToIndex(int security_token_id); int TokenToIndex(int security_token_id);

View File

@ -31,6 +31,7 @@
#include "v8.h" #include "v8.h"
#include "cpu-profiler-inl.h" #include "cpu-profiler-inl.h"
#include "cctest.h" #include "cctest.h"
#include "platform.h"
#include "utils.h" #include "utils.h"
#include "../include/v8-profiler.h" #include "../include/v8-profiler.h"
#undef V8_DISABLE_DEPRECATIONS #undef V8_DISABLE_DEPRECATIONS
@ -97,64 +98,89 @@ class TestSetup {
} // namespace } // namespace
i::Code* CreateCode(LocalContext* env) {
static int counter = 0;
i::EmbeddedVector<char, 256> script;
i::EmbeddedVector<char, 32> name;
i::OS::SNPrintF(name, "function_%d", ++counter);
const char* name_start = name.start();
i::OS::SNPrintF(script,
"function %s() {\n"
"var counter = 0;\n"
"for (var i = 0; i < %d; ++i) counter += i;\n"
"return '%s_' + counter;\n"
"}\n"
"%s();\n", name_start, counter, name_start, name_start);
CompileRun(script.start());
i::Handle<i::JSFunction> fun = v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(
(*env)->Global()->Get(v8_str(name_start))));
return fun->code();
}
TEST(CodeEvents) { TEST(CodeEvents) {
CcTest::InitializeVM(); CcTest::InitializeVM();
LocalContext env;
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
i::Heap* heap = isolate->heap();
i::Factory* factory = isolate->factory(); i::Factory* factory = isolate->factory();
TestSetup test_setup; TestSetup test_setup;
CpuProfilesCollection profiles;
profiles.StartProfiling("", 1, false); i::HandleScope scope(isolate);
ProfileGenerator generator(&profiles);
ProfilerEventsProcessor processor(&generator, &profiles); i::Code* aaa_code = CreateCode(&env);
i::Code* comment_code = CreateCode(&env);
i::Code* args5_code = CreateCode(&env);
i::Code* comment2_code = CreateCode(&env);
i::Code* moved_code = CreateCode(&env);
i::Code* args3_code = CreateCode(&env);
i::Code* args4_code = CreateCode(&env);
CpuProfilesCollection* profiles = new CpuProfilesCollection;
profiles->StartProfiling("", 1, false);
ProfileGenerator generator(profiles);
ProfilerEventsProcessor processor(&generator, profiles);
processor.Start(); processor.Start();
CpuProfiler profiler(isolate, profiles, &generator, &processor);
// Enqueue code creation events. // Enqueue code creation events.
i::HandleScope scope(isolate);
const char* aaa_str = "aaa"; const char* aaa_str = "aaa";
i::Handle<i::String> aaa_name = factory->NewStringFromAscii( i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
processor.CodeCreateEvent(i::Logger::FUNCTION_TAG, profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name);
*aaa_name, profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment");
heap->empty_string(), profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5);
0, profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2");
ToAddress(0x1000), profiler.CodeMoveEvent(comment2_code->address(), moved_code->address());
0x100, profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3);
ToAddress(0x10000), profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4);
NULL);
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
"bbb",
ToAddress(0x1200),
0x80);
processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
"ddd",
ToAddress(0x1400),
0x80);
processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500));
processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10);
processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10);
// Enqueue a tick event to enable code events processing. // Enqueue a tick event to enable code events processing.
EnqueueTickSampleEvent(&processor, ToAddress(0x1000)); EnqueueTickSampleEvent(&processor, aaa_code->address());
processor.Stop(); processor.Stop();
processor.Join(); processor.Join();
// Check the state of profile generator. // Check the state of profile generator.
CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000)); CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address());
CHECK_NE(NULL, entry1); CHECK_NE(NULL, aaa);
CHECK_EQ(aaa_str, entry1->name()); CHECK_EQ(aaa_str, aaa->name());
CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200));
CHECK_NE(NULL, entry2); CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address());
CHECK_EQ("bbb", entry2->name()); CHECK_NE(NULL, comment);
CodeEntry* entry3 = generator.code_map()->FindEntry(ToAddress(0x1300)); CHECK_EQ("comment", comment->name());
CHECK_NE(NULL, entry3);
CHECK_EQ("5", entry3->name()); CodeEntry* args5 = generator.code_map()->FindEntry(args5_code->address());
CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1400))); CHECK_NE(NULL, args5);
CodeEntry* entry4 = generator.code_map()->FindEntry(ToAddress(0x1500)); CHECK_EQ("5", args5->name());
CHECK_NE(NULL, entry4);
CHECK_EQ("ddd", entry4->name()); CHECK_EQ(NULL, generator.code_map()->FindEntry(comment2_code->address()));
CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1600)));
CodeEntry* comment2 = generator.code_map()->FindEntry(moved_code->address());
CHECK_NE(NULL, comment2);
CHECK_EQ("comment2", comment2->name());
} }
@ -165,32 +191,40 @@ static int CompareProfileNodes(const T* p1, const T* p2) {
TEST(TickEvents) { TEST(TickEvents) {
TestSetup test_setup; TestSetup test_setup;
CpuProfilesCollection profiles; LocalContext env;
profiles.StartProfiling("", 1, false); i::Isolate* isolate = i::Isolate::Current();
ProfileGenerator generator(&profiles); i::HandleScope scope(isolate);
ProfilerEventsProcessor processor(&generator, &profiles);
processor.Start();
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, i::Code* frame1_code = CreateCode(&env);
"bbb", i::Code* frame2_code = CreateCode(&env);
ToAddress(0x1200), i::Code* frame3_code = CreateCode(&env);
0x80);
processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); CpuProfilesCollection* profiles = new CpuProfilesCollection;
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, profiles->StartProfiling("", 1, false);
"ddd", ProfileGenerator generator(profiles);
ToAddress(0x1400), ProfilerEventsProcessor processor(&generator, profiles);
0x80); processor.Start();
EnqueueTickSampleEvent(&processor, ToAddress(0x1210)); CpuProfiler profiler(isolate, profiles, &generator, &processor);
EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220));
EnqueueTickSampleEvent(&processor, profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb");
ToAddress(0x1404), profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5);
ToAddress(0x1305), profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd");
ToAddress(0x1230));
EnqueueTickSampleEvent(&processor, frame1_code->instruction_start());
EnqueueTickSampleEvent(
&processor,
frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2,
frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2);
EnqueueTickSampleEvent(
&processor,
frame3_code->instruction_end() - 1,
frame2_code->instruction_end() - 1,
frame1_code->instruction_end() - 1);
processor.Stop(); processor.Stop();
processor.Join(); processor.Join();
CpuProfile* profile = CpuProfile* profile =
profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); profiles->StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
CHECK_NE(NULL, profile); CHECK_NE(NULL, profile);
// Check call trees. // Check call trees.
@ -229,29 +263,33 @@ TEST(CrashIfStoppingLastNonExistentProfile) {
// Long stacks (exceeding max frames limit) must not be erased. // Long stacks (exceeding max frames limit) must not be erased.
TEST(Issue1398) { TEST(Issue1398) {
TestSetup test_setup; TestSetup test_setup;
CpuProfilesCollection profiles; LocalContext env;
profiles.StartProfiling("", 1, false); i::Isolate* isolate = i::Isolate::Current();
ProfileGenerator generator(&profiles); i::HandleScope scope(isolate);
ProfilerEventsProcessor processor(&generator, &profiles);
processor.Start();
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, i::Code* code = CreateCode(&env);
"bbb",
ToAddress(0x1200), CpuProfilesCollection* profiles = new CpuProfilesCollection;
0x80); profiles->StartProfiling("", 1, false);
ProfileGenerator generator(profiles);
ProfilerEventsProcessor processor(&generator, profiles);
processor.Start();
CpuProfiler profiler(isolate, profiles, &generator, &processor);
profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
i::TickSample* sample = processor.TickSampleEvent(); i::TickSample* sample = processor.TickSampleEvent();
sample->pc = ToAddress(0x1200); sample->pc = code->address();
sample->tos = 0; sample->tos = 0;
sample->frames_count = i::TickSample::kMaxFramesCount; sample->frames_count = i::TickSample::kMaxFramesCount;
for (int i = 0; i < sample->frames_count; ++i) { for (int i = 0; i < sample->frames_count; ++i) {
sample->stack[i] = ToAddress(0x1200); sample->stack[i] = code->address();
} }
processor.Stop(); processor.Stop();
processor.Join(); processor.Join();
CpuProfile* profile = CpuProfile* profile =
profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); profiles->StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
CHECK_NE(NULL, profile); CHECK_NE(NULL, profile);
int actual_depth = 0; int actual_depth = 0;

View File

@ -87,17 +87,17 @@ TEST(TokenEnumerator) {
TEST(ProfileNodeFindOrAddChild) { TEST(ProfileNodeFindOrAddChild) {
ProfileTree tree; ProfileTree tree;
ProfileNode node(&tree, NULL); ProfileNode node(&tree, NULL);
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa"); CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
ProfileNode* childNode1 = node.FindOrAddChild(&entry1); ProfileNode* childNode1 = node.FindOrAddChild(&entry1);
CHECK_NE(NULL, childNode1); CHECK_NE(NULL, childNode1);
CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb"); CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
ProfileNode* childNode2 = node.FindOrAddChild(&entry2); ProfileNode* childNode2 = node.FindOrAddChild(&entry2);
CHECK_NE(NULL, childNode2); CHECK_NE(NULL, childNode2);
CHECK_NE(childNode1, childNode2); CHECK_NE(childNode1, childNode2);
CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); CHECK_EQ(childNode2, node.FindOrAddChild(&entry2));
CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc"); CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
ProfileNode* childNode3 = node.FindOrAddChild(&entry3); ProfileNode* childNode3 = node.FindOrAddChild(&entry3);
CHECK_NE(NULL, childNode3); CHECK_NE(NULL, childNode3);
CHECK_NE(childNode1, childNode3); CHECK_NE(childNode1, childNode3);
@ -109,19 +109,18 @@ TEST(ProfileNodeFindOrAddChild) {
TEST(ProfileNodeFindOrAddChildForSameFunction) { TEST(ProfileNodeFindOrAddChildForSameFunction) {
const char* empty = "";
const char* aaa = "aaa"; const char* aaa = "aaa";
ProfileTree tree; ProfileTree tree;
ProfileNode node(&tree, NULL); ProfileNode node(&tree, NULL);
CodeEntry entry1(i::Logger::FUNCTION_TAG, empty, aaa); CodeEntry entry1(i::Logger::FUNCTION_TAG, aaa);
ProfileNode* childNode1 = node.FindOrAddChild(&entry1); ProfileNode* childNode1 = node.FindOrAddChild(&entry1);
CHECK_NE(NULL, childNode1); CHECK_NE(NULL, childNode1);
CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
// The same function again. // The same function again.
CodeEntry entry2(i::Logger::FUNCTION_TAG, empty, aaa); CodeEntry entry2(i::Logger::FUNCTION_TAG, aaa);
CHECK_EQ(childNode1, node.FindOrAddChild(&entry2)); CHECK_EQ(childNode1, node.FindOrAddChild(&entry2));
// Now with a different security token. // Now with a different security token.
CodeEntry entry3(i::Logger::FUNCTION_TAG, empty, aaa, CodeEntry entry3(i::Logger::FUNCTION_TAG, aaa,
TokenEnumerator::kNoSecurityToken + 1); TokenEnumerator::kNoSecurityToken + 1);
CHECK_EQ(childNode1, node.FindOrAddChild(&entry3)); CHECK_EQ(childNode1, node.FindOrAddChild(&entry3));
} }
@ -157,9 +156,9 @@ class ProfileTreeTestHelper {
} // namespace } // namespace
TEST(ProfileTreeAddPathFromStart) { TEST(ProfileTreeAddPathFromStart) {
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa"); CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb"); CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc"); CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
ProfileTree tree; ProfileTree tree;
ProfileTreeTestHelper helper(&tree); ProfileTreeTestHelper helper(&tree);
CHECK_EQ(NULL, helper.Walk(&entry1)); CHECK_EQ(NULL, helper.Walk(&entry1));
@ -224,9 +223,9 @@ TEST(ProfileTreeAddPathFromStart) {
TEST(ProfileTreeAddPathFromEnd) { TEST(ProfileTreeAddPathFromEnd) {
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa"); CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb"); CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc"); CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
ProfileTree tree; ProfileTree tree;
ProfileTreeTestHelper helper(&tree); ProfileTreeTestHelper helper(&tree);
CHECK_EQ(NULL, helper.Walk(&entry1)); CHECK_EQ(NULL, helper.Walk(&entry1));
@ -304,7 +303,7 @@ TEST(ProfileTreeCalculateTotalTicks) {
CHECK_EQ(1, empty_tree.root()->total_ticks()); CHECK_EQ(1, empty_tree.root()->total_ticks());
CHECK_EQ(1, empty_tree.root()->self_ticks()); CHECK_EQ(1, empty_tree.root()->self_ticks());
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa"); CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry* e1_path[] = {&entry1}; CodeEntry* e1_path[] = {&entry1};
Vector<CodeEntry*> e1_path_vec( Vector<CodeEntry*> e1_path_vec(
e1_path, sizeof(e1_path) / sizeof(e1_path[0])); e1_path, sizeof(e1_path) / sizeof(e1_path[0]));
@ -325,7 +324,7 @@ TEST(ProfileTreeCalculateTotalTicks) {
CHECK_EQ(1, node1->total_ticks()); CHECK_EQ(1, node1->total_ticks());
CHECK_EQ(1, node1->self_ticks()); CHECK_EQ(1, node1->self_ticks());
CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb"); CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
CodeEntry* e1_e2_path[] = {&entry1, &entry2}; CodeEntry* e1_e2_path[] = {&entry1, &entry2};
Vector<CodeEntry*> e1_e2_path_vec( Vector<CodeEntry*> e1_e2_path_vec(
e1_e2_path, sizeof(e1_e2_path) / sizeof(e1_e2_path[0])); e1_e2_path, sizeof(e1_e2_path) / sizeof(e1_e2_path[0]));
@ -360,7 +359,7 @@ TEST(ProfileTreeCalculateTotalTicks) {
CodeEntry* e2_path[] = {&entry2}; CodeEntry* e2_path[] = {&entry2};
Vector<CodeEntry*> e2_path_vec( Vector<CodeEntry*> e2_path_vec(
e2_path, sizeof(e2_path) / sizeof(e2_path[0])); e2_path, sizeof(e2_path) / sizeof(e2_path[0]));
CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc"); CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
CodeEntry* e3_path[] = {&entry3}; CodeEntry* e3_path[] = {&entry3};
Vector<CodeEntry*> e3_path_vec( Vector<CodeEntry*> e3_path_vec(
e3_path, sizeof(e3_path) / sizeof(e3_path[0])); e3_path, sizeof(e3_path) / sizeof(e3_path[0]));
@ -418,10 +417,10 @@ TEST(ProfileTreeCalculateTotalTicks) {
TEST(ProfileTreeFilteredClone) { TEST(ProfileTreeFilteredClone) {
ProfileTree source_tree; ProfileTree source_tree;
const int token0 = 0, token1 = 1, token2 = 2; const int token0 = 0, token1 = 1, token2 = 2;
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", token0); CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa", token0);
CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", token1); CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb", token1);
CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", token0); CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc", token0);
CodeEntry entry4(i::Logger::FUNCTION_TAG, "", "ddd", CodeEntry entry4(i::Logger::FUNCTION_TAG, "ddd",
TokenEnumerator::kInheritsSecurityToken); TokenEnumerator::kInheritsSecurityToken);
{ {
@ -519,10 +518,10 @@ static inline i::Address ToAddress(int n) {
TEST(CodeMapAddCode) { TEST(CodeMapAddCode) {
CodeMap code_map; CodeMap code_map;
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa"); CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb"); CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc"); CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
CodeEntry entry4(i::Logger::FUNCTION_TAG, "", "ddd"); CodeEntry entry4(i::Logger::FUNCTION_TAG, "ddd");
code_map.AddCode(ToAddress(0x1500), &entry1, 0x200); code_map.AddCode(ToAddress(0x1500), &entry1, 0x200);
code_map.AddCode(ToAddress(0x1700), &entry2, 0x100); code_map.AddCode(ToAddress(0x1700), &entry2, 0x100);
code_map.AddCode(ToAddress(0x1900), &entry3, 0x50); code_map.AddCode(ToAddress(0x1900), &entry3, 0x50);
@ -549,8 +548,8 @@ TEST(CodeMapAddCode) {
TEST(CodeMapMoveAndDeleteCode) { TEST(CodeMapMoveAndDeleteCode) {
CodeMap code_map; CodeMap code_map;
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa"); CodeEntry entry1(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb"); CodeEntry entry2(i::Logger::FUNCTION_TAG, "bbb");
code_map.AddCode(ToAddress(0x1500), &entry1, 0x200); code_map.AddCode(ToAddress(0x1500), &entry1, 0x200);
code_map.AddCode(ToAddress(0x1700), &entry2, 0x100); code_map.AddCode(ToAddress(0x1700), &entry2, 0x100);
CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500))); CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500)));
@ -558,7 +557,7 @@ TEST(CodeMapMoveAndDeleteCode) {
code_map.MoveCode(ToAddress(0x1500), ToAddress(0x1700)); // Deprecate bbb. code_map.MoveCode(ToAddress(0x1500), ToAddress(0x1700)); // Deprecate bbb.
CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1500))); CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1500)));
CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1700))); CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1700)));
CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc"); CodeEntry entry3(i::Logger::FUNCTION_TAG, "ccc");
code_map.AddCode(ToAddress(0x1750), &entry3, 0x100); code_map.AddCode(ToAddress(0x1750), &entry3, 0x100);
CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700))); CHECK_EQ(NULL, code_map.FindEntry(ToAddress(0x1700)));
CHECK_EQ(&entry3, code_map.FindEntry(ToAddress(0x1750))); CHECK_EQ(&entry3, code_map.FindEntry(ToAddress(0x1750)));