@@ -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 ];
@@ -219,56 +218,88 @@ static void DiskIOTimeMeter_display(ATTR_UNUSED const Object* cast, RichString*
219218 }
220219}
221220
222- static void DiskIOMeter_updateValues (Meter * this ) {
223- DiskIOUpdateCache (this -> host );
224-
225- this -> values [0 ] = cached_utilisation_norm ;
221+ static void DiskIOMeter_display (const Object * cast , RichString * out ) {
222+ DiskIORateMeter_display (cast , out );
226223
227224 switch (status ) {
228225 case RATESTATUS_NODATA :
229- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "no data" );
230- return ;
231226 case RATESTATUS_INIT :
232- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "init" );
233- return ;
234227 case RATESTATUS_STALE :
235- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "stale" );
236228 return ;
237229 case RATESTATUS_DATA :
238230 break ;
239231 }
240232
241- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "r:%siB/s w:%siB/s %.1f%%" , cached_read_diff_str , cached_write_diff_str , cached_utilisation_diff );
233+ RichString_appendAscii (out , CRT_colors [METER_TEXT ], "; " );
234+ DiskIOTimeMeter_display (cast , out );
242235}
243236
244- static void DiskIOMeter_display (ATTR_UNUSED const Object * cast , RichString * out ) {
245- switch (status ) {
246- case RATESTATUS_NODATA :
247- RichString_writeAscii (out , CRT_colors [METER_VALUE_ERROR ], "no data" );
248- return ;
249- case RATESTATUS_INIT :
250- RichString_writeAscii (out , CRT_colors [METER_VALUE ], "initializing..." );
251- return ;
252- case RATESTATUS_STALE :
253- RichString_writeAscii (out , CRT_colors [METER_VALUE_WARN ], "stale data" );
254- return ;
255- case RATESTATUS_DATA :
256- break ;
237+ static void DiskIOMeter_updateValues (Meter * this ) {
238+ DiskIOMeterData * data = this -> meterData ;
239+
240+ Meter_updateValues (data -> diskIORateMeter );
241+ Meter_updateValues (data -> diskIOTimeMeter );
242+ }
243+
244+ static void DiskIOMeter_draw (Meter * this , int x , int y , int w ) {
245+ DiskIOMeterData * data = this -> meterData ;
246+
247+ assert (data -> diskIORateMeter -> draw );
248+ assert (data -> diskIOTimeMeter -> draw );
249+
250+ switch (this -> mode ) {
251+ case TEXT_METERMODE :
252+ case LED_METERMODE :
253+ data -> diskIORateMeter -> draw (this , x , y , w );
254+ return ;
257255 }
258256
259- char buffer [16 ];
257+ /* Use the same width for each sub meter to align with CPU meter */
258+ const int colwidth = w / 2 ;
259+ const int diff = w % 2 ;
260260
261- int color = cached_utilisation_diff > 40.0 ? METER_VALUE_NOTICE : METER_VALUE ;
262- int len = xSnprintf ( buffer , sizeof ( buffer ), "%.1f%%" , cached_utilisation_diff );
263- RichString_appendnAscii ( out , CRT_colors [ color ], buffer , len );
261+ data -> diskIORateMeter -> draw ( data -> diskIORateMeter , x , y , colwidth ) ;
262+ data -> diskIOTimeMeter -> draw ( data -> diskIOTimeMeter , x + colwidth + diff , y , colwidth );
263+ }
264264
265- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " read: " );
266- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], cached_read_diff_str );
267- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], "iB/s" );
265+ static void DiskIOMeter_init (Meter * this ) {
266+ if (!this -> meterData ) {
267+ this -> meterData = xCalloc (1 , sizeof (DiskIOMeterData ));
268+ }
268269
269- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " write: " );
270- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], cached_write_diff_str );
271- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], "iB/s" );
270+ DiskIOMeterData * data = this -> meterData ;
271+
272+ if (!data -> diskIORateMeter )
273+ data -> diskIORateMeter = Meter_new (this -> host , 0 , (const MeterClass * ) Class (DiskIORateMeter ));
274+ if (!data -> diskIOTimeMeter )
275+ data -> diskIOTimeMeter = Meter_new (this -> host , 0 , (const MeterClass * ) Class (DiskIOTimeMeter ));
276+
277+ if (Meter_initFn (data -> diskIORateMeter )) {
278+ Meter_init (data -> diskIORateMeter );
279+ }
280+ if (Meter_initFn (data -> diskIOTimeMeter )) {
281+ Meter_init (data -> diskIOTimeMeter );
282+ }
283+ }
284+
285+ static void DiskIOMeter_updateMode (Meter * this , MeterModeId mode ) {
286+ DiskIOMeterData * data = this -> meterData ;
287+
288+ this -> mode = mode ;
289+
290+ Meter_setMode (data -> diskIORateMeter , mode );
291+ Meter_setMode (data -> diskIOTimeMeter , mode );
292+
293+ this -> h = MAXIMUM (data -> diskIORateMeter -> h , data -> diskIOTimeMeter -> h );
294+ }
295+
296+ static void DiskIOMeter_done (Meter * this ) {
297+ DiskIOMeterData * data = this -> meterData ;
298+
299+ Meter_delete ((Object * )data -> diskIORateMeter );
300+ Meter_delete ((Object * )data -> diskIOTimeMeter );
301+
302+ free (data );
272303}
273304
274305const MeterClass DiskIORateMeter_class = {
@@ -318,11 +349,13 @@ const MeterClass DiskIOMeter_class = {
318349 .updateValues = DiskIOMeter_updateValues ,
319350 .defaultMode = TEXT_METERMODE ,
320351 .supportedModes = METERMODE_DEFAULT_SUPPORTED ,
321- .maxItems = 1 ,
322- .isPercentChart = true,
323- .total = 1.0 ,
324- .attributes = DiskIOMeter_attributes ,
352+ .isMultiColumn = true,
325353 .name = "DiskIO" ,
326354 .uiName = "Disk IO" ,
327- .caption = "Disk IO: "
355+ .description = "Disk IO rate & time combined display" ,
356+ .caption = "Dsk: " ,
357+ .draw = DiskIOMeter_draw ,
358+ .init = DiskIOMeter_init ,
359+ .updateMode = DiskIOMeter_updateMode ,
360+ .done = DiskIOMeter_done
328361};
0 commit comments