The GitHub Actions job "CI" on kvrocks.git/unstable has failed.
Run started by GitHub user PragmaTwice (triggered by PragmaTwice).

Head commit for run:
792df3612c2d6bde2159cacbd104f12e0f73c6d5 / sryan yuan <[email protected]>
feat(info): add thread CPU time measurement for worker thread monitoring (#3379)

## Summary
This PR introduces worker thread CPU time monitoring to identify
bottlenecks and fixes precision issues in process CPU time calculations.

## Problem Statement
1. **Lack of granular thread monitoring**: The current `INFO` command
provides only overall process CPU time, which includes background
threads. This makes it difficult to identify bottlenecks in worker
threads specifically, as background thread activity can mask true worker
thread utilization.

2. **Precision loss in CPU time calculation**: The existing CPU time
calculation truncates microsecond values due to integer division
(`tv_usec / 1000000`), causing millisecond data loss. This results in
inaccurate reporting, especially for short operations where sub-second
precision matters.

## Solution
### 1. Worker Thread CPU Time Monitoring
- Added new `worker_cpu_time` metric to track CPU usage per worker
thread
- Implemented per-thread CPU time collection using platform-specific
APIs
- Formatted output with microsecond precision (6 decimal places) to
match system precision
- Sample output: `worker_cpu_time:[0.123456,0.456789,1.234567]`

### 2. CPU Time Calculation Fix
- Fixed precision loss in `used_cpu_user` and `used_cpu_sys`
calculations
- Replaced integer division with floating point division:  
  **Before**: `tv_usec / 1000000` → truncates to integer  
**After**: `static_cast<double>(tv_usec) / 1e6` → preserves microseconds

## Benefits
- **Pinpoint worker thread bottlenecks**: Isolate worker thread CPU
usage from background threads
- **Accurate performance analysis**: Microsecond-precision timing
enables precise performance profiling
- **Better load diagnosis**: Distinguish between actual worker
saturation and background activity

---------

Co-authored-by: yxj25245 <[email protected]>

Report URL: https://github.com/apache/kvrocks/actions/runs/22614774746

With regards,
GitHub Actions via GitBox

Reply via email to