919dc2d6eb
* Threads can only register and unregister themselves with ThreadInterrupter. * Profiler is no longer involved in interrupting threads. It's just a callback and the buffer. * Profiler operates lock free using an atomic operation to reserve sample in sample buffer. * Linux, Mac, and Windows done. R=asiva@google.com Review URL: https://codereview.chromium.org//109803002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31170 260f80e4-7a28-3924-810f-c04153c831b5
92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
// 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 Isolate* isolate,
|
|
const SampleBuffer& sample_buffer) {
|
|
intptr_t c = 0;
|
|
for (intptr_t i = 0; i < sample_buffer.capacity(); i++) {
|
|
Sample* sample = sample_buffer.GetSample(i);
|
|
if (sample->isolate != isolate) {
|
|
continue;
|
|
}
|
|
c++;
|
|
}
|
|
return c;
|
|
}
|
|
|
|
|
|
static intptr_t IterateSumPC(const Isolate* isolate,
|
|
const SampleBuffer& sample_buffer) {
|
|
intptr_t c = 0;
|
|
for (intptr_t i = 0; i < sample_buffer.capacity(); i++) {
|
|
Sample* sample = sample_buffer.GetSample(i);
|
|
if (sample->isolate != isolate) {
|
|
continue;
|
|
}
|
|
c += sample->pcs[0];
|
|
}
|
|
return c;
|
|
}
|
|
};
|
|
|
|
|
|
TEST_CASE(ProfilerSampleBufferWrapTest) {
|
|
SampleBuffer* sample_buffer = new SampleBuffer(3);
|
|
Isolate* i = reinterpret_cast<Isolate*>(0x1);
|
|
EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
|
|
Sample* s;
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
s->pcs[0] = 2;
|
|
EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
s->pcs[0] = 4;
|
|
EXPECT_EQ(6, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
s->pcs[0] = 6;
|
|
EXPECT_EQ(12, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
s->pcs[0] = 8;
|
|
EXPECT_EQ(18, ProfileSampleBufferTestHelper::IterateSumPC(i, *sample_buffer));
|
|
delete sample_buffer;
|
|
}
|
|
|
|
|
|
TEST_CASE(ProfilerSampleBufferIterateTest) {
|
|
SampleBuffer* sample_buffer = new SampleBuffer(3);
|
|
Isolate* i = reinterpret_cast<Isolate*>(0x1);
|
|
EXPECT_EQ(0, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
|
|
Sample* s;
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
EXPECT_EQ(1, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
EXPECT_EQ(2, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
|
|
s = sample_buffer->ReserveSample();
|
|
s->isolate = i;
|
|
EXPECT_EQ(3, ProfileSampleBufferTestHelper::IterateCount(i, *sample_buffer));
|
|
delete sample_buffer;
|
|
}
|
|
|
|
} // namespace dart
|