@@ -21,10 +21,13 @@ in the source distribution for its full text.
2121#include  "XUtils.h" 
2222
2323
24- static  const  int  DiskIOMeter_attributes [] =  {
25-    METER_VALUE_NOTICE ,
26-    METER_VALUE_IOREAD ,
27-    METER_VALUE_IOWRITE ,
24+ typedef  struct  DiskIOMeterData_  {
25+    Meter *  diskIOTimeMeter ;
26+    Meter *  diskIORateMeter ;
27+ } DiskIOMeterData ;
28+ 
29+ static  const  int  DiskIOTimeMeter_attributes [] =  {
30+    METER_VALUE_NOTICE 
2831};
2932
3033static  const  int  DiskIORateMeter_attributes [] =  {
@@ -110,7 +113,7 @@ static void DiskIOUpdateCache(const Machine* host) {
110113   cached_msTimeSpend_total  =  data .totalMsTimeSpend ;
111114}
112115
113- static  void  DiskIOMeter_updateValues (Meter *  this ) {
116+ static  void  DiskIOTimeMeter_updateValues (Meter *  this ) {
114117   DiskIOUpdateCache (this -> host );
115118
116119   this -> values [0 ] =  cached_utilisation_norm ;
@@ -128,10 +131,10 @@ static void DiskIOMeter_updateValues(Meter* this) {
128131      return ;
129132   }
130133
131-    xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "r:%siB/s w:%siB/s % .1f%%" ,  cached_read_diff_str ,  cached_write_diff_str , cached_utilisation_diff );
134+    xSnprintf (this -> txtBuffer , sizeof (this -> txtBuffer ), "% .1f%%" , cached_utilisation_diff );
132135}
133136
134- static  void  DiskIOMeter_display (ATTR_UNUSED  const  Object *  cast , RichString *  out ) {
137+ static  void  DiskIOTimeMeter_display (ATTR_UNUSED  const  Object *  cast , RichString *  out ) {
135138   switch  (status ) {
136139      case  RATESTATUS_NODATA :
137140         RichString_writeAscii (out , CRT_colors [METER_VALUE_ERROR ], "no data" );
@@ -151,14 +154,6 @@ static void DiskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out)
151154   int  color  =  cached_utilisation_diff  >  40.0  ? METER_VALUE_NOTICE  : METER_VALUE ;
152155   int  len  =  xSnprintf (buffer , sizeof (buffer ), "%.1f%%" , cached_utilisation_diff );
153156   RichString_appendnAscii (out , CRT_colors [color ], buffer , len );
154- 
155-    RichString_appendAscii (out , CRT_colors [METER_TEXT ], " read: " );
156-    RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], cached_read_diff_str );
157-    RichString_appendAscii (out , CRT_colors [METER_VALUE_IOREAD ], "iB/s" );
158- 
159-    RichString_appendAscii (out , CRT_colors [METER_TEXT ], " write: " );
160-    RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], cached_write_diff_str );
161-    RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], "iB/s" );
162157}
163158
164159static  void  DiskIORateMeter_updateValues (Meter *  this ) {
@@ -207,22 +202,82 @@ static void DiskIORateMeter_display(ATTR_UNUSED const Object* cast, RichString*
207202   RichString_appendAscii (out , CRT_colors [METER_VALUE_IOWRITE ], "iB/s" );
208203}
209204
210- const  MeterClass  DiskIOMeter_class  =  {
205+ static  void  DiskIOMeter_updateValues (Meter *  this ) {
206+    DiskIOMeterData *  data  =  this -> meterData ;
207+ 
208+    Meter_updateValues (data -> diskIOTimeMeter );
209+    Meter_updateValues (data -> diskIORateMeter );
210+ }
211+ 
212+ static  void  DiskIOMeter_draw (Meter *  this , int  x , int  y , int  w ) {
213+    DiskIOMeterData *  data  =  this -> meterData ;
214+ 
215+    /* Use the same width for each sub meter to align with CPU meter */ 
216+    const  int  colwidth  =  w  / 2 ;
217+    const  int  diff  =  w  % 2 ;
218+ 
219+    assert (data -> diskIOTimeMeter -> draw );
220+    data -> diskIOTimeMeter -> draw (data -> diskIOTimeMeter , x , y , colwidth );
221+    assert (data -> diskIORateMeter -> draw );
222+    data -> diskIORateMeter -> draw (data -> diskIORateMeter , x  +  colwidth  +  diff , y , colwidth );
223+ }
224+ 
225+ static  void  DiskIOMeter_init (Meter *  this ) {
226+    DiskIOMeterData *  data  =  this -> meterData ;
227+ 
228+    if  (!data ) {
229+       data  =  this -> meterData  =  xCalloc (1 , sizeof (DiskIOMeterData ));
230+    }
231+ 
232+    if  (!data -> diskIOTimeMeter )
233+       data -> diskIOTimeMeter  =  Meter_new (this -> host , 0 , (const  MeterClass * ) Class (DiskIOTimeMeter ));
234+    if  (!data -> diskIORateMeter )
235+       data -> diskIORateMeter  =  Meter_new (this -> host , 0 , (const  MeterClass * ) Class (DiskIORateMeter ));
236+ 
237+    if  (Meter_initFn (data -> diskIOTimeMeter )) {
238+       Meter_init (data -> diskIOTimeMeter );
239+    }
240+    if  (Meter_initFn (data -> diskIORateMeter )) {
241+       Meter_init (data -> diskIORateMeter );
242+    }
243+ }
244+ 
245+ static  void  DiskIOMeter_updateMode (Meter *  this , MeterModeId  mode ) {
246+    DiskIOMeterData *  data  =  this -> meterData ;
247+ 
248+    this -> mode  =  mode ;
249+ 
250+    Meter_setMode (data -> diskIOTimeMeter , mode );
251+    Meter_setMode (data -> diskIORateMeter , mode );
252+ 
253+    this -> h  =  MAXIMUM (data -> diskIOTimeMeter -> h , data -> diskIORateMeter -> h );
254+ }
255+ 
256+ static  void  DiskIOMeter_done (Meter *  this ) {
257+    DiskIOMeterData *  data  =  this -> meterData ;
258+ 
259+    Meter_delete ((Object * )data -> diskIOTimeMeter );
260+    Meter_delete ((Object * )data -> diskIORateMeter );
261+ 
262+    free (data );
263+ }
264+ 
265+ const  MeterClass  DiskIOTimeMeter_class  =  {
211266   .super  =  {
212267      .extends  =  Class (Meter ),
213268      .delete  =  Meter_delete ,
214-       .display  =  DiskIOMeter_display 
269+       .display  =  DiskIOTimeMeter_display 
215270   },
216-    .updateValues  =  DiskIOMeter_updateValues ,
271+    .updateValues  =  DiskIOTimeMeter_updateValues ,
217272   .defaultMode  =  TEXT_METERMODE ,
218273   .supportedModes  =  METERMODE_DEFAULT_SUPPORTED ,
219274   .maxItems  =  1 ,
220275   .isPercentChart  =  true,
221276   .total  =  1.0 ,
222-    .attributes  =  DiskIOMeter_attributes ,
223-    .name  =  "DiskIO " ,
224-    .uiName  =  "Disk IO" ,
225-    .caption  =  "Disk IO : " 
277+    .attributes  =  DiskIOTimeMeter_attributes ,
278+    .name  =  "DiskIOTime " ,
279+    .uiName  =  "Disk IO Time " ,
280+    .caption  =  "Dsk : " 
226281};
227282
228283const  MeterClass  DiskIORateMeter_class  =  {
@@ -242,3 +297,22 @@ const MeterClass DiskIORateMeter_class = {
242297   .uiName  =  "Disk IO Rate" ,
243298   .caption  =  "Dsk: " 
244299};
300+ 
301+ const  MeterClass  DiskIOMeter_class  =  {
302+    .super  =  {
303+       .extends  =  Class (Meter ),
304+       .delete  =  Meter_delete ,
305+    },
306+    .updateValues  =  DiskIOMeter_updateValues ,
307+    .defaultMode  =  TEXT_METERMODE ,
308+    .supportedModes  =  METERMODE_DEFAULT_SUPPORTED ,
309+    .isMultiColumn  =  true,
310+    .name  =  "DiskIO" ,
311+    .uiName  =  "Disk IO" ,
312+    .description  =  "Disk IO time & rate combined display" ,
313+    .caption  =  "Dsk: " ,
314+    .draw  =  DiskIOMeter_draw ,
315+    .init  =  DiskIOMeter_init ,
316+    .updateMode  =  DiskIOMeter_updateMode ,
317+    .done  =  DiskIOMeter_done 
318+ };
0 commit comments