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

Side by Side Diff: runtime/vm/profiler_test.cc

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | « runtime/vm/profiler_macos.cc ('k') | runtime/vm/profiler_win.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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/profiler.h" 10 #include "vm/profiler.h"
11 #include "vm/unit_test.h" 11 #include "vm/unit_test.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 class ProfileSampleBufferTestHelper { 15 class ProfileSampleBufferTestHelper {
16 public: 16 public:
17 static intptr_t IterateCount(const SampleBuffer& sample_buffer) { 17 static intptr_t IterateCount(const Isolate* isolate,
18 const SampleBuffer& sample_buffer) {
18 intptr_t c = 0; 19 intptr_t c = 0;
19 for (Sample* i = sample_buffer.FirstSample(); 20 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) {
20 i != sample_buffer.LastSample(); 21 Sample* sample = sample_buffer.GetSample(i);
21 i = sample_buffer.NextSample(i)) { 22 if (sample->isolate != isolate) {
23 continue;
24 }
22 c++; 25 c++;
23 } 26 }
24 return c; 27 return c;
25 } 28 }
26 29
27 30
28 static intptr_t IterateSumPC(const SampleBuffer& sample_buffer) { 31 static intptr_t IterateSumPC(const Isolate* isolate,
32 const SampleBuffer& sample_buffer) {
29 intptr_t c = 0; 33 intptr_t c = 0;
30 for (Sample* i = sample_buffer.FirstSample(); 34 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) {
31 i != sample_buffer.LastSample(); 35 Sample* sample = sample_buffer.GetSample(i);
32 i = sample_buffer.NextSample(i)) { 36 if (sample->isolate != isolate) {
33 c += i->pcs[0]; 37 continue;
38 }
39 c += sample->pcs[0];
34 } 40 }
35 return c; 41 return c;
36 } 42 }
37 }; 43 };
38 44
39 45
40 TEST_CASE(ProfilerSampleBufferWrapTest) { 46 TEST_CASE(ProfilerSampleBufferWrapTest) {
41 SampleBuffer* sample_buffer = new SampleBuffer(3); 47 SampleBuffer* sample_buffer = new SampleBuffer(3);
42 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer)); 48 Isolate* i = reinterpret_cast<Isolate*>(0x1);
49 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
43 Sample* s; 50 Sample* s;
44 s = sample_buffer->ReserveSample(); 51 s = sample_buffer->ReserveSample();
52 s->isolate = i;
45 s->pcs[0] = 2; 53 s->pcs[0] = 2;
46 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer)); 54 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
47 s = sample_buffer->ReserveSample(); 55 s = sample_buffer->ReserveSample();
56 s->isolate = i;
48 s->pcs[0] = 4; 57 s->pcs[0] = 4;
49 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer)); 58 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
50 s = sample_buffer->ReserveSample(); 59 s = sample_buffer->ReserveSample();
60 s->isolate = i;
51 s->pcs[0] = 6; 61 s->pcs[0] = 6;
52 EXPECT_EQ(10, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer)); 62 EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
53 s = sample_buffer->ReserveSample(); 63 s = sample_buffer->ReserveSample();
64 s->isolate = i;
54 s->pcs[0] = 8; 65 s->pcs[0] = 8;
55 EXPECT_EQ(14, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer)); 66 EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
56 delete sample_buffer; 67 delete sample_buffer;
57 } 68 }
58 69
59 70
60 TEST_CASE(ProfilerSampleBufferIterateTest) { 71 TEST_CASE(ProfilerSampleBufferIterateTest) {
61 SampleBuffer* sample_buffer = new SampleBuffer(3); 72 SampleBuffer* sample_buffer = new SampleBuffer(3);
62 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer)); 73 Isolate* i = reinterpret_cast<Isolate*>(0x1);
63 sample_buffer->ReserveSample(); 74 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
64 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer)); 75 Sample* s;
65 sample_buffer->ReserveSample(); 76 s = sample_buffer->ReserveSample();
66 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer)); 77 s->isolate = i;
67 sample_buffer->ReserveSample(); 78 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
68 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer)); 79 s = sample_buffer->ReserveSample();
69 sample_buffer->ReserveSample(); 80 s->isolate = i;
70 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer)); 81 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
82 s = sample_buffer->ReserveSample();
83 s->isolate = i;
84 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
85 s = sample_buffer->ReserveSample();
86 s->isolate = i;
87 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
71 delete sample_buffer; 88 delete sample_buffer;
72 } 89 }
73 90
74 } // namespace dart 91 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler_macos.cc ('k') | runtime/vm/profiler_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698