OLD | NEW |
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 Isolate* isolate, | 17 static intptr_t IterateCount(const Isolate* isolate, |
18 const SampleBuffer& sample_buffer) { | 18 const SampleBuffer& sample_buffer) { |
19 intptr_t c = 0; | 19 intptr_t c = 0; |
20 Sample* sample = Sample::Allocate(); | |
21 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { | 20 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { |
22 sample_buffer.CopySample(i, sample); | 21 Sample* sample = sample_buffer.At(i); |
23 if (sample->isolate() != isolate) { | 22 if (sample->isolate() != isolate) { |
24 continue; | 23 continue; |
25 } | 24 } |
26 c++; | 25 c++; |
27 } | 26 } |
28 free(sample); | |
29 return c; | 27 return c; |
30 } | 28 } |
31 | 29 |
32 | 30 |
33 static intptr_t IterateSumPC(const Isolate* isolate, | 31 static intptr_t IterateSumPC(const Isolate* isolate, |
34 const SampleBuffer& sample_buffer) { | 32 const SampleBuffer& sample_buffer) { |
35 intptr_t c = 0; | 33 intptr_t c = 0; |
36 Sample* sample = Sample::Allocate(); | |
37 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { | 34 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { |
38 sample_buffer.CopySample(i, sample); | 35 Sample* sample = sample_buffer.At(i); |
39 if (sample->isolate() != isolate) { | 36 if (sample->isolate() != isolate) { |
40 continue; | 37 continue; |
41 } | 38 } |
42 c += sample->At(0); | 39 c += sample->At(0); |
43 } | 40 } |
44 free(sample); | |
45 return c; | 41 return c; |
46 } | 42 } |
47 }; | 43 }; |
48 | 44 |
49 | 45 |
50 TEST_CASE(ProfilerSampleBufferWrapTest) { | 46 TEST_CASE(ProfilerSampleBufferWrapTest) { |
51 SampleBuffer* sample_buffer = new SampleBuffer(3); | 47 SampleBuffer* sample_buffer = new SampleBuffer(3); |
52 Isolate* i = reinterpret_cast<Isolate*>(0x1); | 48 Isolate* i = reinterpret_cast<Isolate*>(0x1); |
53 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 49 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
54 Sample* s; | 50 Sample* s; |
55 s = sample_buffer->ReserveSample(); | 51 s = sample_buffer->ReserveSample(); |
56 s->Init(Sample::kIsolateSample, i, 0, 0); | 52 s->Init(i, 0, 0); |
57 s->SetAt(0, 2); | 53 s->SetAt(0, 2); |
58 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 54 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
59 s = sample_buffer->ReserveSample(); | 55 s = sample_buffer->ReserveSample(); |
60 s->Init(Sample::kIsolateSample, i, 0, 0); | 56 s->Init(i, 0, 0); |
61 s->SetAt(0, 4); | 57 s->SetAt(0, 4); |
62 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 58 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
63 s = sample_buffer->ReserveSample(); | 59 s = sample_buffer->ReserveSample(); |
64 s->Init(Sample::kIsolateSample, i, 0, 0); | 60 s->Init(i, 0, 0); |
65 s->SetAt(0, 6); | 61 s->SetAt(0, 6); |
66 EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 62 EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
67 s = sample_buffer->ReserveSample(); | 63 s = sample_buffer->ReserveSample(); |
68 s->Init(Sample::kIsolateSample, i, 0, 0); | 64 s->Init(i, 0, 0); |
69 s->SetAt(0, 8); | 65 s->SetAt(0, 8); |
70 EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); | 66 EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); |
71 delete sample_buffer; | 67 delete sample_buffer; |
72 } | 68 } |
73 | 69 |
74 | 70 |
75 TEST_CASE(ProfilerSampleBufferIterateTest) { | 71 TEST_CASE(ProfilerSampleBufferIterateTest) { |
76 SampleBuffer* sample_buffer = new SampleBuffer(3); | 72 SampleBuffer* sample_buffer = new SampleBuffer(3); |
77 Isolate* i = reinterpret_cast<Isolate*>(0x1); | 73 Isolate* i = reinterpret_cast<Isolate*>(0x1); |
78 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 74 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
79 Sample* s; | 75 Sample* s; |
80 s = sample_buffer->ReserveSample(); | 76 s = sample_buffer->ReserveSample(); |
81 s->Init(Sample::kIsolateSample, i, 0, 0); | 77 s->Init(i, 0, 0); |
82 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 78 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
83 s = sample_buffer->ReserveSample(); | 79 s = sample_buffer->ReserveSample(); |
84 s->Init(Sample::kIsolateSample, i, 0, 0); | 80 s->Init(i, 0, 0); |
85 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 81 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
86 s = sample_buffer->ReserveSample(); | 82 s = sample_buffer->ReserveSample(); |
87 s->Init(Sample::kIsolateSample, i, 0, 0); | 83 s->Init(i, 0, 0); |
88 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 84 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
89 s = sample_buffer->ReserveSample(); | 85 s = sample_buffer->ReserveSample(); |
90 s->Init(Sample::kIsolateSample, i, 0, 0); | 86 s->Init(i, 0, 0); |
91 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); | 87 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); |
92 delete sample_buffer; | 88 delete sample_buffer; |
93 } | 89 } |
94 | 90 |
95 } // namespace dart | 91 } // namespace dart |
OLD | NEW |