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

Unified Diff: runtime/vm/profiler_test.cc

Issue 25909002: Sampling profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/profiler_macos.cc ('k') | runtime/vm/profiler_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/profiler_test.cc
diff --git a/runtime/vm/profiler_test.cc b/runtime/vm/profiler_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a974b8519045bb6385b81244435d817dc9317ed8
--- /dev/null
+++ b/runtime/vm/profiler_test.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "platform/assert.h"
+
+#include "vm/dart_api_impl.h"
+#include "vm/dart_api_state.h"
+#include "vm/globals.h"
+#include "vm/profiler.h"
+#include "vm/unit_test.h"
+
+namespace dart {
+
+class ProfileSampleBufferTestHelper {
+ public:
+ static intptr_t IterateCount(const SampleBuffer& sample_buffer) {
+ intptr_t c = 0;
+ for (Sample* i = sample_buffer.FirstSample();
+ i != sample_buffer.LastSample();
+ i = sample_buffer.NextSample(i)) {
+ c++;
+ }
+ return c;
+ }
+
+
+ static intptr_t IterateSumPC(const SampleBuffer& sample_buffer) {
+ intptr_t c = 0;
+ for (Sample* i = sample_buffer.FirstSample();
+ i != sample_buffer.LastSample();
+ i = sample_buffer.NextSample(i)) {
+ c += i->pcs[0];
+ }
+ return c;
+ }
+};
+
+
+TEST_CASE(ProfilerSampleBufferWrapTest) {
+ SampleBuffer* sample_buffer = new SampleBuffer(3);
+ EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer));
+ Sample* s;
+ s = sample_buffer->ReserveSample();
+ s->pcs[0] = 2;
+ EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer));
+ s = sample_buffer->ReserveSample();
+ s->pcs[0] = 4;
+ EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer));
+ s = sample_buffer->ReserveSample();
+ s->pcs[0] = 6;
+ EXPECT_EQ(10, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer));
+ s = sample_buffer->ReserveSample();
+ s->pcs[0] = 8;
+ EXPECT_EQ(14, ProfileSampleBufferTestHelper::IterateSumPC(*sample_buffer));
+ delete sample_buffer;
+}
+
+
+TEST_CASE(ProfilerSampleBufferIterateTest) {
+ SampleBuffer* sample_buffer = new SampleBuffer(3);
+ EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer));
+ sample_buffer->ReserveSample();
+ EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer));
+ sample_buffer->ReserveSample();
+ EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer));
+ sample_buffer->ReserveSample();
+ EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer));
+ sample_buffer->ReserveSample();
+ EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(*sample_buffer));
+ delete sample_buffer;
+}
+
+} // namespace dart
« 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