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

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

Issue 2053523003: Refactor CpuProfiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move CpuProfilerManager to .cc Created 4 years, 6 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
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 16 matching lines...) Expand all
27 // 27 //
28 // Tests of profiles generator and utilities. 28 // Tests of profiles generator and utilities.
29 29
30 #include "src/v8.h" 30 #include "src/v8.h"
31 31
32 #include "include/v8-profiler.h" 32 #include "include/v8-profiler.h"
33 #include "src/base/platform/platform.h" 33 #include "src/base/platform/platform.h"
34 #include "src/base/smart-pointers.h" 34 #include "src/base/smart-pointers.h"
35 #include "src/deoptimizer.h" 35 #include "src/deoptimizer.h"
36 #include "src/profiler/cpu-profiler-inl.h" 36 #include "src/profiler/cpu-profiler-inl.h"
37 #include "src/profiler/profiler-listener.h"
37 #include "src/utils.h" 38 #include "src/utils.h"
38 #include "test/cctest/cctest.h" 39 #include "test/cctest/cctest.h"
39 #include "test/cctest/profiler-extension.h" 40 #include "test/cctest/profiler-extension.h"
40 using i::CodeEntry; 41 using i::CodeEntry;
41 using i::CpuProfile; 42 using i::CpuProfile;
42 using i::CpuProfiler; 43 using i::CpuProfiler;
43 using i::CpuProfilesCollection; 44 using i::CpuProfilesCollection;
44 using i::Heap; 45 using i::Heap;
45 using i::ProfileGenerator; 46 using i::ProfileGenerator;
46 using i::ProfileNode; 47 using i::ProfileNode;
47 using i::ProfilerEventsProcessor; 48 using i::ProfilerEventsProcessor;
49 using i::ProfilerListener;
48 using i::ScopedVector; 50 using i::ScopedVector;
49 using i::Vector; 51 using i::Vector;
50 using v8::base::SmartPointer; 52 using v8::base::SmartPointer;
51 53
52 54
53 // Helper methods 55 // Helper methods
54 static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env, 56 static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env,
55 const char* name) { 57 const char* name) {
56 return v8::Local<v8::Function>::Cast( 58 return v8::Local<v8::Function>::Cast(
57 env->Global()->Get(env, v8_str(name)).ToLocalChecked()); 59 env->Global()->Get(env, v8_str(name)).ToLocalChecked());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 i::AbstractCode* args3_code = CreateCode(&env); 159 i::AbstractCode* args3_code = CreateCode(&env);
158 i::AbstractCode* args4_code = CreateCode(&env); 160 i::AbstractCode* args4_code = CreateCode(&env);
159 161
160 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); 162 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
161 profiles->StartProfiling("", false); 163 profiles->StartProfiling("", false);
162 ProfileGenerator generator(profiles); 164 ProfileGenerator generator(profiles);
163 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 165 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
164 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); 166 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
165 processor->Start(); 167 processor->Start();
166 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); 168 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
169 ProfilerListener* profiler_listener =
170 profiler.isolate()->logger()->profiler_listener();
171 profiler_listener->ResolveCodeEvent();
167 172
168 // Enqueue code creation events. 173 // Enqueue code creation events.
169 const char* aaa_str = "aaa"; 174 const char* aaa_str = "aaa";
170 i::Handle<i::String> aaa_name = factory->NewStringFromAsciiChecked(aaa_str); 175 i::Handle<i::String> aaa_name = factory->NewStringFromAsciiChecked(aaa_str);
171 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); 176 profiler_listener->CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code,
172 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); 177 *aaa_name);
173 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); 178 profiler_listener->CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code,
174 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2"); 179 "comment");
175 profiler.CodeMoveEvent(comment2_code, moved_code->address()); 180 profiler_listener->CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5);
176 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3); 181 profiler_listener->CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code,
177 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4); 182 "comment2");
183 profiler_listener->CodeMoveEvent(comment2_code, moved_code->address());
184 profiler_listener->CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3);
185 profiler_listener->CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4);
178 186
179 // Enqueue a tick event to enable code events processing. 187 // Enqueue a tick event to enable code events processing.
180 EnqueueTickSampleEvent(processor.get(), aaa_code->address()); 188 EnqueueTickSampleEvent(processor.get(), aaa_code->address());
181 189
182 processor->StopSynchronously(); 190 processor->StopSynchronously();
183 191
184 // Check the state of profile generator. 192 // Check the state of profile generator.
185 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address()); 193 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address());
186 CHECK(aaa); 194 CHECK(aaa);
187 CHECK_EQ(0, strcmp(aaa_str, aaa->name())); 195 CHECK_EQ(0, strcmp(aaa_str, aaa->name()));
(...skipping 28 matching lines...) Expand all
216 i::AbstractCode* frame2_code = CreateCode(&env); 224 i::AbstractCode* frame2_code = CreateCode(&env);
217 i::AbstractCode* frame3_code = CreateCode(&env); 225 i::AbstractCode* frame3_code = CreateCode(&env);
218 226
219 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); 227 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
220 profiles->StartProfiling("", false); 228 profiles->StartProfiling("", false);
221 ProfileGenerator generator(profiles); 229 ProfileGenerator generator(profiles);
222 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 230 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
223 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); 231 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
224 processor->Start(); 232 processor->Start();
225 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); 233 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
234 ProfilerListener* profiler_listener =
235 profiler.isolate()->logger()->profiler_listener();
226 236
227 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); 237 profiler_listener->ResolveCodeEvent();
228 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); 238 profiler_listener->CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code,
229 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); 239 "bbb");
240 profiler_listener->CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5);
241 profiler_listener->CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code,
242 "ddd");
230 243
231 EnqueueTickSampleEvent(processor.get(), frame1_code->instruction_start()); 244 EnqueueTickSampleEvent(processor.get(), frame1_code->instruction_start());
232 EnqueueTickSampleEvent( 245 EnqueueTickSampleEvent(
233 processor.get(), 246 processor.get(),
234 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, 247 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2,
235 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); 248 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2);
236 EnqueueTickSampleEvent( 249 EnqueueTickSampleEvent(
237 processor.get(), 250 processor.get(),
238 frame3_code->instruction_end() - 1, 251 frame3_code->instruction_end() - 1,
239 frame2_code->instruction_end() - 1, 252 frame2_code->instruction_end() - 1,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 296
284 i::AbstractCode* code = CreateCode(&env); 297 i::AbstractCode* code = CreateCode(&env);
285 298
286 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); 299 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
287 profiles->StartProfiling("", false); 300 profiles->StartProfiling("", false);
288 ProfileGenerator generator(profiles); 301 ProfileGenerator generator(profiles);
289 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 302 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
290 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); 303 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
291 processor->Start(); 304 processor->Start();
292 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); 305 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
306 ProfilerListener* profiler_listener =
307 profiler.isolate()->logger()->profiler_listener();
293 308
294 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); 309 profiler_listener->ResolveCodeEvent();
310 profiler_listener->CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
295 311
296 i::TickSample* sample = processor->StartTickSample(); 312 i::TickSample* sample = processor->StartTickSample();
297 sample->pc = code->address(); 313 sample->pc = code->address();
298 sample->tos = 0; 314 sample->tos = 0;
299 sample->frames_count = i::TickSample::kMaxFramesCount; 315 sample->frames_count = i::TickSample::kMaxFramesCount;
300 for (unsigned i = 0; i < sample->frames_count; ++i) { 316 for (unsigned i = 0; i < sample->frames_count; ++i) {
301 sample->stack[i] = code->address(); 317 sample->stack[i] = code->address();
302 } 318 }
303 processor->FinishTickSample(); 319 processor->FinishTickSample();
304 320
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 i::Address code_address = code->instruction_start(); 1037 i::Address code_address = code->instruction_start();
1022 CHECK(code_address); 1038 CHECK(code_address);
1023 1039
1024 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); 1040 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
1025 profiles->StartProfiling("", false); 1041 profiles->StartProfiling("", false);
1026 ProfileGenerator generator(profiles); 1042 ProfileGenerator generator(profiles);
1027 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( 1043 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
1028 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); 1044 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
1029 processor->Start(); 1045 processor->Start();
1030 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); 1046 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
1047 ProfilerListener* profiler_listener =
1048 profiler.isolate()->logger()->profiler_listener();
1031 1049
1032 // Enqueue code creation events. 1050 // Enqueue code creation events.
1033 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name); 1051 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name);
1034 int line = 1; 1052 int line = 1;
1035 int column = 1; 1053 int column = 1;
1036 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, code, func->shared(), *str, 1054 profiler_listener->ResolveCodeEvent();
1037 line, column); 1055 profiler_listener->CodeCreateEvent(i::Logger::FUNCTION_TAG, code,
1056 func->shared(), *str, line, column);
1038 1057
1039 // Enqueue a tick event to enable code events processing. 1058 // Enqueue a tick event to enable code events processing.
1040 EnqueueTickSampleEvent(processor.get(), code_address); 1059 EnqueueTickSampleEvent(processor.get(), code_address);
1041 1060
1042 processor->StopSynchronously(); 1061 processor->StopSynchronously();
1043 1062
1044 CpuProfile* profile = profiles->StopProfiling(""); 1063 CpuProfile* profile = profiles->StopProfiling("");
1045 CHECK(profile); 1064 CHECK(profile);
1046 1065
1047 // Check the state of profile generator. 1066 // Check the state of profile generator.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 int32_t duration_ms = 100; 1143 int32_t duration_ms = 100;
1125 v8::Local<v8::Value> args[] = { 1144 v8::Local<v8::Value> args[] = {
1126 v8::Integer::New(env->GetIsolate(), duration_ms)}; 1145 v8::Integer::New(env->GetIsolate(), duration_ms)};
1127 v8::CpuProfile* profile = 1146 v8::CpuProfile* profile =
1128 RunProfiler(env.local(), function, args, arraysize(args), 1000); 1147 RunProfiler(env.local(), function, args, arraysize(args), 1000);
1129 1148
1130 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1149 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1131 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 1150 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
1132 GetChild(env.local(), start_node, "bar"); 1151 GetChild(env.local(), start_node, "bar");
1133 1152
1134 const v8::CpuProfileNode* unresolved_node = FindChild( 1153 const v8::CpuProfileNode* unresolved_node =
1135 env.local(), root, i::ProfileGenerator::kUnresolvedFunctionName); 1154 FindChild(env.local(), root, i::CodeEntry::kUnresolvedFunctionName);
1136 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "call")); 1155 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "call"));
1137 1156
1138 profile->Delete(); 1157 profile->Delete();
1139 } 1158 }
1140 1159
1141 static const char* function_apply_test_source = 1160 static const char* function_apply_test_source =
1142 "%NeverOptimizeFunction(bar);\n" 1161 "%NeverOptimizeFunction(bar);\n"
1143 "%NeverOptimizeFunction(test);\n" 1162 "%NeverOptimizeFunction(test);\n"
1144 "%NeverOptimizeFunction(start);\n" 1163 "%NeverOptimizeFunction(start);\n"
1145 "function bar(n) {\n" 1164 "function bar(n) {\n"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1199
1181 v8::CpuProfile* profile = 1200 v8::CpuProfile* profile =
1182 RunProfiler(env.local(), function, args, arraysize(args), 1000); 1201 RunProfiler(env.local(), function, args, arraysize(args), 1000);
1183 1202
1184 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1203 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1185 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 1204 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
1186 const v8::CpuProfileNode* test_node = 1205 const v8::CpuProfileNode* test_node =
1187 GetChild(env.local(), start_node, "test"); 1206 GetChild(env.local(), start_node, "test");
1188 GetChild(env.local(), test_node, "bar"); 1207 GetChild(env.local(), test_node, "bar");
1189 1208
1190 const v8::CpuProfileNode* unresolved_node = FindChild( 1209 const v8::CpuProfileNode* unresolved_node =
1191 env.local(), start_node, ProfileGenerator::kUnresolvedFunctionName); 1210 FindChild(env.local(), start_node, CodeEntry::kUnresolvedFunctionName);
1192 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "apply")); 1211 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "apply"));
1193 1212
1194 profile->Delete(); 1213 profile->Delete();
1195 } 1214 }
1196 1215
1197 static const char* cpu_profiler_deep_stack_test_source = 1216 static const char* cpu_profiler_deep_stack_test_source =
1198 "function foo(n) {\n" 1217 "function foo(n) {\n"
1199 " if (n)\n" 1218 " if (n)\n"
1200 " foo(n - 1);\n" 1219 " foo(n - 1);\n"
1201 " else\n" 1220 " else\n"
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 cpu_profiler->SetIdle(false); 1607 cpu_profiler->SetIdle(false);
1589 processor->AddCurrentStack(isolate, true); 1608 processor->AddCurrentStack(isolate, true);
1590 1609
1591 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 1610 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
1592 CHECK(profile); 1611 CHECK(profile);
1593 // Dump collected profile to have a better diagnostic in case of failure. 1612 // Dump collected profile to have a better diagnostic in case of failure.
1594 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 1613 reinterpret_cast<i::CpuProfile*>(profile)->Print();
1595 1614
1596 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1615 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1597 const v8::CpuProfileNode* program_node = 1616 const v8::CpuProfileNode* program_node =
1598 GetChild(env.local(), root, ProfileGenerator::kProgramEntryName); 1617 GetChild(env.local(), root, CodeEntry::kProgramEntryName);
1599 CHECK_EQ(0, program_node->GetChildrenCount()); 1618 CHECK_EQ(0, program_node->GetChildrenCount());
1600 CHECK_GE(program_node->GetHitCount(), 2u); 1619 CHECK_GE(program_node->GetHitCount(), 2u);
1601 1620
1602 const v8::CpuProfileNode* idle_node = 1621 const v8::CpuProfileNode* idle_node =
1603 GetChild(env.local(), root, ProfileGenerator::kIdleEntryName); 1622 GetChild(env.local(), root, CodeEntry::kIdleEntryName);
1604 CHECK_EQ(0, idle_node->GetChildrenCount()); 1623 CHECK_EQ(0, idle_node->GetChildrenCount());
1605 CHECK_GE(idle_node->GetHitCount(), 3u); 1624 CHECK_GE(idle_node->GetHitCount(), 3u);
1606 1625
1607 profile->Delete(); 1626 profile->Delete();
1608 } 1627 }
1609 1628
1610 static void CheckFunctionDetails(v8::Isolate* isolate, 1629 static void CheckFunctionDetails(v8::Isolate* isolate,
1611 const v8::CpuProfileNode* node, 1630 const v8::CpuProfileNode* node,
1612 const char* name, const char* script_name, 1631 const char* name, const char* script_name,
1613 int script_id, int line, int column) { 1632 int script_id, int line, int column) {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 iprofile->Print(); 2042 iprofile->Print();
2024 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 2043 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
2025 2044
2026 const char* branch[] = {"", "test"}; 2045 const char* branch[] = {"", "test"};
2027 const ProfileNode* itest_node = 2046 const ProfileNode* itest_node =
2028 GetSimpleBranch(env, profile, branch, arraysize(branch)); 2047 GetSimpleBranch(env, profile, branch, arraysize(branch));
2029 CHECK_EQ(0U, itest_node->deopt_infos().size()); 2048 CHECK_EQ(0U, itest_node->deopt_infos().size());
2030 2049
2031 iprofiler->DeleteProfile(iprofile); 2050 iprofiler->DeleteProfile(iprofile);
2032 } 2051 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698