MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / thread_worker

Function thread_worker

tools/cpp_examples/demo-client/src/ximage_press.cpp:137–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137void thread_worker(PredictorApi* api, int thread_id) {
138 Request req;
139 Response res;
140
141 api->thrd_initialize();
142
143 for (int i = 0; i < FLAGS_requests; ++i) {
144 api->thrd_clear();
145
146 Predictor* predictor = api->fetch_predictor("ximage");
147 if (!predictor) {
148 LOG(ERROR) << "Failed fetch predictor: ximage";
149 return;
150 }
151
152 req.Clear();
153 res.Clear();
154
155 if (create_req(req) != 0) {
156 return;
157 }
158
159 while (g_concurrency.load() >= FLAGS_concurrency) {
160 }
161 g_concurrency++;
162#if 1
163 LOG(INFO) << "Current concurrency " << g_concurrency.load();
164#endif
165
166 timeval start;
167 timeval end;
168
169 gettimeofday(&start, NULL);
170 if (predictor->inference(&req, &res) != 0) {
171 LOG(ERROR) << "failed call predictor with req:" << req.ShortDebugString();
172 return;
173 }
174 gettimeofday(&end, NULL);
175
176 g_round_time[thread_id].push_back(end.tv_sec * 1000 + end.tv_usec / 1000 -
177 start.tv_sec * 1000 -
178 start.tv_usec / 1000);
179
180 extract_res(req, res);
181 res.Clear();
182
183 g_concurrency--;
184#if 1
185 LOG(INFO) << "Done. Currenct concurrency " << g_concurrency.load();
186#endif
187 } // for (int i = 0; i < FLAGS_requests; ++i)
188
189 api->thrd_finalize();
190}
191
192int main(int argc, char** argv) {
193 google::ParseCommandLineFlags(&argc, &argv, true);

Callers

nothing calls this directly

Calls 11

push_backMethod · 0.80
create_reqFunction · 0.70
extract_resFunction · 0.70
thrd_initializeMethod · 0.45
thrd_clearMethod · 0.45
fetch_predictorMethod · 0.45
ClearMethod · 0.45
loadMethod · 0.45
inferenceMethod · 0.45
ShortDebugStringMethod · 0.45
thrd_finalizeMethod · 0.45

Tested by

no test coverage detected