aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-11-01 23:34:46 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-11-01 23:34:46 +0100
commit3b1603410a29046e5dcabe1bdfc2dc109461111d (patch)
tree47b3d3ef695903084804096427ef2a15fbf1f023
parentf8a5b792ba3cb0d11531902a04600fc274dff69e (diff)
downloadbusybox-w32-3b1603410a29046e5dcabe1bdfc2dc109461111d.tar.gz
busybox-w32-3b1603410a29046e5dcabe1bdfc2dc109461111d.tar.bz2
busybox-w32-3b1603410a29046e5dcabe1bdfc2dc109461111d.zip
nmeter: fix block i/o count on newer Linux kernels
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/nmeter.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/procps/nmeter.c b/procps/nmeter.c
index 999955982..ed5479024 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -274,30 +274,56 @@ static int rdval_loadavg(const char* p, ullong *vec, ...)
274// 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14 274// 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14
275// 3 0 hda 51292 14441 841783 926052 25717 79650 843256 3029804 0 148459 3956933 275// 3 0 hda 51292 14441 841783 926052 25717 79650 843256 3029804 0 148459 3956933
276// 3 1 hda1 0 0 0 0 <- ignore if only 4 fields 276// 3 1 hda1 0 0 0 0 <- ignore if only 4 fields
277// Linux 3.0 (maybe earlier) started printing full stats for hda1 too.
278// Had to add code which skips such devices.
277static int rdval_diskstats(const char* p, ullong *vec) 279static int rdval_diskstats(const char* p, ullong *vec)
278{ 280{
279 ullong rd = rd; // for compiler 281 char devname[32];
280 int indexline = 0; 282 unsigned devname_len = 0;
283 int value_idx = 0;
284
281 vec[0] = 0; 285 vec[0] = 0;
282 vec[1] = 0; 286 vec[1] = 0;
283 while (1) { 287 while (1) {
284 indexline++; 288 value_idx++;
285 while (*p == ' ' || *p == '\t') p++; 289 while (*p == ' ' || *p == '\t')
286 if (*p == '\0') break; 290 p++;
291 if (*p == '\0')
292 break;
287 if (*p == '\n') { 293 if (*p == '\n') {
288 indexline = 0; 294 value_idx = 0;
289 p++; 295 p++;
290 continue; 296 continue;
291 } 297 }
292 if (indexline == 6) { 298 if (value_idx == 3) {
293 rd = strtoull(p, NULL, 10); 299 char *end = strchrnul(p, ' ');
294 } else if (indexline == 10) { 300 /* If this a hda1-like device (same prefix as last one + digit)? */
295 vec[0] += rd; // TODO: *sectorsize (don't know how to find out sectorsize) 301 if (devname_len && strncmp(devname, p, devname_len) == 0 && isdigit(p[devname_len])) {
302 p = end;
303 goto skip_line; /* skip entire line */
304 }
305 /* It is not. Remember the name for future checks */
306 devname_len = end - p;
307 if (devname_len > sizeof(devname)-1)
308 devname_len = sizeof(devname)-1;
309 strncpy(devname, p, devname_len);
310 /* devname[devname_len] = '\0'; - not really needed */
311 p = end;
312 } else
313 if (value_idx == 6) {
314 // TODO: *sectorsize (don't know how to find out sectorsize)
315 vec[0] += strtoull(p, NULL, 10);
316 } else
317 if (value_idx == 10) {
318 // TODO: *sectorsize (don't know how to find out sectorsize)
296 vec[1] += strtoull(p, NULL, 10); 319 vec[1] += strtoull(p, NULL, 10);
297 while (*p != '\n' && *p != '\0') p++; 320 skip_line:
321 while (*p != '\n' && *p != '\0')
322 p++;
298 continue; 323 continue;
299 } 324 }
300 while (*p > ' ') p++; // skip over value 325 while ((unsigned char)(*p) > ' ') // skip over value
326 p++;
301 } 327 }
302 return 0; 328 return 0;
303} 329}