Skip to content

Commit 537ea07

Browse files
committed
Introduce DiskIORateMeter, split from DiskIOMeter
1 parent e768a97 commit 537ea07

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

DiskIOMeter.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3035
static MeterRateStatus status = RATESTATUS_INIT;
36+
static double cached_read_diff;
3137
static char cached_read_diff_str[6];
38+
static double cached_write_diff;
3239
static char cached_write_diff_str[6];
3340
static double cached_utilisation_diff;
3441
static 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+
155210
const 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+
};

DiskIOMeter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ typedef struct DiskIOData_ {
2121

2222
extern const MeterClass DiskIOMeter_class;
2323

24+
extern const MeterClass DiskIORateMeter_class;
25+
2426
#endif /* HEADER_DiskIOMeter */

darwin/Platform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const MeterClass* const Platform_meterTypes[] = {
144144
&ZfsArcMeter_class,
145145
&ZfsCompressedArcMeter_class,
146146
&DiskIOMeter_class,
147+
&DiskIORateMeter_class,
147148
&NetworkIOMeter_class,
148149
&FileDescriptorMeter_class,
149150
&GPUMeter_class,

dragonflybsd/Platform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const MeterClass* const Platform_meterTypes[] = {
121121
&LeftCPUs8Meter_class,
122122
&RightCPUs8Meter_class,
123123
&DiskIOMeter_class,
124+
&DiskIORateMeter_class,
124125
&NetworkIOMeter_class,
125126
&FileDescriptorMeter_class,
126127
&BlankMeter_class,

freebsd/Platform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const MeterClass* const Platform_meterTypes[] = {
131131
&ZfsArcMeter_class,
132132
&ZfsCompressedArcMeter_class,
133133
&DiskIOMeter_class,
134+
&DiskIORateMeter_class,
134135
&FileDescriptorMeter_class,
135136
&NetworkIOMeter_class,
136137
NULL

linux/Platform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ const MeterClass* const Platform_meterTypes[] = {
248248
&ZfsCompressedArcMeter_class,
249249
&ZramMeter_class,
250250
&DiskIOMeter_class,
251+
&DiskIORateMeter_class,
251252
&NetworkIOMeter_class,
252253
&SELinuxMeter_class,
253254
&SystemdMeter_class,

netbsd/Platform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const MeterClass* const Platform_meterTypes[] = {
181181
&RightCPUs8Meter_class,
182182
&BlankMeter_class,
183183
&DiskIOMeter_class,
184+
&DiskIORateMeter_class,
184185
&NetworkIOMeter_class,
185186
&FileDescriptorMeter_class,
186187
NULL

pcp/Platform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const MeterClass* const Platform_meterTypes[] = {
115115
&ZfsCompressedArcMeter_class,
116116
&ZramMeter_class,
117117
&DiskIOMeter_class,
118+
&DiskIORateMeter_class,
118119
&NetworkIOMeter_class,
119120
&SysArchMeter_class,
120121
&FileDescriptorMeter_class,

0 commit comments

Comments
 (0)