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

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

Issue 23490015: Reland^2 "Add Chromium-style TimeDelta, Time and TimeTicks classes, and a new ElapsedTimer class." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Some windows cleanup Created 7 years, 3 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 | « test/cctest/cctest.gyp ('k') | test/cctest/test-time.cc » ('j') | 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 26 matching lines...) Expand all
37 using i::CodeEntry; 37 using i::CodeEntry;
38 using i::CpuProfile; 38 using i::CpuProfile;
39 using i::CpuProfiler; 39 using i::CpuProfiler;
40 using i::CpuProfilesCollection; 40 using i::CpuProfilesCollection;
41 using i::Heap; 41 using i::Heap;
42 using i::ProfileGenerator; 42 using i::ProfileGenerator;
43 using i::ProfileNode; 43 using i::ProfileNode;
44 using i::ProfilerEventsProcessor; 44 using i::ProfilerEventsProcessor;
45 using i::ScopedVector; 45 using i::ScopedVector;
46 using i::SmartPointer; 46 using i::SmartPointer;
47 using i::TimeDelta;
47 using i::Vector; 48 using i::Vector;
48 49
49 50
50 TEST(StartStop) { 51 TEST(StartStop) {
51 CpuProfilesCollection profiles; 52 CpuProfilesCollection profiles;
52 ProfileGenerator generator(&profiles); 53 ProfileGenerator generator(&profiles);
53 SmartPointer<ProfilerEventsProcessor> processor( 54 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
54 new ProfilerEventsProcessor(&generator, NULL, 100)); 55 &generator, NULL, TimeDelta::FromMicroseconds(100)));
55 processor->Start(); 56 processor->Start();
56 processor->StopSynchronously(); 57 processor->StopSynchronously();
57 } 58 }
58 59
59 60
60 static inline i::Address ToAddress(int n) { 61 static inline i::Address ToAddress(int n) {
61 return reinterpret_cast<i::Address>(n); 62 return reinterpret_cast<i::Address>(n);
62 } 63 }
63 64
64 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, 65 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 i::Code* comment_code = CreateCode(&env); 136 i::Code* comment_code = CreateCode(&env);
136 i::Code* args5_code = CreateCode(&env); 137 i::Code* args5_code = CreateCode(&env);
137 i::Code* comment2_code = CreateCode(&env); 138 i::Code* comment2_code = CreateCode(&env);
138 i::Code* moved_code = CreateCode(&env); 139 i::Code* moved_code = CreateCode(&env);
139 i::Code* args3_code = CreateCode(&env); 140 i::Code* args3_code = CreateCode(&env);
140 i::Code* args4_code = CreateCode(&env); 141 i::Code* args4_code = CreateCode(&env);
141 142
142 CpuProfilesCollection* profiles = new CpuProfilesCollection; 143 CpuProfilesCollection* profiles = new CpuProfilesCollection;
143 profiles->StartProfiling("", 1, false); 144 profiles->StartProfiling("", 1, false);
144 ProfileGenerator generator(profiles); 145 ProfileGenerator generator(profiles);
145 SmartPointer<ProfilerEventsProcessor> processor( 146 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
146 new ProfilerEventsProcessor(&generator, NULL, 100)); 147 &generator, NULL, TimeDelta::FromMicroseconds(100)));
147 processor->Start(); 148 processor->Start();
148 CpuProfiler profiler(isolate, profiles, &generator, *processor); 149 CpuProfiler profiler(isolate, profiles, &generator, *processor);
149 150
150 // Enqueue code creation events. 151 // Enqueue code creation events.
151 const char* aaa_str = "aaa"; 152 const char* aaa_str = "aaa";
152 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( 153 i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
153 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); 154 i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
154 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); 155 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name);
155 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); 156 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment");
156 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); 157 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 i::Isolate* isolate = i::Isolate::Current(); 198 i::Isolate* isolate = i::Isolate::Current();
198 i::HandleScope scope(isolate); 199 i::HandleScope scope(isolate);
199 200
200 i::Code* frame1_code = CreateCode(&env); 201 i::Code* frame1_code = CreateCode(&env);
201 i::Code* frame2_code = CreateCode(&env); 202 i::Code* frame2_code = CreateCode(&env);
202 i::Code* frame3_code = CreateCode(&env); 203 i::Code* frame3_code = CreateCode(&env);
203 204
204 CpuProfilesCollection* profiles = new CpuProfilesCollection; 205 CpuProfilesCollection* profiles = new CpuProfilesCollection;
205 profiles->StartProfiling("", 1, false); 206 profiles->StartProfiling("", 1, false);
206 ProfileGenerator generator(profiles); 207 ProfileGenerator generator(profiles);
207 SmartPointer<ProfilerEventsProcessor> processor( 208 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
208 new ProfilerEventsProcessor(&generator, NULL, 100)); 209 &generator, NULL, TimeDelta::FromMicroseconds(100)));
209 processor->Start(); 210 processor->Start();
210 CpuProfiler profiler(isolate, profiles, &generator, *processor); 211 CpuProfiler profiler(isolate, profiles, &generator, *processor);
211 212
212 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); 213 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb");
213 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); 214 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5);
214 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); 215 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd");
215 216
216 EnqueueTickSampleEvent(*processor, frame1_code->instruction_start()); 217 EnqueueTickSampleEvent(*processor, frame1_code->instruction_start());
217 EnqueueTickSampleEvent( 218 EnqueueTickSampleEvent(
218 *processor, 219 *processor,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 TestSetup test_setup; 267 TestSetup test_setup;
267 LocalContext env; 268 LocalContext env;
268 i::Isolate* isolate = i::Isolate::Current(); 269 i::Isolate* isolate = i::Isolate::Current();
269 i::HandleScope scope(isolate); 270 i::HandleScope scope(isolate);
270 271
271 i::Code* code = CreateCode(&env); 272 i::Code* code = CreateCode(&env);
272 273
273 CpuProfilesCollection* profiles = new CpuProfilesCollection; 274 CpuProfilesCollection* profiles = new CpuProfilesCollection;
274 profiles->StartProfiling("", 1, false); 275 profiles->StartProfiling("", 1, false);
275 ProfileGenerator generator(profiles); 276 ProfileGenerator generator(profiles);
276 SmartPointer<ProfilerEventsProcessor> processor( 277 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
277 new ProfilerEventsProcessor(&generator, NULL, 100)); 278 &generator, NULL, TimeDelta::FromMicroseconds(100)));
278 processor->Start(); 279 processor->Start();
279 CpuProfiler profiler(isolate, profiles, &generator, *processor); 280 CpuProfiler profiler(isolate, profiles, &generator, *processor);
280 281
281 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); 282 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
282 283
283 i::TickSample* sample = processor->StartTickSample(); 284 i::TickSample* sample = processor->StartTickSample();
284 sample->pc = code->address(); 285 sample->pc = code->address();
285 sample->tos = 0; 286 sample->tos = 0;
286 sample->frames_count = i::TickSample::kMaxFramesCount; 287 sample->frames_count = i::TickSample::kMaxFramesCount;
287 for (int i = 0; i < sample->frames_count; ++i) { 288 for (int i = 0; i < sample->frames_count; ++i) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 isolate->Dispose(); 413 isolate->Dispose();
413 CHECK_EQ(NULL, isolate->GetCpuProfiler()); 414 CHECK_EQ(NULL, isolate->GetCpuProfiler());
414 } 415 }
415 416
416 417
417 TEST(ProfileStartEndTime) { 418 TEST(ProfileStartEndTime) {
418 LocalContext env; 419 LocalContext env;
419 v8::HandleScope scope(env->GetIsolate()); 420 v8::HandleScope scope(env->GetIsolate());
420 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 421 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
421 422
422 int64_t time_before_profiling = i::OS::Ticks();
423 v8::Local<v8::String> profile_name = v8::String::New("test"); 423 v8::Local<v8::String> profile_name = v8::String::New("test");
424 cpu_profiler->StartCpuProfiling(profile_name); 424 cpu_profiler->StartCpuProfiling(profile_name);
425 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); 425 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
426 CHECK(time_before_profiling <= profile->GetStartTime());
427 CHECK(profile->GetStartTime() <= profile->GetEndTime()); 426 CHECK(profile->GetStartTime() <= profile->GetEndTime());
428 CHECK(profile->GetEndTime() <= i::OS::Ticks());
429 } 427 }
430 428
431 429
432 static const v8::CpuProfile* RunProfiler( 430 static const v8::CpuProfile* RunProfiler(
433 LocalContext& env, v8::Handle<v8::Function> function, 431 LocalContext& env, v8::Handle<v8::Function> function,
434 v8::Handle<v8::Value> argv[], int argc, 432 v8::Handle<v8::Value> argv[], int argc,
435 unsigned min_js_samples) { 433 unsigned min_js_samples) {
436 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 434 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
437 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); 435 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
438 436
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 CHECK_EQ(0, programNode->GetChildrenCount()); 1372 CHECK_EQ(0, programNode->GetChildrenCount());
1375 CHECK_GE(programNode->GetHitCount(), 3); 1373 CHECK_GE(programNode->GetHitCount(), 3);
1376 1374
1377 const v8::CpuProfileNode* idleNode = 1375 const v8::CpuProfileNode* idleNode =
1378 GetChild(root, ProfileGenerator::kIdleEntryName); 1376 GetChild(root, ProfileGenerator::kIdleEntryName);
1379 CHECK_EQ(0, idleNode->GetChildrenCount()); 1377 CHECK_EQ(0, idleNode->GetChildrenCount());
1380 CHECK_GE(idleNode->GetHitCount(), 3); 1378 CHECK_GE(idleNode->GetHitCount(), 3);
1381 1379
1382 cpu_profiler->DeleteAllCpuProfiles(); 1380 cpu_profiler->DeleteAllCpuProfiles();
1383 } 1381 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/test-time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698