Skip to content

Commit

Permalink
[BUG FIX] Call push_freq_mgr_.next() for next push period
Browse files Browse the repository at this point in the history
Summary:
The bug is that the next sampling time returns the next push time.
Because push time were never updated, the sampling time will be always 0, which means the iteration
will be repeating without any sleep, thus increases cpu usage.

Test Plan: Jenkins

Reviewers: #stirling, oazizi

Reviewed By: #stirling, oazizi

Differential Revision: https://phab.corp.pixielabs.ai/D8916

GitOrigin-RevId: fb11e0b
  • Loading branch information
yzhao1012 authored and copybaranaut committed Jun 10, 2021
1 parent 3c2a5fb commit 4f85e7a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stirling/core/utils.h
Expand Up @@ -89,7 +89,7 @@ class SamplePushFrequencyManager {
* @return std::chrono::milliseconds
*/
px::chrono::coarse_steady_clock::time_point NextSamplingTime() const {
return push_freq_mgr_.next();
return sampling_freq_mgr_.next();
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/stirling/core/utils_test.cc
Expand Up @@ -49,5 +49,33 @@ TEST(FrequencyManagerTest, SetPeriodEndAndCheck) {
EXPECT_GE(computed_period, std::chrono::milliseconds{9990});
}

// Tests that the sampling period were set correctly for SamplePushFrequencyManager.
TEST(SamplePushFrequencyManagerTest, SetSamplingPeriodEndAndCheck) {
SamplePushFrequencyManager mgr;
mgr.set_sampling_period(std::chrono::milliseconds{10000});
EXPECT_EQ(mgr.sampling_period(), std::chrono::milliseconds{10000});
EXPECT_TRUE(mgr.SamplingRequired());

mgr.Sample();
EXPECT_FALSE(mgr.SamplingRequired());
auto computed_period = mgr.NextSamplingTime() - px::chrono::coarse_steady_clock::now();
EXPECT_LE(computed_period, std::chrono::milliseconds{10000});
EXPECT_GE(computed_period, std::chrono::milliseconds{9990});
}

// Tests that the push period were set correctly for SamplePushFrequencyManager.
TEST(SamplePushFrequencyManagerTest, SetPushPeriodEndAndCheck) {
SamplePushFrequencyManager mgr;
mgr.set_push_period(std::chrono::milliseconds{10000});
EXPECT_EQ(mgr.push_period(), std::chrono::milliseconds{10000});
EXPECT_TRUE(mgr.PushRequired(0.5, 0));

mgr.Push();
EXPECT_FALSE(mgr.PushRequired(0.5, 0));
auto computed_period = mgr.NextPushTime() - px::chrono::coarse_steady_clock::now();
EXPECT_LE(computed_period, std::chrono::milliseconds{10000});
EXPECT_GE(computed_period, std::chrono::milliseconds{9990});
}

} // namespace stirling
} // namespace px

0 comments on commit 4f85e7a

Please sign in to comment.