MCPcopy Create free account
hub / github.com/apache/brpc / dump_thread

Method dump_thread

src/bvar/collector.cpp:362–411  ·  view source on GitHub ↗

Call user's callbacks in this thread.

Source from the content-addressed store, hash-verified

360
361// Call user's callbacks in this thread.
362void Collector::dump_thread() {
363 int64_t last_ns = butil::cpuwide_time_ns();
364
365 // vars
366 double busy_seconds = 0;
367 bvar::PassiveStatus<double> busy_seconds_var(deref_value<double>, &busy_seconds);
368 bvar::PerSecond<bvar::PassiveStatus<double> > busy_seconds_second(
369 "bvar_collector_dump_thread_usage", &busy_seconds_var);
370
371 bvar::PassiveStatus<int64_t> ndumped_var(deref_value<int64_t>, &_ndump);
372 bvar::PerSecond<bvar::PassiveStatus<int64_t> > ndumped_second(
373 "bvar::collector_dump_second", &ndumped_var);
374
375 butil::LinkNode<Collected> root;
376 size_t round = 0;
377
378 // The main loop
379 while (!_stop) {
380 ++round;
381 // Get new samples set by grab_thread.
382 butil::LinkNode<Collected>* newhead = NULL;
383 {
384 BAIDU_SCOPED_LOCK(_dump_thread_mutex);
385 while (!_stop && _dump_root.next() == &_dump_root) {
386 const int64_t now_ns = butil::cpuwide_time_ns();
387 busy_seconds += (now_ns - last_ns) / 1000000000.0;
388 pthread_cond_wait(&_dump_thread_cond, &_dump_thread_mutex);
389 last_ns = butil::cpuwide_time_ns();
390 }
391 if (_stop) {
392 break;
393 }
394 newhead = _dump_root.next();
395 _dump_root.RemoveFromList();
396 }
397 CHECK(newhead != &_dump_root);
398 newhead->InsertBeforeAsList(&root);
399
400 // Call callbacks.
401 for (butil::LinkNode<Collected>* p = root.next(); !_stop && p != &root;) {
402 // We remove p from the list, save next first.
403 butil::LinkNode<Collected>* saved_next = p->next();
404 p->RemoveFromList();
405 Collected* s = p->value();
406 s->dump_and_destroy(round);
407 ++_ndump;
408 p = saved_next;
409 }
410 }
411}
412
413// Submit a sample for asynchronous dumping. The Collector holds only the Collected*
414// pointer (e.g., SpanContainer*). Regardless of which branch is taken below, the

Callers 1

run_dump_threadMethod · 0.80

Calls 6

cpuwide_time_nsFunction · 0.85
RemoveFromListMethod · 0.80
InsertBeforeAsListMethod · 0.80
nextMethod · 0.45
valueMethod · 0.45
dump_and_destroyMethod · 0.45

Tested by

no test coverage detected