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

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

Issue 2105943002: Expose TickSample and its APIs in v8-profiler.h (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase & address comments. Created 4 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
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 new ProfilerEventsProcessor(&generator, nullptr, 74 new ProfilerEventsProcessor(&generator, nullptr,
75 v8::base::TimeDelta::FromMicroseconds(100))); 75 v8::base::TimeDelta::FromMicroseconds(100)));
76 processor->Start(); 76 processor->Start();
77 processor->StopSynchronously(); 77 processor->StopSynchronously();
78 } 78 }
79 79
80 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, 80 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
81 i::Address frame1, 81 i::Address frame1,
82 i::Address frame2 = NULL, 82 i::Address frame2 = NULL,
83 i::Address frame3 = NULL) { 83 i::Address frame3 = NULL) {
84 i::TickSample* sample = proc->StartTickSample(); 84 v8::TickSample* sample = proc->StartTickSample();
85 sample->pc = frame1; 85 sample->pc = frame1;
86 sample->tos = frame1; 86 sample->tos = frame1;
87 sample->frames_count = 0; 87 sample->frames_count = 0;
88 if (frame2 != NULL) { 88 if (frame2 != NULL) {
89 sample->stack[0] = frame2; 89 sample->stack[0] = frame2;
90 sample->frames_count = 1; 90 sample->frames_count = 1;
91 } 91 }
92 if (frame3 != NULL) { 92 if (frame3 != NULL) {
93 sample->stack[1] = frame3; 93 sample->stack[1] = frame3;
94 sample->frames_count = 2; 94 sample->frames_count = 2;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 generator, nullptr, v8::base::TimeDelta::FromMicroseconds(100)); 299 generator, nullptr, v8::base::TimeDelta::FromMicroseconds(100));
300 CpuProfiler profiler(isolate, profiles, generator, processor); 300 CpuProfiler profiler(isolate, profiles, generator, processor);
301 profiles->StartProfiling("", false); 301 profiles->StartProfiling("", false);
302 processor->Start(); 302 processor->Start();
303 ProfilerListener profiler_listener(isolate); 303 ProfilerListener profiler_listener(isolate);
304 isolate->code_event_dispatcher()->AddListener(&profiler_listener); 304 isolate->code_event_dispatcher()->AddListener(&profiler_listener);
305 profiler_listener.AddObserver(&profiler); 305 profiler_listener.AddObserver(&profiler);
306 306
307 profiler_listener.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); 307 profiler_listener.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb");
308 308
309 i::TickSample* sample = processor->StartTickSample(); 309 v8::TickSample* sample = processor->StartTickSample();
310 sample->pc = code->address(); 310 sample->pc = code->address();
311 sample->tos = 0; 311 sample->tos = 0;
312 sample->frames_count = i::TickSample::kMaxFramesCount; 312 sample->frames_count = v8::TickSample::kMaxFramesCount;
313 for (unsigned i = 0; i < sample->frames_count; ++i) { 313 for (unsigned i = 0; i < sample->frames_count; ++i) {
314 sample->stack[i] = code->address(); 314 sample->stack[i] = code->address();
315 } 315 }
316 processor->FinishTickSample(); 316 processor->FinishTickSample();
317 317
318 profiler_listener.RemoveObserver(&profiler); 318 profiler_listener.RemoveObserver(&profiler);
319 isolate->code_event_dispatcher()->RemoveListener(&profiler_listener); 319 isolate->code_event_dispatcher()->RemoveListener(&profiler_listener);
320 processor->StopSynchronously(); 320 processor->StopSynchronously();
321 CpuProfile* profile = profiles->StopProfiling(""); 321 CpuProfile* profile = profiles->StopProfiling("");
322 CHECK(profile); 322 CHECK(profile);
323 323
324 unsigned actual_depth = 0; 324 unsigned actual_depth = 0;
325 const ProfileNode* node = profile->top_down()->root(); 325 const ProfileNode* node = profile->top_down()->root();
326 while (node->children()->length() > 0) { 326 while (node->children()->length() > 0) {
327 node = node->children()->last(); 327 node = node->children()->last();
328 ++actual_depth; 328 ++actual_depth;
329 } 329 }
330 330
331 CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. 331 CHECK_EQ(1 + v8::TickSample::kMaxFramesCount, actual_depth); // +1 for PC.
332 } 332 }
333 333
334 TEST(DeleteAllCpuProfiles) { 334 TEST(DeleteAllCpuProfiles) {
335 CcTest::InitializeVM(); 335 CcTest::InitializeVM();
336 TestSetup test_setup; 336 TestSetup test_setup;
337 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); 337 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
338 CHECK_EQ(0, profiler->GetProfilesCount()); 338 CHECK_EQ(0, profiler->GetProfilesCount());
339 profiler->DeleteAllProfiles(); 339 profiler->DeleteAllProfiles();
340 CHECK_EQ(0, profiler->GetProfilesCount()); 340 CHECK_EQ(0, profiler->GetProfilesCount());
341 341
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 iprofile->Print(); 2043 iprofile->Print();
2044 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 2044 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
2045 2045
2046 const char* branch[] = {"", "test"}; 2046 const char* branch[] = {"", "test"};
2047 const ProfileNode* itest_node = 2047 const ProfileNode* itest_node =
2048 GetSimpleBranch(env, profile, branch, arraysize(branch)); 2048 GetSimpleBranch(env, profile, branch, arraysize(branch));
2049 CHECK_EQ(0U, itest_node->deopt_infos().size()); 2049 CHECK_EQ(0U, itest_node->deopt_infos().size());
2050 2050
2051 iprofiler->DeleteProfile(iprofile); 2051 iprofiler->DeleteProfile(iprofile);
2052 } 2052 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698