@@ -27,8 +27,15 @@ static const int DiskIOMeter_attributes[] = {
2727 METER_VALUE_IOWRITE ,
2828};
2929
30+ static const int DiskIORateMeter_attributes [] = {
31+ METER_VALUE_IOREAD ,
32+ METER_VALUE_IOWRITE ,
33+ };
34+
3035static MeterRateStatus status = RATESTATUS_INIT ;
36+ static double cached_read_diff ;
3137static char cached_read_diff_str [6 ];
38+ static double cached_write_diff ;
3239static char cached_write_diff_str [6 ];
3340static double cached_utilisation_diff ;
3441static double cached_utilisation_norm ;
@@ -73,6 +80,7 @@ static void DiskIOUpdateCache(const Machine* host) {
7380 } else {
7481 diff = 0 ;
7582 }
83+ cached_read_diff = diff ;
7684 Meter_humanUnit (cached_read_diff_str , diff , sizeof (cached_read_diff_str ));
7785
7886 if (data .totalBytesWritten > cached_write_total ) {
@@ -82,6 +90,7 @@ static void DiskIOUpdateCache(const Machine* host) {
8290 } else {
8391 diff = 0 ;
8492 }
93+ cached_write_diff = diff ;
8594 Meter_humanUnit (cached_write_diff_str , diff , sizeof (cached_write_diff_str ));
8695
8796 cached_utilisation_diff = 0.0 ;
@@ -152,6 +161,52 @@ static void DiskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out)
152161 RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], "iB/s" );
153162}
154163
164+ static void DiskIORateMeter_updateValues (Meter * this ) {
165+ DiskIOUpdateCache (this -> host );
166+
167+ this -> values [0 ] = cached_read_diff ;
168+ this -> values [1 ] = cached_write_diff ;
169+
170+ if (status == RATESTATUS_NODATA ) {
171+ xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "no data" );
172+ return ;
173+ }
174+ if (status == RATESTATUS_INIT ) {
175+ xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "init" );
176+ return ;
177+ }
178+ if (status == RATESTATUS_STALE ) {
179+ xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "stale" );
180+ return ;
181+ }
182+
183+ xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "r:%siB/s w:%siB/s" , cached_read_diff_str , cached_write_diff_str );
184+ }
185+
186+ static void DiskIORateMeter_display (ATTR_UNUSED const Object * cast , RichString * out ) {
187+ switch (status ) {
188+ case RATESTATUS_NODATA :
189+ RichString_writeAscii (out , CRT_colors [METER_VALUE_ERROR ], "no data" );
190+ return ;
191+ case RATESTATUS_INIT :
192+ RichString_writeAscii (out , CRT_colors [METER_VALUE ], "initializing..." );
193+ return ;
194+ case RATESTATUS_STALE :
195+ RichString_writeAscii (out , CRT_colors [METER_VALUE_WARN ], "stale data" );
196+ return ;
197+ case RATESTATUS_DATA :
198+ break ;
199+ }
200+
201+ RichString_appendAscii (out , CRT_colors [METER_TEXT ], "read: " );
202+ RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], cached_read_diff_str );
203+ RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], "iB/s" );
204+
205+ RichString_appendAscii (out , CRT_colors [METER_TEXT ], " write: " );
206+ RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], cached_write_diff_str );
207+ RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], "iB/s" );
208+ }
209+
155210const MeterClass DiskIOMeter_class = {
156211 .super = {
157212 .extends = Class (Meter ),
@@ -169,3 +224,21 @@ const MeterClass DiskIOMeter_class = {
169224 .uiName = "Disk IO" ,
170225 .caption = "Disk IO: "
171226};
227+
228+ const MeterClass DiskIORateMeter_class = {
229+ .super = {
230+ .extends = Class (Meter ),
231+ .delete = Meter_delete ,
232+ .display = DiskIORateMeter_display
233+ },
234+ .updateValues = DiskIORateMeter_updateValues ,
235+ .defaultMode = TEXT_METERMODE ,
236+ .supportedModes = METERMODE_DEFAULT_SUPPORTED ,
237+ .maxItems = 2 ,
238+ .isPercentChart = false,
239+ .total = 1.0 ,
240+ .attributes = DiskIORateMeter_attributes ,
241+ .name = "DiskIORate" ,
242+ .uiName = "Disk IO Rate" ,
243+ .caption = "Dsk: "
244+ };
0 commit comments