@@ -35,68 +35,70 @@ static double cached_utilisation_norm;
3535
3636static void DiskIOUpdateCache (const Machine * host ) {
3737 static uint64_t cached_last_update ;
38+
3839 uint64_t passedTimeInMs = host -> realtimeMs - cached_last_update ;
39- bool hasNewData = false;
40- DiskIOData data ;
4140
4241 /* update only every 500ms to have a sane span for rate calculation */
43- if (passedTimeInMs > 500 ) {
44- hasNewData = Platform_getDiskIO (& data );
45- if (!hasNewData ) {
46- status = RATESTATUS_NODATA ;
47- } else if (cached_last_update == 0 ) {
48- status = RATESTATUS_INIT ;
49- } else if (passedTimeInMs > 30000 ) {
50- status = RATESTATUS_STALE ;
51- } else {
52- status = RATESTATUS_DATA ;
53- }
42+ if (passedTimeInMs <= 500 )
43+ return ;
5444
55- cached_last_update = host -> realtimeMs ;
45+ DiskIOData data ;
46+ bool hasNewData = Platform_getDiskIO (& data );
47+ if (!hasNewData ) {
48+ status = RATESTATUS_NODATA ;
49+ } else if (cached_last_update == 0 ) {
50+ status = RATESTATUS_INIT ;
51+ } else if (passedTimeInMs > 30000 ) {
52+ status = RATESTATUS_STALE ;
53+ } else {
54+ status = RATESTATUS_DATA ;
5655 }
5756
58- if (hasNewData ) {
59- static uint64_t cached_read_total ;
60- static uint64_t cached_write_total ;
61- static uint64_t cached_msTimeSpend_total ;
57+ cached_last_update = host -> realtimeMs ;
6258
63- if (status != RATESTATUS_INIT ) {
64- uint64_t diff ;
59+ if (! hasNewData )
60+ return ;
6561
66- if (data .totalBytesRead > cached_read_total ) {
67- diff = data .totalBytesRead - cached_read_total ;
68- diff = (1000 * diff ) / passedTimeInMs ; /* convert to B/s */
69- diff /= ONE_K ; /* convert to KiB/s */
70- } else {
71- diff = 0 ;
72- }
73- Meter_humanUnit (cached_read_diff_str , diff , sizeof (cached_read_diff_str ));
74-
75- if (data .totalBytesWritten > cached_write_total ) {
76- diff = data .totalBytesWritten - cached_write_total ;
77- diff = (1000 * diff ) / passedTimeInMs ; /* convert to B/s */
78- diff /= ONE_K ; /* convert to KiB/s */
79- } else {
80- diff = 0 ;
81- }
82- Meter_humanUnit (cached_write_diff_str , diff , sizeof (cached_write_diff_str ));
83-
84- cached_utilisation_diff = 0.0 ;
85- cached_utilisation_norm = 0.0 ;
86- if (data .totalMsTimeSpend > cached_msTimeSpend_total ) {
87- diff = data .totalMsTimeSpend - cached_msTimeSpend_total ;
88- cached_utilisation_diff = 100.0 * (double )diff / passedTimeInMs ;
89- if (data .numDisks > 0 ) {
90- cached_utilisation_norm = (double )diff / (passedTimeInMs * data .numDisks );
91- cached_utilisation_norm = MINIMUM (cached_utilisation_norm , 1.0 );
92- }
93- }
62+ static uint64_t cached_read_total ;
63+ static uint64_t cached_write_total ;
64+ static uint64_t cached_msTimeSpend_total ;
65+
66+ if (status != RATESTATUS_INIT ) {
67+ uint64_t diff ;
68+
69+ if (data .totalBytesRead > cached_read_total ) {
70+ diff = data .totalBytesRead - cached_read_total ;
71+ diff = (1000 * diff ) / passedTimeInMs ; /* convert to B/s */
72+ diff /= ONE_K ; /* convert to KiB/s */
73+ } else {
74+ diff = 0 ;
9475 }
76+ Meter_humanUnit (cached_read_diff_str , diff , sizeof (cached_read_diff_str ));
9577
96- cached_read_total = data .totalBytesRead ;
97- cached_write_total = data .totalBytesWritten ;
98- cached_msTimeSpend_total = data .totalMsTimeSpend ;
78+ if (data .totalBytesWritten > cached_write_total ) {
79+ diff = data .totalBytesWritten - cached_write_total ;
80+ diff = (1000 * diff ) / passedTimeInMs ; /* convert to B/s */
81+ diff /= ONE_K ; /* convert to KiB/s */
82+ } else {
83+ diff = 0 ;
84+ }
85+ Meter_humanUnit (cached_write_diff_str , diff , sizeof (cached_write_diff_str ));
86+
87+ cached_utilisation_diff = 0.0 ;
88+ cached_utilisation_norm = 0.0 ;
89+ if (data .totalMsTimeSpend > cached_msTimeSpend_total ) {
90+ diff = data .totalMsTimeSpend - cached_msTimeSpend_total ;
91+ cached_utilisation_diff = 100.0 * (double )diff / passedTimeInMs ;
92+ if (data .numDisks > 0 ) {
93+ cached_utilisation_norm = (double )diff / (passedTimeInMs * data .numDisks );
94+ cached_utilisation_norm = MINIMUM (cached_utilisation_norm , 1.0 );
95+ }
96+ }
9997 }
98+
99+ cached_read_total = data .totalBytesRead ;
100+ cached_write_total = data .totalBytesWritten ;
101+ cached_msTimeSpend_total = data .totalMsTimeSpend ;
100102}
101103
102104static void DiskIOMeter_updateValues (Meter * this ) {
0 commit comments