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

Method default_method

src/brpc/builtin/bthreads_service.cpp:34–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32namespace brpc {
33
34void BthreadsService::default_method(::google::protobuf::RpcController* cntl_base,
35 const ::brpc::BthreadsRequest*,
36 ::brpc::BthreadsResponse*,
37 ::google::protobuf::Closure* done) {
38 ClosureGuard done_guard(done);
39 Controller *cntl = static_cast<Controller*>(cntl_base);
40 cntl->http_response().set_content_type("text/plain");
41 butil::IOBufBuilder os;
42 const std::string& constraint = cntl->http_request().unresolved_path();
43 if (constraint.empty()) {
44#ifdef BRPC_BTHREAD_TRACER
45 os << "Use /bthreads/<bthread_id> or /bthreads/<bthread_id>?st=1 for stack trace\n";
46 os << "To check all living bthread, use /bthreads/all or /bthreads/all?st=1 for stack trace\n";
47#else
48 os << "Use /bthreads/<bthread_id>\n";
49 os << "To check all living bthread, use /bthreads/all\n";
50#endif // BRPC_BTHREAD_TRACER
51 } else {
52 bool enable_trace = false;
53#ifdef BRPC_BTHREAD_TRACER
54 const std::string* st = cntl->http_request().uri().GetQuery("st");
55 if (NULL != st && *st == "1") {
56 enable_trace = true;
57 }
58#endif // BRPC_BTHREAD_TRACER
59 char* endptr = NULL;
60 bthread_t tid = strtoull(constraint.c_str(), &endptr, 10);
61 if (*endptr == '\0' || *endptr == '/' || *endptr == '?') {
62 ::bthread::print_task(os, tid, enable_trace);
63 }
64 else if (constraint != "all" && constraint != "all?st=1") {
65 cntl->SetFailed(ENOMETHOD, "path=%s is not a bthread id or all, or all?st=1\n",
66 constraint.c_str());
67 } else {
68 ::bthread::print_living_tasks(os, enable_trace);
69 }
70
71 }
72 os.move_to(cntl->response_attachment());
73}
74
75} // namespace brpc

Callers

nothing calls this directly

Calls 8

print_taskFunction · 0.85
print_living_tasksFunction · 0.85
set_content_typeMethod · 0.80
GetQueryMethod · 0.80
emptyMethod · 0.45
c_strMethod · 0.45
SetFailedMethod · 0.45
move_toMethod · 0.45

Tested by

no test coverage detected