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

Side by Side Diff: test/cctest/test-cpu-profiler.cc

Issue 616963005: Extend CPU profiler with mapping ticks to source lines (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed x64.debug linker error Created 6 years, 2 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
« no previous file with comments | « src/profile-generator-inl.h ('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 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 CheckChildrenNames(root, names); 1057 CheckChildrenNames(root, names);
1058 1058
1059 const v8::CpuProfileNode* startNode = 1059 const v8::CpuProfileNode* startNode =
1060 GetChild(env->GetIsolate(), root, "start"); 1060 GetChild(env->GetIsolate(), root, "start");
1061 GetChild(env->GetIsolate(), startNode, "foo"); 1061 GetChild(env->GetIsolate(), startNode, "foo");
1062 1062
1063 profile->Delete(); 1063 profile->Delete();
1064 } 1064 }
1065 1065
1066 1066
1067 // This tests checks distribution of the samples through the source lines.
1068 TEST(TickLines) {
1069 CcTest::InitializeVM();
1070 LocalContext env;
1071 i::FLAG_turbo_source_positions = true;
1072 i::Isolate* isolate = CcTest::i_isolate();
1073 i::Factory* factory = isolate->factory();
1074 i::HandleScope scope(isolate);
1075
1076 i::EmbeddedVector<char, 512> script;
1077
1078 const char* func_name = "func";
1079 i::SNPrintF(script,
1080 "function %s() {\n"
1081 " var n = 0;\n"
1082 " var m = 100*100;\n"
1083 " while (m > 1) {\n"
1084 " m--;\n"
1085 " n += m * m * m;\n"
1086 " }\n"
1087 "}\n"
1088 "%s();\n",
1089 func_name, func_name);
1090
1091 CompileRun(script.start());
1092
1093 i::Handle<i::JSFunction> func = v8::Utils::OpenHandle(
1094 *v8::Local<v8::Function>::Cast((*env)->Global()->Get(v8_str(func_name))));
1095 CHECK_NE(NULL, func->shared());
1096 CHECK_NE(NULL, func->shared()->code());
1097 i::Code* code = NULL;
1098 if (func->code()->is_optimized_code()) {
1099 code = func->code();
1100 } else {
1101 CHECK(func->shared()->code() == func->code() || !i::FLAG_crankshaft);
1102 code = func->shared()->code();
1103 }
1104 CHECK_NE(NULL, code);
1105 i::Address code_address = code->instruction_start();
1106 CHECK_NE(NULL, code_address);
1107
1108 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
1109 profiles->StartProfiling("", false);
1110 ProfileGenerator generator(profiles);
1111 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
1112 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
1113 processor->Start();
1114 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
1115
1116 // Enqueue code creation events.
1117 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name);
1118 int line = 1;
1119 int column = 1;
1120 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, code, func->shared(), NULL,
1121 *str, line, column);
1122
1123 // Enqueue a tick event to enable code events processing.
1124 EnqueueTickSampleEvent(processor.get(), code_address);
1125
1126 processor->StopSynchronously();
1127
1128 CpuProfile* profile = profiles->StopProfiling("");
1129 CHECK_NE(NULL, profile);
1130
1131 // Check the state of profile generator.
1132 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address);
1133 CHECK_NE(NULL, func_entry);
1134 CHECK_EQ(func_name, func_entry->name());
1135 const i::JITLineInfoTable* line_info = func_entry->line_info();
1136 CHECK_NE(NULL, line_info);
1137 CHECK(!line_info->empty());
1138
1139 // Check the hit source lines using V8 Public APIs.
1140 const i::ProfileTree* tree = profile->top_down();
1141 ProfileNode* root = tree->root();
1142 CHECK_NE(NULL, root);
1143 ProfileNode* func_node = root->FindChild(func_entry);
1144 CHECK_NE(NULL, func_node);
1145
1146 // Add 10 faked ticks to source line #5.
1147 int hit_line = 5;
1148 int hit_count = 10;
1149 for (int i = 0; i < hit_count; i++) func_node->IncrementLineTicks(hit_line);
1150
1151 unsigned int line_count = func_node->GetHitLineCount();
1152 CHECK_EQ(2, line_count); // Expect two hit source lines - #1 and #5.
1153 ScopedVector<v8::CpuProfileNode::LineTick> entries(line_count);
1154 CHECK(func_node->GetLineTicks(&entries[0], line_count));
1155 int value = 0;
1156 for (int i = 0; i < entries.length(); i++)
1157 if (entries[i].line == hit_line) {
1158 value = entries[i].hit_count;
1159 break;
1160 }
1161 CHECK_EQ(hit_count, value);
1162 }
1163
1164
1067 static const char* call_function_test_source = "function bar(iterations) {\n" 1165 static const char* call_function_test_source = "function bar(iterations) {\n"
1068 "}\n" 1166 "}\n"
1069 "function start(duration) {\n" 1167 "function start(duration) {\n"
1070 " var start = Date.now();\n" 1168 " var start = Date.now();\n"
1071 " while (Date.now() - start < duration) {\n" 1169 " while (Date.now() - start < duration) {\n"
1072 " try {\n" 1170 " try {\n"
1073 " bar.call(this, 10 * 1000);\n" 1171 " bar.call(this, 10 * 1000);\n"
1074 " } catch(e) {}\n" 1172 " } catch(e) {}\n"
1075 " }\n" 1173 " }\n"
1076 "}"; 1174 "}";
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 inner_profile = NULL; 1772 inner_profile = NULL;
1675 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1773 CHECK_EQ(0, iprofiler->GetProfilesCount());
1676 1774
1677 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); 1775 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
1678 CHECK(outer_profile); 1776 CHECK(outer_profile);
1679 CHECK_EQ(1, iprofiler->GetProfilesCount()); 1777 CHECK_EQ(1, iprofiler->GetProfilesCount());
1680 outer_profile->Delete(); 1778 outer_profile->Delete();
1681 outer_profile = NULL; 1779 outer_profile = NULL;
1682 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1780 CHECK_EQ(0, iprofiler->GetProfilesCount());
1683 } 1781 }
OLDNEW
« no previous file with comments | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698