sryanyuan opened a new pull request, #3379:
URL: https://github.com/apache/kvrocks/pull/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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to