Index: test/cctest/test-profile-generator.cc |
diff --git a/test/cctest/test-profile-generator.cc b/test/cctest/test-profile-generator.cc |
index f56275c1beef1e0b6ec8efcc5d9d5207bf7d0296..7b8278ba660d4d490a026af108308b1c756e3043 100644 |
--- a/test/cctest/test-profile-generator.cc |
+++ b/test/cctest/test-profile-generator.cc |
@@ -41,6 +41,7 @@ using i::CpuProfilesCollection; |
using i::ProfileNode; |
using i::ProfileTree; |
using i::ProfileGenerator; |
+using i::SampleRateCalculator; |
using i::TickSample; |
using i::Vector; |
@@ -484,7 +485,7 @@ TEST(RecordTickSample) { |
sample3.frames_count = 2; |
generator.RecordTickSample(sample3); |
- CpuProfile* profile = profiles.StopProfiling(""); |
+ CpuProfile* profile = profiles.StopProfiling("", 1); |
CHECK_NE(NULL, profile); |
ProfileTreeTestHelper top_down_test_helper(profile->top_down()); |
CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); |
@@ -504,6 +505,56 @@ TEST(RecordTickSample) { |
} |
+TEST(SampleRateCalculator) { |
+ const double kSamplingIntervalMs = i::Logger::kSamplingIntervalMs; |
+ |
+ // Verify that ticking exactly in query intervals results in the |
+ // initial sampling interval. |
+ double time = 0.0; |
+ SampleRateCalculator calc1; |
+ CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
+ calc1.UpdateMeasurements(time); |
+ CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
+ time += SampleRateCalculator::kWallTimeQueryIntervalMs; |
+ calc1.UpdateMeasurements(time); |
+ CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
+ time += SampleRateCalculator::kWallTimeQueryIntervalMs; |
+ calc1.UpdateMeasurements(time); |
+ CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
+ time += SampleRateCalculator::kWallTimeQueryIntervalMs; |
+ calc1.UpdateMeasurements(time); |
+ CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
+ |
+ SampleRateCalculator calc2; |
+ time = 0.0; |
+ CHECK_EQ(kSamplingIntervalMs, calc2.ticks_per_ms()); |
+ calc2.UpdateMeasurements(time); |
+ CHECK_EQ(kSamplingIntervalMs, calc2.ticks_per_ms()); |
+ time += SampleRateCalculator::kWallTimeQueryIntervalMs * 0.5; |
+ calc2.UpdateMeasurements(time); |
+ // (1.0 + 2.0) / 2 |
+ CHECK_EQ(kSamplingIntervalMs * 1.5, calc2.ticks_per_ms()); |
+ time += SampleRateCalculator::kWallTimeQueryIntervalMs * 0.75; |
+ calc2.UpdateMeasurements(time); |
+ // (1.0 + 2.0 + 2.0) / 3 |
+ CHECK_EQ(kSamplingIntervalMs * 5.0, floor(calc2.ticks_per_ms() * 3.0 + 0.5)); |
+ |
+ SampleRateCalculator calc3; |
+ time = 0.0; |
+ CHECK_EQ(kSamplingIntervalMs, calc3.ticks_per_ms()); |
+ calc3.UpdateMeasurements(time); |
+ CHECK_EQ(kSamplingIntervalMs, calc3.ticks_per_ms()); |
+ time += SampleRateCalculator::kWallTimeQueryIntervalMs * 2; |
+ calc3.UpdateMeasurements(time); |
+ // (1.0 + 0.5) / 2 |
+ CHECK_EQ(kSamplingIntervalMs * 0.75, calc3.ticks_per_ms()); |
+ time += SampleRateCalculator::kWallTimeQueryIntervalMs * 1.5; |
+ calc3.UpdateMeasurements(time); |
+ // (1.0 + 0.5 + 0.5) / 3 |
+ CHECK_EQ(kSamplingIntervalMs * 2.0, floor(calc3.ticks_per_ms() * 3.0 + 0.5)); |
+} |
+ |
+ |
static void CheckNodeIds(ProfileNode* node, int* expectedId) { |
CHECK_EQ((*expectedId)++, node->id()); |
for (int i = 0; i < node->children()->length(); i++) { |
@@ -547,7 +598,7 @@ TEST(SampleIds) { |
sample3.frames_count = 2; |
generator.RecordTickSample(sample3); |
- CpuProfile* profile = profiles.StopProfiling(""); |
+ CpuProfile* profile = profiles.StopProfiling("", 1); |
int nodeId = 1; |
CheckNodeIds(profile->top_down()->root(), &nodeId); |
CHECK_EQ(7, nodeId - 1); |
@@ -576,7 +627,7 @@ TEST(NoSamples) { |
sample1.frames_count = 1; |
generator.RecordTickSample(sample1); |
- CpuProfile* profile = profiles.StopProfiling(""); |
+ CpuProfile* profile = profiles.StopProfiling("", 1); |
int nodeId = 1; |
CheckNodeIds(profile->top_down()->root(), &nodeId); |
CHECK_EQ(3, nodeId - 1); |