Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: test/cctest/test-profile-generator.cc

Issue 18058008: CPUProfiler: Improve line numbers support in profiler. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/log.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 current = PickChild(current, "b"); 958 current = PickChild(current, "b");
959 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 959 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
960 CHECK_EQ(script_b->GetId(), current->GetScriptId()); 960 CHECK_EQ(script_b->GetId(), current->GetScriptId());
961 961
962 current = PickChild(current, "a"); 962 current = PickChild(current, "a");
963 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 963 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
964 CHECK_EQ(script_a->GetId(), current->GetScriptId()); 964 CHECK_EQ(script_a->GetId(), current->GetScriptId());
965 } 965 }
966 966
967 967
968
969
970 static const char* line_number_test_source_existing_functions =
971 "function foo_at_the_first_line() {\n"
972 "}\n"
973 "foo_at_the_first_line();\n"
974 "function lazy_func_at_forth_line() {}\n";
975
976
977 static const char* line_number_test_source_profile_time_functions =
978 "// Empty first line\n"
979 "function bar_at_the_second_line() {\n"
980 " foo_at_the_first_line();\n"
981 "}\n"
982 "bar_at_the_second_line();\n"
983 "function lazy_func_at_6th_line() {}";
984
985 int GetFunctionLineNumber(LocalContext* env, const char* name) {
986 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
987 CodeMap* code_map = profiler->generator()->code_map();
988 i::Handle<i::JSFunction> func = v8::Utils::OpenHandle(
989 *v8::Local<v8::Function>::Cast(
990 (*(*env))->Global()->Get(v8_str(name))));
991 CodeEntry* func_entry = code_map->FindEntry(func->code()->address());
992 if (!func_entry)
993 FATAL(name);
994 return func_entry->line_number();
995 }
996
997
998 TEST(LineNumber) {
999 i::FLAG_use_inlining = false;
1000
1001 CcTest::InitializeVM();
1002 LocalContext env;
1003 i::Isolate* isolate = i::Isolate::Current();
1004 TestSetup test_setup;
1005
1006 i::HandleScope scope(isolate);
1007
1008 CompileRun(line_number_test_source_existing_functions);
1009
1010 CpuProfiler* profiler = isolate->cpu_profiler();
1011 profiler->StartProfiling("LineNumber");
1012
1013 CompileRun(line_number_test_source_profile_time_functions);
1014
1015 profiler->processor()->Stop();
1016
1017 CHECK_EQ(1, GetFunctionLineNumber(&env, "foo_at_the_first_line"));
1018 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_forth_line"));
1019 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line"));
1020 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_6th_line"));
1021
1022 profiler->StopProfiling("LineNumber");
1023 }
OLDNEW
« src/log.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698