blob: 114a8e725f19e46e38f7f90f9eb83763a4e77e0e [file] [log] [blame]
whesse@chromium.orgcec079d2010-03-22 14:44:04 +00001// Copyright 2010 the V8 project authors. All rights reserved.
ulan@chromium.org750145a2013-03-07 15:14:13 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000027//
28// Tests of profiles generator and utilities.
29
30#include "v8.h"
31#include "cpu-profiler-inl.h"
32#include "cctest.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000033#include "../include/v8-profiler.h"
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000034
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000035using i::CodeEntry;
lrn@chromium.org25156de2010-04-06 13:10:27 +000036using i::CpuProfile;
vegorov@chromium.org26c16f82010-08-11 13:41:03 +000037using i::CpuProfiler;
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000038using i::CpuProfilesCollection;
39using i::ProfileGenerator;
40using i::ProfileNode;
41using i::ProfilerEventsProcessor;
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +000042using i::TokenEnumerator;
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000043
44
45TEST(StartStop) {
46 CpuProfilesCollection profiles;
47 ProfileGenerator generator(&profiles);
ulan@chromium.org750145a2013-03-07 15:14:13 +000048 ProfilerEventsProcessor processor(&generator);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000049 processor.Start();
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000050 processor.Stop();
51 processor.Join();
52}
53
54static v8::Persistent<v8::Context> env;
55
56static void InitializeVM() {
57 if (env.IsEmpty()) env = v8::Context::New();
58 v8::HandleScope scope;
59 env->Enter();
60}
61
62static inline i::Address ToAddress(int n) {
63 return reinterpret_cast<i::Address>(n);
64}
65
mmassi@chromium.org49a44672012-12-04 13:52:03 +000066static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
67 i::Address frame1,
68 i::Address frame2 = NULL,
69 i::Address frame3 = NULL) {
70 i::TickSample* sample = proc->TickSampleEvent();
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000071 sample->pc = frame1;
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +000072 sample->tos = frame1;
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000073 sample->frames_count = 0;
74 if (frame2 != NULL) {
75 sample->stack[0] = frame2;
76 sample->frames_count = 1;
77 }
78 if (frame3 != NULL) {
79 sample->stack[1] = frame3;
80 sample->frames_count = 2;
81 }
82}
83
ager@chromium.org357bf652010-04-12 11:30:10 +000084namespace {
85
86class TestSetup {
87 public:
88 TestSetup()
89 : old_flag_prof_browser_mode_(i::FLAG_prof_browser_mode) {
90 i::FLAG_prof_browser_mode = false;
91 }
92
93 ~TestSetup() {
94 i::FLAG_prof_browser_mode = old_flag_prof_browser_mode_;
95 }
96
97 private:
98 bool old_flag_prof_browser_mode_;
99};
100
101} // namespace
102
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000103TEST(CodeEvents) {
104 InitializeVM();
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000105 i::Isolate* isolate = i::Isolate::Current();
106 i::Heap* heap = isolate->heap();
107 i::Factory* factory = isolate->factory();
ager@chromium.org357bf652010-04-12 11:30:10 +0000108 TestSetup test_setup;
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000109 CpuProfilesCollection profiles;
lrn@chromium.org25156de2010-04-06 13:10:27 +0000110 profiles.StartProfiling("", 1);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000111 ProfileGenerator generator(&profiles);
ulan@chromium.org750145a2013-03-07 15:14:13 +0000112 ProfilerEventsProcessor processor(&generator);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000113 processor.Start();
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000114
115 // Enqueue code creation events.
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000116 i::HandleScope scope(isolate);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000117 const char* aaa_str = "aaa";
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000118 i::Handle<i::String> aaa_name = factory->NewStringFromAscii(
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000119 i::Vector<const char>(aaa_str, i::StrLength(aaa_str)));
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000120 processor.CodeCreateEvent(i::Logger::FUNCTION_TAG,
121 *aaa_name,
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000122 heap->empty_string(),
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000123 0,
124 ToAddress(0x1000),
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000125 0x100,
126 ToAddress(0x10000));
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000127 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
128 "bbb",
129 ToAddress(0x1200),
130 0x80);
131 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
132 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
133 "ddd",
134 ToAddress(0x1400),
135 0x80);
136 processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500));
137 processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10);
lrn@chromium.org34e60782011-09-15 07:25:40 +0000138 processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10);
mmassi@chromium.org49a44672012-12-04 13:52:03 +0000139 // Enqueue a tick event to enable code events processing.
140 EnqueueTickSampleEvent(&processor, ToAddress(0x1000));
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000141
142 processor.Stop();
143 processor.Join();
144
145 // Check the state of profile generator.
146 CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000));
147 CHECK_NE(NULL, entry1);
148 CHECK_EQ(aaa_str, entry1->name());
149 CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200));
150 CHECK_NE(NULL, entry2);
151 CHECK_EQ("bbb", entry2->name());
152 CodeEntry* entry3 = generator.code_map()->FindEntry(ToAddress(0x1300));
153 CHECK_NE(NULL, entry3);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000154 CHECK_EQ("5", entry3->name());
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000155 CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1400)));
156 CodeEntry* entry4 = generator.code_map()->FindEntry(ToAddress(0x1500));
157 CHECK_NE(NULL, entry4);
158 CHECK_EQ("ddd", entry4->name());
159 CHECK_EQ(NULL, generator.code_map()->FindEntry(ToAddress(0x1600)));
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000160}
161
162
163template<typename T>
164static int CompareProfileNodes(const T* p1, const T* p2) {
165 return strcmp((*p1)->entry()->name(), (*p2)->entry()->name());
166}
167
168TEST(TickEvents) {
ager@chromium.org357bf652010-04-12 11:30:10 +0000169 TestSetup test_setup;
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000170 CpuProfilesCollection profiles;
lrn@chromium.org25156de2010-04-06 13:10:27 +0000171 profiles.StartProfiling("", 1);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000172 ProfileGenerator generator(&profiles);
ulan@chromium.org750145a2013-03-07 15:14:13 +0000173 ProfilerEventsProcessor processor(&generator);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000174 processor.Start();
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000175
176 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
177 "bbb",
178 ToAddress(0x1200),
179 0x80);
180 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
181 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
182 "ddd",
183 ToAddress(0x1400),
184 0x80);
mmassi@chromium.org49a44672012-12-04 13:52:03 +0000185 EnqueueTickSampleEvent(&processor, ToAddress(0x1210));
186 EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220));
187 EnqueueTickSampleEvent(&processor,
188 ToAddress(0x1404),
189 ToAddress(0x1305),
190 ToAddress(0x1230));
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000191
192 processor.Stop();
193 processor.Join();
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000194 CpuProfile* profile =
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000195 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000196 CHECK_NE(NULL, profile);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000197
198 // Check call trees.
lrn@chromium.org25156de2010-04-06 13:10:27 +0000199 const i::List<ProfileNode*>* top_down_root_children =
200 profile->top_down()->root()->children();
201 CHECK_EQ(1, top_down_root_children->length());
202 CHECK_EQ("bbb", top_down_root_children->last()->entry()->name());
203 const i::List<ProfileNode*>* top_down_bbb_children =
204 top_down_root_children->last()->children();
205 CHECK_EQ(1, top_down_bbb_children->length());
206 CHECK_EQ("5", top_down_bbb_children->last()->entry()->name());
207 const i::List<ProfileNode*>* top_down_stub_children =
208 top_down_bbb_children->last()->children();
209 CHECK_EQ(1, top_down_stub_children->length());
210 CHECK_EQ("ddd", top_down_stub_children->last()->entry()->name());
211 const i::List<ProfileNode*>* top_down_ddd_children =
212 top_down_stub_children->last()->children();
213 CHECK_EQ(0, top_down_ddd_children->length());
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000214
lrn@chromium.org25156de2010-04-06 13:10:27 +0000215 const i::List<ProfileNode*>* bottom_up_root_children_unsorted =
216 profile->bottom_up()->root()->children();
217 CHECK_EQ(3, bottom_up_root_children_unsorted->length());
218 i::List<ProfileNode*> bottom_up_root_children(3);
219 bottom_up_root_children.AddAll(*bottom_up_root_children_unsorted);
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000220 bottom_up_root_children.Sort(&CompareProfileNodes);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000221 CHECK_EQ("5", bottom_up_root_children[0]->entry()->name());
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000222 CHECK_EQ("bbb", bottom_up_root_children[1]->entry()->name());
223 CHECK_EQ("ddd", bottom_up_root_children[2]->entry()->name());
lrn@chromium.org25156de2010-04-06 13:10:27 +0000224 const i::List<ProfileNode*>* bottom_up_stub_children =
225 bottom_up_root_children[0]->children();
226 CHECK_EQ(1, bottom_up_stub_children->length());
227 CHECK_EQ("bbb", bottom_up_stub_children->last()->entry()->name());
228 const i::List<ProfileNode*>* bottom_up_bbb_children =
229 bottom_up_root_children[1]->children();
230 CHECK_EQ(0, bottom_up_bbb_children->length());
231 const i::List<ProfileNode*>* bottom_up_ddd_children =
232 bottom_up_root_children[2]->children();
233 CHECK_EQ(1, bottom_up_ddd_children->length());
234 CHECK_EQ("5", bottom_up_ddd_children->last()->entry()->name());
235 const i::List<ProfileNode*>* bottom_up_ddd_stub_children =
236 bottom_up_ddd_children->last()->children();
237 CHECK_EQ(1, bottom_up_ddd_stub_children->length());
238 CHECK_EQ("bbb", bottom_up_ddd_stub_children->last()->entry()->name());
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000239}
lrn@chromium.org25156de2010-04-06 13:10:27 +0000240
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000241
242// http://crbug/51594
243// This test must not crash.
244TEST(CrashIfStoppingLastNonExistentProfile) {
245 InitializeVM();
246 TestSetup test_setup;
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000247 CpuProfiler::SetUp();
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000248 CpuProfiler::StartProfiling("1");
249 CpuProfiler::StopProfiling("2");
250 CpuProfiler::StartProfiling("1");
251 CpuProfiler::StopProfiling("");
252 CpuProfiler::TearDown();
253}
254
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000255
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000256// http://code.google.com/p/v8/issues/detail?id=1398
257// Long stacks (exceeding max frames limit) must not be erased.
258TEST(Issue1398) {
259 TestSetup test_setup;
260 CpuProfilesCollection profiles;
261 profiles.StartProfiling("", 1);
262 ProfileGenerator generator(&profiles);
ulan@chromium.org750145a2013-03-07 15:14:13 +0000263 ProfilerEventsProcessor processor(&generator);
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000264 processor.Start();
265
266 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
267 "bbb",
268 ToAddress(0x1200),
269 0x80);
270
mmassi@chromium.org49a44672012-12-04 13:52:03 +0000271 i::TickSample* sample = processor.TickSampleEvent();
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000272 sample->pc = ToAddress(0x1200);
273 sample->tos = 0;
274 sample->frames_count = i::TickSample::kMaxFramesCount;
275 for (int i = 0; i < sample->frames_count; ++i) {
276 sample->stack[i] = ToAddress(0x1200);
277 }
278
279 processor.Stop();
280 processor.Join();
281 CpuProfile* profile =
282 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
283 CHECK_NE(NULL, profile);
284
285 int actual_depth = 0;
286 const ProfileNode* node = profile->top_down()->root();
287 while (node->children()->length() > 0) {
288 node = node->children()->last();
289 ++actual_depth;
290 }
291
292 CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC.
293}
294
295
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000296TEST(DeleteAllCpuProfiles) {
297 InitializeVM();
298 TestSetup test_setup;
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000299 CpuProfiler::SetUp();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000300 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
301 CpuProfiler::DeleteAllProfiles();
302 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
303
304 CpuProfiler::StartProfiling("1");
305 CpuProfiler::StopProfiling("1");
306 CHECK_EQ(1, CpuProfiler::GetProfilesCount());
307 CpuProfiler::DeleteAllProfiles();
308 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
309 CpuProfiler::StartProfiling("1");
310 CpuProfiler::StartProfiling("2");
311 CpuProfiler::StopProfiling("2");
312 CpuProfiler::StopProfiling("1");
313 CHECK_EQ(2, CpuProfiler::GetProfilesCount());
314 CpuProfiler::DeleteAllProfiles();
315 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
316
317 // Test profiling cancellation by the 'delete' command.
318 CpuProfiler::StartProfiling("1");
319 CpuProfiler::StartProfiling("2");
320 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
321 CpuProfiler::DeleteAllProfiles();
322 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
323
324 CpuProfiler::TearDown();
325}
326
327
328TEST(DeleteCpuProfile) {
329 v8::HandleScope scope;
330 LocalContext env;
331
332 CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
333 v8::Local<v8::String> name1 = v8::String::New("1");
334 v8::CpuProfiler::StartProfiling(name1);
335 const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1);
336 CHECK_NE(NULL, p1);
337 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
338 unsigned uid1 = p1->GetUid();
339 CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1));
340 const_cast<v8::CpuProfile*>(p1)->Delete();
341 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
342 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
343
344 v8::Local<v8::String> name2 = v8::String::New("2");
345 v8::CpuProfiler::StartProfiling(name2);
346 const v8::CpuProfile* p2 = v8::CpuProfiler::StopProfiling(name2);
347 CHECK_NE(NULL, p2);
348 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
349 unsigned uid2 = p2->GetUid();
350 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
351 CHECK_EQ(p2, v8::CpuProfiler::FindProfile(uid2));
352 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
353 v8::Local<v8::String> name3 = v8::String::New("3");
354 v8::CpuProfiler::StartProfiling(name3);
355 const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3);
356 CHECK_NE(NULL, p3);
357 CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount());
358 unsigned uid3 = p3->GetUid();
359 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
360 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
361 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
362 const_cast<v8::CpuProfile*>(p2)->Delete();
363 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
364 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
365 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
366 const_cast<v8::CpuProfile*>(p3)->Delete();
367 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
368 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3));
369 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
370 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
371}
372
373
374TEST(DeleteCpuProfileDifferentTokens) {
375 v8::HandleScope scope;
376 LocalContext env;
377
378 CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
379 v8::Local<v8::String> name1 = v8::String::New("1");
380 v8::CpuProfiler::StartProfiling(name1);
381 const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1);
382 CHECK_NE(NULL, p1);
383 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
384 unsigned uid1 = p1->GetUid();
385 CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1));
386 v8::Local<v8::String> token1 = v8::String::New("token1");
387 const v8::CpuProfile* p1_t1 = v8::CpuProfiler::FindProfile(uid1, token1);
388 CHECK_NE(NULL, p1_t1);
389 CHECK_NE(p1, p1_t1);
390 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
391 const_cast<v8::CpuProfile*>(p1)->Delete();
392 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
393 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
394 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1, token1));
395 const_cast<v8::CpuProfile*>(p1_t1)->Delete();
396 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
397
398 v8::Local<v8::String> name2 = v8::String::New("2");
399 v8::CpuProfiler::StartProfiling(name2);
400 v8::Local<v8::String> token2 = v8::String::New("token2");
401 const v8::CpuProfile* p2_t2 = v8::CpuProfiler::StopProfiling(name2, token2);
402 CHECK_NE(NULL, p2_t2);
403 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
404 unsigned uid2 = p2_t2->GetUid();
405 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
406 const v8::CpuProfile* p2 = v8::CpuProfiler::FindProfile(uid2);
407 CHECK_NE(p2_t2, p2);
408 v8::Local<v8::String> name3 = v8::String::New("3");
409 v8::CpuProfiler::StartProfiling(name3);
410 const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3);
411 CHECK_NE(NULL, p3);
412 CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount());
413 unsigned uid3 = p3->GetUid();
414 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
415 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
416 const_cast<v8::CpuProfile*>(p2_t2)->Delete();
417 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
418 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
419 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
420 const_cast<v8::CpuProfile*>(p2)->Delete();
421 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
422 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
423 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
424 const_cast<v8::CpuProfile*>(p3)->Delete();
425 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
426 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3));
427}