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

Method run_main_task

src/bthread/task_group.cpp:198–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198void TaskGroup::run_main_task() {
199 bvar::PassiveStatus<double> cumulated_cputime(
200 get_cumulated_cputime_from_this, this);
201 std::unique_ptr<bvar::PerSecond<bvar::PassiveStatus<double> > > usage_bvar;
202
203 TaskGroup* dummy = this;
204 bthread_t tid;
205 while (wait_task(&tid)) {
206 sched_to(&dummy, tid);
207 DCHECK_EQ(this, dummy);
208 DCHECK_EQ(_cur_meta->stack, _main_stack);
209 if (_cur_meta->tid != _main_tid) {
210 task_runner(1/*skip remained*/);
211 }
212 if (FLAGS_show_per_worker_usage_in_vars && !usage_bvar) {
213 char name[32];
214#if defined(OS_MACOSX)
215 snprintf(name, sizeof(name), "bthread_worker_usage_%" PRIu64,
216 pthread_numeric_id());
217#else
218 snprintf(name, sizeof(name), "bthread_worker_usage_%ld",
219 (long)syscall(SYS_gettid));
220#endif
221 usage_bvar.reset(new bvar::PerSecond<bvar::PassiveStatus<double> >
222 (name, &cumulated_cputime, 1));
223 }
224 }
225 // Don't forget to add elapse of last wait_task.
226 current_task()->stat.cputime_ns +=
227 butil::cpuwide_time_ns() - _cpu_time_stat.load_unsafe().last_run_ns();
228}
229
230TaskGroup::TaskGroup(TaskControl* c)
231 : _control(c) {

Callers 1

worker_threadMethod · 0.80

Calls 6

snprintfFunction · 0.85
pthread_numeric_idFunction · 0.85
cpuwide_time_nsFunction · 0.85
last_run_nsMethod · 0.80
resetMethod · 0.45
load_unsafeMethod · 0.45

Tested by

no test coverage detected