MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / cpuMonitorCycle

Method cpuMonitorCycle

src/flightRecorder.cpp:415–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

413 }
414
415 void cpuMonitorCycle() {
416 if (!_cpu_monitor_enabled) return;
417
418 CpuTimes times;
419 times.proc.real = OS::getProcessCpuTime(&times.proc.user, &times.proc.system);
420 times.total.real = OS::getTotalCpuTime(&times.total.user, &times.total.system);
421
422 float proc_user = 0, proc_system = 0, machine_total = 0;
423
424 if (times.proc.real != (u64)-1 && times.proc.real > _last_times.proc.real) {
425 float delta = (times.proc.real - _last_times.proc.real) * _available_processors;
426 proc_user = ratio((times.proc.user - _last_times.proc.user) / delta);
427 proc_system = ratio((times.proc.system - _last_times.proc.system) / delta);
428 }
429
430 if (times.total.real != (u64)-1 && times.total.real > _last_times.total.real) {
431 float delta = times.total.real - _last_times.total.real;
432 machine_total = ratio(((times.total.user + times.total.system) -
433 (_last_times.total.user + _last_times.total.system)) / delta);
434 if (machine_total < proc_user + proc_system) {
435 machine_total = ratio(proc_user + proc_system);
436 }
437 }
438
439 recordCpuLoad(&_monitor_buf, proc_user, proc_system, machine_total);
440 flushIfNeeded(&_monitor_buf, SMALL_BUFFER_LIMIT);
441
442 _last_times = times;
443 }
444
445 void heapMonitorCycle(u32 gc_id) {
446 if (!_heap_monitor_enabled || gc_id == _last_gc_id) return;

Callers 1

timerTickMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected