MCPcopy Create free account
hub / github.com/apache/thrift / reportCheckpoint

Method reportCheckpoint

contrib/fb303/cpp/ServiceTracker.cpp:239–292  ·  view source on GitHub ↗

* Logs some statistics gathered since the last call to this method. * * note: Thread race conditions on this method could cause * misreporting and/or undefined behavior; the caller must protect * uses of the object variables (and calls to this method) with a * mutex. * */

Source from the content-addressed store, hash-verified

237 *
238 */
239void
240ServiceTracker::reportCheckpoint()
241{
242 time_t now = time(nullptr);
243
244 uint64_t check_count = checkpointServices_;
245 uint64_t check_interval = now - checkpointTime_;
246 uint64_t check_duration = checkpointDuration_;
247
248 // export counters for timing of service methods (by service name)
249 handler_->setCounter("checkpoint_time", check_interval);
250 map<string, pair<uint64_t, uint64_t> >::iterator iter;
251 uint64_t count;
252 for (iter = checkpointServiceDuration_.begin();
253 iter != checkpointServiceDuration_.end();
254 ++iter) {
255 count = iter->second.first;
256 handler_->setCounter(string("checkpoint_count_") + iter->first, count);
257 if (count == 0) {
258 handler_->setCounter(string("checkpoint_speed_") + iter->first,
259 0);
260 } else {
261 handler_->setCounter(string("checkpoint_speed_") + iter->first,
262 iter->second.second / count);
263 }
264 }
265
266 // reset checkpoint variables
267 // note: Clearing the map while other threads are using it might
268 // cause undefined behavior.
269 checkpointServiceDuration_.clear();
270 checkpointTime_ = now;
271 checkpointServices_ = 0;
272 checkpointDuration_ = 0;
273
274 // get lifetime variables
275 uint64_t life_count = handler_->getCounter("lifetime_services");
276 uint64_t life_interval = now - handler_->aliveSince();
277
278 // log checkpoint
279 stringstream message;
280 message << "checkpoint_time:" << check_interval
281 << " checkpoint_services:" << check_count
282 << " checkpoint_speed_sum:" << check_duration
283 << " lifetime_time:" << life_interval
284 << " lifetime_services:" << life_count;
285 if (featureThreadCheck_ && threadManager_ != nullptr) {
286 size_t worker_count = threadManager_->workerCount();
287 size_t idle_count = threadManager_->idleWorkerCount();
288 message << " total_workers:" << worker_count
289 << " active_workers:" << (worker_count - idle_count);
290 }
291 logMethod_(4, message.str());
292}
293
294/**
295 * Remembers the thread manager used in the server, for monitoring thread

Callers

nothing calls this directly

Calls 10

stringFunction · 0.85
workerCountMethod · 0.80
idleWorkerCountMethod · 0.80
strMethod · 0.80
clearMethod · 0.65
setCounterMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getCounterMethod · 0.45
aliveSinceMethod · 0.45

Tested by

no test coverage detected