| 413 | } |
| 414 | |
| 415 | void cpuMonitorCycle() { |
| 416 | if (!_cpu_monitor_enabled) return; |
| 417 | |
| 418 | CpuTimes times; |
| 419 | times.proc.real = OS::getProcessCpuTime(×.proc.user, ×.proc.system); |
| 420 | times.total.real = OS::getTotalCpuTime(×.total.user, ×.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; |