@@ -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 ];
@@ -221,56 +220,88 @@ static void DiskIOTimeMeter_display(ATTR_UNUSED const Object* cast, RichString*
221220 }
222221}
223222
224- static void DiskIOMeter_updateValues (Meter * this ) {
225- DiskIOUpdateCache (this -> host );
226-
227- this -> values [0 ] = cached_utilisation_norm ;
223+ static void DiskIOMeter_display (const Object * cast , RichString * out ) {
224+ DiskIORateMeter_display (cast , out );
228225
229226 switch (status ) {
230227 case RATESTATUS_NODATA :
231- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "no data" );
232- return ;
233228 case RATESTATUS_INIT :
234- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "init" );
235- return ;
236229 case RATESTATUS_STALE :
237- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "stale" );
238230 return ;
239231 case RATESTATUS_DATA :
240232 break ;
241233 }
242234
243- xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "r:%siB/s w:%siB/s %.1f%%" , cached_read_diff_str , cached_write_diff_str , cached_utilisation_diff );
235+ RichString_appendAscii (out , CRT_colors [METER_TEXT ], "; " );
236+ DiskIOTimeMeter_display (cast , out );
244237}
245238
246- static void DiskIOMeter_display (ATTR_UNUSED const Object * cast , RichString * out ) {
247- switch (status ) {
248- case RATESTATUS_NODATA :
249- RichString_writeAscii (out , CRT_colors [METER_VALUE_ERROR ], "no data" );
250- return ;
251- case RATESTATUS_INIT :
252- RichString_writeAscii (out , CRT_colors [METER_VALUE ], "initializing..." );
253- return ;
254- case RATESTATUS_STALE :
255- RichString_writeAscii (out , CRT_colors [METER_VALUE_WARN ], "stale data" );
256- return ;
257- case RATESTATUS_DATA :
258- break ;
239+ static void DiskIOMeter_updateValues (Meter * this ) {
240+ DiskIOMeterData * data = this -> meterData ;
241+
242+ Meter_updateValues (data -> diskIORateMeter );
243+ Meter_updateValues (data -> diskIOTimeMeter );
244+ }
245+
246+ static void DiskIOMeter_draw (Meter * this , int x , int y , int w ) {
247+ DiskIOMeterData * data = this -> meterData ;
248+
249+ assert (data -> diskIORateMeter -> draw );
250+ assert (data -> diskIOTimeMeter -> draw );
251+
252+ switch (this -> mode ) {
253+ case TEXT_METERMODE :
254+ case LED_METERMODE :
255+ data -> diskIORateMeter -> draw (this , x , y , w );
256+ return ;
259257 }
260258
261- char buffer [16 ];
259+ /* Use the same width for each sub meter to align with CPU meter */
260+ const int colwidth = w / 2 ;
261+ const int diff = w % 2 ;
262262
263- int color = cached_utilisation_diff > 40.0 ? METER_VALUE_NOTICE : METER_VALUE ;
264- int len = xSnprintf ( buffer , sizeof ( buffer ), "%.1f%%" , cached_utilisation_diff );
265- RichString_appendnAscii ( out , CRT_colors [ color ], buffer , len );
263+ data -> diskIORateMeter -> draw ( data -> diskIORateMeter , x , y , colwidth ) ;
264+ data -> diskIOTimeMeter -> draw ( data -> diskIOTimeMeter , x + colwidth + diff , y , colwidth );
265+ }
266266
267- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " read: " );
268- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], cached_read_diff_str );
269- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], "iB/s" );
267+ static void DiskIOMeter_init (Meter * this ) {
268+ if (!this -> meterData ) {
269+ this -> meterData = xCalloc (1 , sizeof (DiskIOMeterData ));
270+ }
270271
271- RichString_appendAscii (out , CRT_colors [METER_TEXT ], " write: " );
272- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], cached_write_diff_str );
273- RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], "iB/s" );
272+ DiskIOMeterData * data = this -> meterData ;
273+
274+ if (!data -> diskIORateMeter )
275+ data -> diskIORateMeter = Meter_new (this -> host , 0 , (const MeterClass * ) Class (DiskIORateMeter ));
276+ if (!data -> diskIOTimeMeter )
277+ data -> diskIOTimeMeter = Meter_new (this -> host , 0 , (const MeterClass * ) Class (DiskIOTimeMeter ));
278+
279+ if (Meter_initFn (data -> diskIORateMeter )) {
280+ Meter_init (data -> diskIORateMeter );
281+ }
282+ if (Meter_initFn (data -> diskIOTimeMeter )) {
283+ Meter_init (data -> diskIOTimeMeter );
284+ }
285+ }
286+
287+ static void DiskIOMeter_updateMode (Meter * this , MeterModeId mode ) {
288+ DiskIOMeterData * data = this -> meterData ;
289+
290+ this -> mode = mode ;
291+
292+ Meter_setMode (data -> diskIORateMeter , mode );
293+ Meter_setMode (data -> diskIOTimeMeter , mode );
294+
295+ this -> h = MAXIMUM (data -> diskIORateMeter -> h , data -> diskIOTimeMeter -> h );
296+ }
297+
298+ static void DiskIOMeter_done (Meter * this ) {
299+ DiskIOMeterData * data = this -> meterData ;
300+
301+ Meter_delete ((Object * )data -> diskIORateMeter );
302+ Meter_delete ((Object * )data -> diskIOTimeMeter );
303+
304+ free (data );
274305}
275306
276307const MeterClass DiskIORateMeter_class = {
@@ -320,11 +351,13 @@ const MeterClass DiskIOMeter_class = {
320351 .updateValues = DiskIOMeter_updateValues ,
321352 .defaultMode = TEXT_METERMODE ,
322353 .supportedModes = METERMODE_DEFAULT_SUPPORTED ,
323- .maxItems = 1 ,
324- .isPercentChart = true,
325- .total = 1.0 ,
326- .attributes = DiskIOMeter_attributes ,
354+ .isMultiColumn = true,
327355 .name = "DiskIO" ,
328356 .uiName = "Disk IO" ,
329- .caption = "Disk IO: "
357+ .description = "Disk IO rate & time combined display" ,
358+ .caption = "Dsk: " ,
359+ .draw = DiskIOMeter_draw ,
360+ .init = DiskIOMeter_init ,
361+ .updateMode = DiskIOMeter_updateMode ,
362+ .done = DiskIOMeter_done
330363};
0 commit comments