本文整理汇总了C++中Sampler::InsertBeforeAsList方法的典型用法代码示例。如果您正苦于以下问题:C++ Sampler::InsertBeforeAsList方法的具体用法?C++ Sampler::InsertBeforeAsList怎么用?C++ Sampler::InsertBeforeAsList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sampler
的用法示例。
在下文中一共展示了Sampler::InsertBeforeAsList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void SamplerCollector::run() {
butil::LinkNode<Sampler> root;
int consecutive_nosleep = 0;
#ifndef UNIT_TEST
PassiveStatus<double> cumulated_time(get_cumulated_time, this);
bvar::PerSecond<bvar::PassiveStatus<double> > usage(
"bvar_sampler_collector_usage", &cumulated_time, 10);
#endif
while (!_stop) {
int64_t abstime = butil::gettimeofday_us();
Sampler* s = this->reset();
if (s) {
s->InsertBeforeAsList(&root);
}
int nremoved = 0;
int nsampled = 0;
for (butil::LinkNode<Sampler>* p = root.next(); p != &root;) {
// We may remove p from the list, save next first.
butil::LinkNode<Sampler>* saved_next = p->next();
Sampler* s = p->value();
s->_mutex.lock();
if (!s->_used) {
s->_mutex.unlock();
p->RemoveFromList();
delete s;
++nremoved;
} else {
s->take_sample();
s->_mutex.unlock();
++nsampled;
}
p = saved_next;
}
bool slept = false;
int64_t now = butil::gettimeofday_us();
_cumulated_time_us += now - abstime;
abstime += 1000000L;
while (abstime > now) {
::usleep(abstime - now);
slept = true;
now = butil::gettimeofday_us();
}
if (slept) {
consecutive_nosleep = 0;
} else {
if (++consecutive_nosleep >= WARN_NOSLEEP_THRESHOLD) {
consecutive_nosleep = 0;
LOG(WARNING) << "bvar is busy at sampling for "
<< WARN_NOSLEEP_THRESHOLD << " seconds!";
}
}
}
}