本文整理汇总了C++中EventBase::resetLoadAvg方法的典型用法代码示例。如果您正苦于以下问题:C++ EventBase::resetLoadAvg方法的具体用法?C++ EventBase::resetLoadAvg怎么用?C++ EventBase::resetLoadAvg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventBase
的用法示例。
在下文中一共展示了EventBase::resetLoadAvg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: timeouts
/**
* Verify that idle time is correctly accounted for when decaying our loop
* time.
*
* This works by creating a high loop time (via usleep), expecting a latency
* callback with known value, and then scheduling a timeout for later. This
* later timeout is far enough in the future that the idle time should have
* caused the loop time to decay.
*/
TEST(EventBaseTest, IdleTime) {
EventBase eventBase;
eventBase.setLoadAvgMsec(1000);
eventBase.resetLoadAvg(5900.0);
std::deque<uint64_t> timeouts0(4, 8080);
timeouts0.push_front(8000);
timeouts0.push_back(14000);
IdleTimeTimeoutSeries tos0(&eventBase, timeouts0);
std::deque<uint64_t> timeouts(20, 20);
std::unique_ptr<IdleTimeTimeoutSeries> tos;
int64_t testStart = duration_cast<microseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count();
bool hostOverloaded = false;
int latencyCallbacks = 0;
eventBase.setMaxLatency(6000, [&]() {
++latencyCallbacks;
switch (latencyCallbacks) {
case 1:
if (tos0.getTimeouts() < 6) {
// This could only happen if the host this test is running
// on is heavily loaded.
int64_t maxLatencyReached = duration_cast<microseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count();
ASSERT_LE(43800, maxLatencyReached - testStart);
hostOverloaded = true;
break;
}
ASSERT_EQ(6, tos0.getTimeouts());
ASSERT_GE(6100, eventBase.getAvgLoopTime() - 1200);
ASSERT_LE(6100, eventBase.getAvgLoopTime() + 1200);
tos.reset(new IdleTimeTimeoutSeries(&eventBase, timeouts));
break;
default:
FAIL() << "Unexpected latency callback";
break;
}
});
// Kick things off with an "immedite" timeout
tos0.scheduleTimeout(1);
eventBase.loop();
if (hostOverloaded) {
return;
}
ASSERT_EQ(1, latencyCallbacks);
ASSERT_EQ(7, tos0.getTimeouts());
ASSERT_GE(5900, eventBase.getAvgLoopTime() - 1200);
ASSERT_LE(5900, eventBase.getAvgLoopTime() + 1200);
ASSERT_TRUE(!!tos);
ASSERT_EQ(21, tos->getTimeouts());
}