@@ -21,6 +21,11 @@ in the source distribution for its full text.
2121#include "XUtils.h"
2222
2323
24+ typedef struct DiskIOMeterData_ {
25+ Meter * diskIORateMeter ;
26+ Meter * diskIOTimeMeter ;
27+ } DiskIOMeterData ;
28+
2429static const int DiskIORateMeter_attributes [] = {
2530 METER_VALUE_IOREAD ,
2631 METER_VALUE_IOWRITE ,
@@ -30,12 +35,6 @@ static const int DiskIOTimeMeter_attributes[] = {
3035 METER_VALUE_NOTICE ,
3136};
3237
33- static const int DiskIOMeter_attributes [] = {
34- METER_VALUE_NOTICE ,
35- METER_VALUE_IOREAD ,
36- METER_VALUE_IOWRITE ,
37- };
38-
3938static MeterRateStatus status = RATESTATUS_INIT ;
4039static double cached_read_diff ;
4140static char cached_read_diff_str [6 ];
@@ -206,55 +205,63 @@ static void DiskIOTimeMeter_display(ATTR_UNUSED const Object* cast, RichString*
206205}
207206
208207static void DiskIOMeter_updateValues (Meter * this ) {
209- DiskIOUpdateCache ( this -> host ) ;
208+ DiskIOMeterData * data = this -> meterData ;
210209
211- this -> values [0 ] = cached_utilisation_norm ;
210+ Meter_updateValues (data -> diskIORateMeter );
211+ Meter_updateValues (data -> diskIOTimeMeter );
212+ }
212213
213- switch (status ) {
214- case RATESTATUS_NODATA :
215- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "no data" );
216- return ;
217- case RATESTATUS_INIT :
218- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "init" );
219- return ;
220- case RATESTATUS_STALE :
221- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "stale" );
222- return ;
223- case RATESTATUS_DATA :
224- break ;
225- }
214+ static void DiskIOMeter_draw (Meter * this , int x , int y , int w ) {
215+ DiskIOMeterData * data = this -> meterData ;
226216
227- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "r:%siB/s w:%siB/s %.1f%%" , cached_read_diff_str , cached_write_diff_str , cached_utilisation_diff );
217+ /* Use the same width for each sub meter to align with CPU meter */
218+ const int colwidth = w / 2 ;
219+ const int diff = w % 2 ;
220+
221+ assert (data -> diskIORateMeter -> draw );
222+ data -> diskIORateMeter -> draw (data -> diskIORateMeter , x , y , colwidth );
223+ assert (data -> diskIOTimeMeter -> draw );
224+ data -> diskIOTimeMeter -> draw (data -> diskIOTimeMeter , x + colwidth + diff , y , colwidth );
228225}
229226
230- static void DiskIOMeter_display (ATTR_UNUSED const Object * cast , RichString * out ) {
231- switch (status ) {
232- case RATESTATUS_NODATA :
233- RichString_writeAscii (out , CRT_colors [METER_VALUE_ERROR ], "no data" );
234- return ;
235- case RATESTATUS_INIT :
236- RichString_writeAscii (out , CRT_colors [METER_VALUE ], "initializing..." );
237- return ;
238- case RATESTATUS_STALE :
239- RichString_writeAscii (out , CRT_colors [METER_VALUE_WARN ], "stale data" );
240- return ;
241- case RATESTATUS_DATA :
242- break ;
227+ static void DiskIOMeter_init (Meter * this ) {
228+ if (!this -> meterData ) {
229+ this -> meterData = xCalloc (1 , sizeof (DiskIOMeterData ));
243230 }
244231
245- char buffer [ 16 ] ;
232+ DiskIOMeterData * data = this -> meterData ;
246233
247- int color = cached_utilisation_diff > 40.0 ? METER_VALUE_NOTICE : METER_VALUE ;
248- int len = xSnprintf (buffer , sizeof (buffer ), "%.1f%%" , cached_utilisation_diff );
249- RichString_appendnAscii (out , CRT_colors [color ], buffer , len );
234+ if (!data -> diskIORateMeter )
235+ data -> diskIORateMeter = Meter_new (this -> host , 0 , (const MeterClass * ) Class (DiskIORateMeter ));
236+ if (!data -> diskIOTimeMeter )
237+ data -> diskIOTimeMeter = Meter_new (this -> host , 0 , (const MeterClass * ) Class (DiskIOTimeMeter ));
250238
251- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " read: " );
252- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], cached_read_diff_str );
253- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], "iB/s" );
239+ if (Meter_initFn (data -> diskIORateMeter )) {
240+ Meter_init (data -> diskIORateMeter );
241+ }
242+ if (Meter_initFn (data -> diskIOTimeMeter )) {
243+ Meter_init (data -> diskIOTimeMeter );
244+ }
245+ }
254246
255- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " write: " );
256- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], cached_write_diff_str );
257- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], "iB/s" );
247+ static void DiskIOMeter_updateMode (Meter * this , MeterModeId mode ) {
248+ DiskIOMeterData * data = this -> meterData ;
249+
250+ this -> mode = mode ;
251+
252+ Meter_setMode (data -> diskIORateMeter , mode );
253+ Meter_setMode (data -> diskIOTimeMeter , mode );
254+
255+ this -> h = MAXIMUM (data -> diskIORateMeter -> h , data -> diskIOTimeMeter -> h );
256+ }
257+
258+ static void DiskIOMeter_done (Meter * this ) {
259+ DiskIOMeterData * data = this -> meterData ;
260+
261+ Meter_delete ((Object * )data -> diskIORateMeter );
262+ Meter_delete ((Object * )data -> diskIOTimeMeter );
263+
264+ free (data );
258265}
259266
260267const MeterClass DiskIORateMeter_class = {
@@ -299,16 +306,17 @@ const MeterClass DiskIOMeter_class = {
299306 .super = {
300307 .extends = Class (Meter ),
301308 .delete = Meter_delete ,
302- .display = DiskIOMeter_display
303309 },
304310 .updateValues = DiskIOMeter_updateValues ,
305311 .defaultMode = TEXT_METERMODE ,
306312 .supportedModes = METERMODE_DEFAULT_SUPPORTED ,
307- .maxItems = 1 ,
308- .isPercentChart = true,
309- .total = 1.0 ,
310- .attributes = DiskIOMeter_attributes ,
313+ .isMultiColumn = true,
311314 .name = "DiskIO" ,
312315 .uiName = "Disk IO" ,
313- .caption = "Disk IO: "
316+ .description = "Disk IO rate & time combined display" ,
317+ .caption = "Dsk: " ,
318+ .draw = DiskIOMeter_draw ,
319+ .init = DiskIOMeter_init ,
320+ .updateMode = DiskIOMeter_updateMode ,
321+ .done = DiskIOMeter_done
314322};
0 commit comments