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

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

Issue 131853007: Add flag to control number of stack frames collected by profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 | « runtime/vm/profiler.cc ('k') | no next file » | 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 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();
20 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { 21 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) {
21 Sample sample = sample_buffer.GetSample(i); 22 sample_buffer.CopySample(i, sample);
22 if (sample.isolate != isolate) { 23 if (sample->isolate() != isolate) {
23 continue; 24 continue;
24 } 25 }
25 c++; 26 c++;
26 } 27 }
28 free(sample);
27 return c; 29 return c;
28 } 30 }
29 31
30 32
31 static intptr_t IterateSumPC(const Isolate* isolate, 33 static intptr_t IterateSumPC(const Isolate* isolate,
32 const SampleBuffer& sample_buffer) { 34 const SampleBuffer& sample_buffer) {
33 intptr_t c = 0; 35 intptr_t c = 0;
36 Sample* sample = Sample::Allocate();
34 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) { 37 for (intptr_t i = 0; i < sample_buffer.capacity(); i++) {
35 Sample sample = sample_buffer.GetSample(i); 38 sample_buffer.CopySample(i, sample);
36 if (sample.isolate != isolate) { 39 if (sample->isolate() != isolate) {
37 continue; 40 continue;
38 } 41 }
39 c += sample.pcs[0]; 42 c += sample->At(0);
40 } 43 }
44 free(sample);
41 return c; 45 return c;
42 } 46 }
43 }; 47 };
44 48
45 49
46 TEST_CASE(ProfilerSampleBufferWrapTest) { 50 TEST_CASE(ProfilerSampleBufferWrapTest) {
47 SampleBuffer* sample_buffer = new SampleBuffer(3); 51 SampleBuffer* sample_buffer = new SampleBuffer(3);
48 Isolate* i = reinterpret_cast<Isolate*>(0x1); 52 Isolate* i = reinterpret_cast<Isolate*>(0x1);
49 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); 53 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
50 Sample* s; 54 Sample* s;
51 s = sample_buffer->ReserveSample(); 55 s = sample_buffer->ReserveSample();
52 s->isolate = i; 56 s->Init(Sample::kIsolateSample, i, 0, 0);
53 s->pcs[0] = 2; 57 s->SetAt(0, 2);
54 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); 58 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
55 s = sample_buffer->ReserveSample(); 59 s = sample_buffer->ReserveSample();
56 s->isolate = i; 60 s->Init(Sample::kIsolateSample, i, 0, 0);
57 s->pcs[0] = 4; 61 s->SetAt(0, 4);
58 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); 62 EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
59 s = sample_buffer->ReserveSample(); 63 s = sample_buffer->ReserveSample();
60 s->isolate = i; 64 s->Init(Sample::kIsolateSample, i, 0, 0);
61 s->pcs[0] = 6; 65 s->SetAt(0, 6);
62 EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); 66 EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
63 s = sample_buffer->ReserveSample(); 67 s = sample_buffer->ReserveSample();
64 s->isolate = i; 68 s->Init(Sample::kIsolateSample, i, 0, 0);
65 s->pcs[0] = 8; 69 s->SetAt(0, 8);
66 EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer)); 70 EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
67 delete sample_buffer; 71 delete sample_buffer;
68 } 72 }
69 73
70 74
71 TEST_CASE(ProfilerSampleBufferIterateTest) { 75 TEST_CASE(ProfilerSampleBufferIterateTest) {
72 SampleBuffer* sample_buffer = new SampleBuffer(3); 76 SampleBuffer* sample_buffer = new SampleBuffer(3);
73 Isolate* i = reinterpret_cast<Isolate*>(0x1); 77 Isolate* i = reinterpret_cast<Isolate*>(0x1);
74 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); 78 EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
75 Sample* s; 79 Sample* s;
76 s = sample_buffer->ReserveSample(); 80 s = sample_buffer->ReserveSample();
77 s->isolate = i; 81 s->Init(Sample::kIsolateSample, i, 0, 0);
78 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); 82 EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
79 s = sample_buffer->ReserveSample(); 83 s = sample_buffer->ReserveSample();
80 s->isolate = i; 84 s->Init(Sample::kIsolateSample, i, 0, 0);
81 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); 85 EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
82 s = sample_buffer->ReserveSample(); 86 s = sample_buffer->ReserveSample();
83 s->isolate = i; 87 s->Init(Sample::kIsolateSample, i, 0, 0);
84 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); 88 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
85 s = sample_buffer->ReserveSample(); 89 s = sample_buffer->ReserveSample();
86 s->isolate = i; 90 s->Init(Sample::kIsolateSample, i, 0, 0);
87 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer)); 91 EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
88 delete sample_buffer; 92 delete sample_buffer;
89 } 93 }
90 94
91 } // namespace dart 95 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698