| 152 | } |
| 153 | |
| 154 | static void HandleResponse(RespClosure* closure) { |
| 155 | std::unique_ptr<brpc::Controller> cntl_guard(closure->cntl); |
| 156 | std::unique_ptr<test::PerfTestResponse> response_guard(closure->resp); |
| 157 | if (closure->cntl->Failed()) { |
| 158 | LOG(ERROR) << "RPC call failed: " << closure->cntl->ErrorText(); |
| 159 | closure->test->_stop = true; |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | g_latency_recorder << closure->cntl->latency_us(); |
| 164 | if (closure->resp->cpu_usage().size() > 0) { |
| 165 | g_server_cpu_recorder << atof(closure->resp->cpu_usage().c_str()) * 100; |
| 166 | } |
| 167 | g_total_bytes.fetch_add(closure->cntl->request_attachment().size(), butil::memory_order_relaxed); |
| 168 | g_total_cnt.fetch_add(1, butil::memory_order_relaxed); |
| 169 | |
| 170 | cntl_guard.reset(NULL); |
| 171 | response_guard.reset(NULL); |
| 172 | |
| 173 | if (closure->test->_iterations == 0 && FLAGS_test_iterations > 0) { |
| 174 | closure->test->_stop = true; |
| 175 | return; |
| 176 | } |
| 177 | --closure->test->_iterations; |
| 178 | uint64_t last = g_last_time.load(butil::memory_order_relaxed); |
| 179 | uint64_t now = butil::cpuwide_time_us(); |
| 180 | if (now > last && now - last > 100000) { |
| 181 | if (g_last_time.exchange(now, butil::memory_order_relaxed) == last) { |
| 182 | g_client_cpu_recorder << |
| 183 | atof(bvar::Variable::describe_exposed("process_cpu_usage").c_str()) * 100; |
| 184 | } |
| 185 | } |
| 186 | if (now - closure->test->_start_time > FLAGS_test_seconds * 1000000u) { |
| 187 | closure->test->_stop = true; |
| 188 | return; |
| 189 | } |
| 190 | closure->test->SendRequest(); |
| 191 | } |
| 192 | |
| 193 | static void* RunTest(void* arg) { |
| 194 | PerformanceTest* test = (PerformanceTest*)arg; |
nothing calls this directly
no test coverage detected