| 28 | namespace brpc { |
| 29 | |
| 30 | void ThreadsService::default_method(::google::protobuf::RpcController* cntl_base, |
| 31 | const ::brpc::ThreadsRequest*, |
| 32 | ::brpc::ThreadsResponse*, |
| 33 | ::google::protobuf::Closure* done) { |
| 34 | ClosureGuard done_guard(done); |
| 35 | Controller *cntl = static_cast<Controller*>(cntl_base); |
| 36 | cntl->http_response().set_content_type("text/plain"); |
| 37 | butil::IOBuf& resp = cntl->response_attachment(); |
| 38 | |
| 39 | std::string cmd = butil::string_printf("pstack %lld", (long long)getpid()); |
| 40 | butil::Timer tm; |
| 41 | tm.start(); |
| 42 | butil::IOBufBuilder pstack_output; |
| 43 | const int rc = butil::read_command_output(pstack_output, cmd.c_str()); |
| 44 | if (rc < 0) { |
| 45 | LOG(ERROR) << "Fail to popen `" << cmd << "'"; |
| 46 | return; |
| 47 | } |
| 48 | pstack_output.move_to(resp); |
| 49 | tm.stop(); |
| 50 | resp.append(butil::string_printf("\n\ntime=%" PRId64 "ms", tm.m_elapsed())); |
| 51 | } |
| 52 | |
| 53 | } // namespace brpc |
nothing calls this directly
no test coverage detected