| 1480 | } |
| 1481 | |
| 1482 | void Profiler::timerLoop(void* timer_id) { |
| 1483 | u64 current_micros = OS::micros(); |
| 1484 | u64 loop_limit = std::min(_stop_time, _loop_time); |
| 1485 | u64 sleep_until = _jfr.active() ? current_micros + 1000000 : loop_limit; |
| 1486 | |
| 1487 | while (true) { |
| 1488 | { |
| 1489 | // Release _timer_lock after sleep to avoid deadlock with Profiler::stop |
| 1490 | MutexLocker ml(_timer_lock); |
| 1491 | while (_timer_id == timer_id && !_timer_lock.waitUntil(sleep_until)) { |
| 1492 | // timeout not reached |
| 1493 | } |
| 1494 | if (_timer_id != timer_id) return; |
| 1495 | } |
| 1496 | |
| 1497 | if ((current_micros = OS::micros()) >= loop_limit) { |
| 1498 | expire(_global_args, current_micros < _stop_time); |
| 1499 | return; |
| 1500 | } |
| 1501 | |
| 1502 | bool need_switch_chunk = _jfr.timerTick(current_micros, _gc_id); |
| 1503 | if (need_switch_chunk) { |
| 1504 | // Flush under profiler state lock |
| 1505 | flushJfr(); |
| 1506 | } |
| 1507 | |
| 1508 | sleep_until = current_micros + 1000000; |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | void Profiler::logEmptyOutput(Arguments& args, u64 printed_samples_count, Writer& out) { |
| 1513 | if (!out.good()) { |
no test coverage detected