Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/procps/nmeter.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/procps/nmeter.c
r2725 r3232 6 6 * Contact me: vda.linux@googlemail.com 7 7 */ 8 9 //config:config NMETER 10 //config: bool "nmeter" 11 //config: default y 12 //config: help 13 //config: Prints selected system stats continuously, one line per update. 14 15 //applet:IF_NMETER(APPLET(nmeter, BB_DIR_USR_BIN, BB_SUID_DROP)) 16 17 //kbuild:lib-$(CONFIG_NMETER) += nmeter.o 18 19 //usage:#define nmeter_trivial_usage 20 //usage: "[-d MSEC] FORMAT_STRING" 21 //usage:#define nmeter_full_usage "\n\n" 22 //usage: "Monitor system in real time" 23 //usage: "\n" 24 //usage: "\n -d MSEC Milliseconds between updates (default:1000)" 25 //usage: "\n" 26 //usage: "\nFormat specifiers:" 27 //usage: "\n %Nc or %[cN] CPU. N - bar size (default:10)" 28 //usage: "\n (displays: S:system U:user N:niced D:iowait I:irq i:softirq)" 29 //usage: "\n %[nINTERFACE] Network INTERFACE" 30 //usage: "\n %m Allocated memory" 31 //usage: "\n %[mf] Free memory" 32 //usage: "\n %[mt] Total memory" 33 //usage: "\n %s Allocated swap" 34 //usage: "\n %f Number of used file descriptors" 35 //usage: "\n %Ni Total/specific IRQ rate" 36 //usage: "\n %x Context switch rate" 37 //usage: "\n %p Forks" 38 //usage: "\n %[pn] # of processes" 39 //usage: "\n %b Block io" 40 //usage: "\n %Nt Time (with N decimal points)" 41 //usage: "\n %r Print <cr> instead of <lf> at EOL" 8 42 9 43 //TODO: … … 238 272 239 273 // Parses /proc/diskstats 240 // 1 2 3 4 56(rd) 7 8 9 10(wr) 11 12 13 14274 // 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14 241 275 // 3 0 hda 51292 14441 841783 926052 25717 79650 843256 3029804 0 148459 3956933 242 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. 243 279 static int rdval_diskstats(const char* p, ullong *vec) 244 280 { 245 ullong rd = rd; // for compiler 246 int indexline = 0; 281 char devname[32]; 282 unsigned devname_len = 0; 283 int value_idx = 0; 284 247 285 vec[0] = 0; 248 286 vec[1] = 0; 249 287 while (1) { 250 indexline++; 251 while (*p == ' ' || *p == '\t') p++; 252 if (*p == '\0') break; 288 value_idx++; 289 while (*p == ' ' || *p == '\t') 290 p++; 291 if (*p == '\0') 292 break; 253 293 if (*p == '\n') { 254 indexline= 0;294 value_idx = 0; 255 295 p++; 256 296 continue; 257 297 } 258 if (indexline == 6) { 259 rd = strtoull(p, NULL, 10); 260 } else if (indexline == 10) { 261 vec[0] += rd; // TODO: *sectorsize (don't know how to find out sectorsize) 298 if (value_idx == 3) { 299 char *end = strchrnul(p, ' '); 300 /* If this a hda1-like device (same prefix as last one + digit)? */ 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) 262 319 vec[1] += strtoull(p, NULL, 10); 263 while (*p != '\n' && *p != '\0') p++; 320 skip_line: 321 while (*p != '\n' && *p != '\0') 322 p++; 264 323 continue; 265 324 } 266 while (*p > ' ') p++; // skip over value 325 while ((unsigned char)(*p) > ' ') // skip over value 326 p++; 267 327 } 268 328 return 0; … … 770 830 typedef s_stat* init_func(const char *param); 771 831 832 // Deprecated %NNNd is to be removed, -d MSEC supersedes it 772 833 static const char options[] ALIGN1 = "ncmsfixptbdr"; 773 834 static init_func *const init_functions[] = { … … 793 854 s_stat *last = NULL; 794 855 s_stat *s; 856 char *opt_d; 795 857 char *cur, *prev; 796 858 … … 798 860 799 861 xchdir("/proc"); 800 801 if (!argv[1])802 bb_show_usage();803 862 804 863 if (open_read_close("version", buf, sizeof(buf)-1) > 0) { … … 807 866 } 808 867 809 // Can use argv[1] directly, but this will mess up 868 if (getopt32(argv, "d:", &opt_d)) 869 init_delay(opt_d); 870 argv += optind; 871 872 if (!argv[0]) 873 bb_show_usage(); 874 875 // Can use argv[0] directly, but this will mess up 810 876 // parameters as seen by e.g. ps. Making a copy... 811 cur = xstrdup(argv[ 1]);877 cur = xstrdup(argv[0]); 812 878 while (1) { 813 879 char *param, *p;
Note:
See TracChangeset
for help on using the changeset viewer.