DevTools: CPUProfiler: provide url for scripts that have sourceURL property.
BUG=none TEST=SourceURLSupportForNewFunctions, LogExistingFunctionSourceURLCheck R=jkummerow@chromium.org, yurys@chromium.org Review URL: https://codereview.chromium.org/16035027 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15074 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
1e4448b581
commit
29abaf4aad
@ -1141,7 +1141,16 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
|
||||
Handle<Code> code = info->code();
|
||||
if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile))
|
||||
return;
|
||||
Handle<String> script_name;
|
||||
if (script->name()->IsString()) {
|
||||
script_name = Handle<String>(String::cast(script->name()));
|
||||
} else {
|
||||
Handle<Object> name = GetScriptNameOrSourceURL(script);
|
||||
if (!name.is_null() && name->IsString()) {
|
||||
script_name = Handle<String>::cast(name);
|
||||
}
|
||||
}
|
||||
if (!script_name.is_null()) {
|
||||
int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
|
||||
USE(line_num);
|
||||
PROFILE(info->isolate(),
|
||||
@ -1149,7 +1158,7 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
|
||||
*code,
|
||||
*shared,
|
||||
info,
|
||||
String::cast(script->name()),
|
||||
String::cast(*script_name),
|
||||
line_num));
|
||||
} else {
|
||||
PROFILE(info->isolate(),
|
||||
|
@ -599,6 +599,9 @@ v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
|
||||
|
||||
Handle<Object> GetScriptNameOrSourceURL(Handle<Script> script) {
|
||||
Isolate* isolate = script->GetIsolate();
|
||||
if (!isolate->IsInitialized()) {
|
||||
return isolate->factory()->undefined_value();
|
||||
}
|
||||
Handle<String> name_or_source_url_key =
|
||||
isolate->factory()->InternalizeOneByteString(
|
||||
STATIC_ASCII_VECTOR("nameOrSourceURL"));
|
||||
|
12
src/log.cc
12
src/log.cc
@ -1728,10 +1728,18 @@ void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
|
||||
Handle<String> func_name(shared->DebugName());
|
||||
if (shared->script()->IsScript()) {
|
||||
Handle<Script> script(Script::cast(shared->script()));
|
||||
Handle<String> script_name;
|
||||
if (script->name()->IsString()) {
|
||||
Handle<String> script_name(String::cast(script->name()));
|
||||
script_name = Handle<String>(String::cast(script->name()));
|
||||
} else {
|
||||
Handle<Object> name = GetScriptNameOrSourceURL(script);
|
||||
if (!name.is_null() && name->IsString()) {
|
||||
script_name = Handle<String>::cast(name);
|
||||
}
|
||||
}
|
||||
if (!script_name.is_null()) {
|
||||
int line_num = GetScriptLineNumber(script, shared->start_position());
|
||||
if (line_num > 0) {
|
||||
if (line_num > -1) {
|
||||
PROFILE(isolate_,
|
||||
CodeCreateEvent(
|
||||
Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script),
|
||||
|
@ -917,3 +917,79 @@ TEST(NativeMethodMonomorphicIC) {
|
||||
|
||||
cpu_profiler->DeleteAllCpuProfiles();
|
||||
}
|
||||
|
||||
|
||||
static const char* cpu_profiler_sourceURL_source =
|
||||
"function start(timeout) {\n"
|
||||
" var start = Date.now();\n"
|
||||
" var duration = 0;\n"
|
||||
" do {\n"
|
||||
" try {\n"
|
||||
" duration = Date.now() - start;\n"
|
||||
" } catch(e) { }\n"
|
||||
" } while (duration < timeout);\n"
|
||||
" return duration;\n"
|
||||
"}\n"
|
||||
"//# sourceURL=cpu_profiler_sourceURL_source.js";
|
||||
|
||||
|
||||
TEST(SourceURLSupportForNewFunctions) {
|
||||
LocalContext env;
|
||||
v8::HandleScope scope(env->GetIsolate());
|
||||
|
||||
v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run();
|
||||
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
||||
env->Global()->Get(v8::String::New("start")));
|
||||
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
||||
int32_t profiling_interval_ms = 100;
|
||||
|
||||
// Cold run.
|
||||
v8::Local<v8::String> profile_name = v8::String::New("my_profile");
|
||||
cpu_profiler->StartCpuProfiling(profile_name);
|
||||
v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) };
|
||||
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
||||
const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
|
||||
CHECK_NE(NULL, profile);
|
||||
|
||||
// Dump collected profile to have a better diagnostic in case of failure.
|
||||
reinterpret_cast<i::CpuProfile*>(
|
||||
const_cast<v8::CpuProfile*>(profile))->Print();
|
||||
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
||||
const v8::CpuProfileNode* startNode = GetChild(root, "start");
|
||||
|
||||
CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"),
|
||||
startNode->GetScriptResourceName());
|
||||
|
||||
cpu_profiler->DeleteAllCpuProfiles();
|
||||
}
|
||||
|
||||
TEST(LogExistingFunctionSourceURLCheck) {
|
||||
LocalContext env;
|
||||
v8::HandleScope scope(env->GetIsolate());
|
||||
|
||||
v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run();
|
||||
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
||||
env->Global()->Get(v8::String::New("start")));
|
||||
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
|
||||
int32_t profiling_interval_ms = 100;
|
||||
|
||||
// Warm up.
|
||||
v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) };
|
||||
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
||||
|
||||
v8::Local<v8::String> profile_name = v8::String::New("my_profile");
|
||||
cpu_profiler->StartCpuProfiling(profile_name);
|
||||
function->Call(env->Global(), ARRAY_SIZE(args), args);
|
||||
const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
|
||||
CHECK_NE(NULL, profile);
|
||||
|
||||
// Dump collected profile to have a better diagnostic in case of failure.
|
||||
reinterpret_cast<i::CpuProfile*>(
|
||||
const_cast<v8::CpuProfile*>(profile))->Print();
|
||||
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
|
||||
const v8::CpuProfileNode* startNode = GetChild(root, "start");
|
||||
CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"),
|
||||
startNode->GetScriptResourceName());
|
||||
|
||||
cpu_profiler->DeleteAllCpuProfiles();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user