aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-28 23:30:37 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-28 23:30:37 +0000
commit333aa0c04a34cd35472dec5c2af70f23c4fa2a40 (patch)
tree7e39c9acadfb665c3004f7b5d26a523464467c6e
parent6ea75e2f5db42d102f3a8d2bf59f4d27a4d65863 (diff)
downloadbusybox-w32-333aa0c04a34cd35472dec5c2af70f23c4fa2a40.tar.gz
busybox-w32-333aa0c04a34cd35472dec5c2af70f23c4fa2a40.tar.bz2
busybox-w32-333aa0c04a34cd35472dec5c2af70f23c4fa2a40.zip
nmeter: code shrink
function old new delta init_delay 61 64 +3 init_cpu 86 82 -4 init_int 63 57 -6 nmeter_main 679 667 -12 init_if 88 63 -25 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/4 up/down: 3/-47) Total: -44 bytes
-rw-r--r--procps/nmeter.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/procps/nmeter.c b/procps/nmeter.c
index 798afcf16..888b827ea 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -281,14 +281,14 @@ static void collect_literal(s_stat *s ATTRIBUTE_UNUSED)
281 281
282static s_stat* init_literal(void) 282static s_stat* init_literal(void)
283{ 283{
284 s_stat *s = xmalloc(sizeof(s_stat)); 284 s_stat *s = xzalloc(sizeof(s_stat));
285 s->collect = collect_literal; 285 s->collect = collect_literal;
286 return (s_stat*)s; 286 return (s_stat*)s;
287} 287}
288 288
289static s_stat* init_delay(const char *param) 289static s_stat* init_delay(const char *param)
290{ 290{
291 delta = bb_strtoi(param, NULL, 0) * 1000; 291 delta = strtoul(param, NULL, 0) * 1000; /* param can be "" */
292 deltanz = delta > 0 ? delta : 1; 292 deltanz = delta > 0 ? delta : 1;
293 need_seconds = (1000000%deltanz) != 0; 293 need_seconds = (1000000%deltanz) != 0;
294 return NULL; 294 return NULL;
@@ -369,13 +369,13 @@ static void collect_cpu(cpu_stat *s)
369static s_stat* init_cpu(const char *param) 369static s_stat* init_cpu(const char *param)
370{ 370{
371 int sz; 371 int sz;
372 cpu_stat *s = xmalloc(sizeof(cpu_stat)); 372 cpu_stat *s = xzalloc(sizeof(*s));
373 s->collect = collect_cpu; 373 s->collect = collect_cpu;
374 sz = strtol(param, NULL, 0); 374 sz = strtoul(param, NULL, 0); /* param can be "" */
375 if (sz < 10) sz = 10; 375 if (sz < 10) sz = 10;
376 if (sz > 1000) sz = 1000; 376 if (sz > 1000) sz = 1000;
377 s->bar = xmalloc(sz+1); 377 s->bar = xzalloc(sz+1);
378 s->bar[sz] = '\0'; 378 /*s->bar[sz] = '\0'; - xzalloc did it */
379 s->bar_sz = sz; 379 s->bar_sz = sz;
380 return (s_stat*)s; 380 return (s_stat*)s;
381} 381}
@@ -404,13 +404,13 @@ static void collect_int(int_stat *s)
404 404
405static s_stat* init_int(const char *param) 405static s_stat* init_int(const char *param)
406{ 406{
407 int_stat *s = xmalloc(sizeof(int_stat)); 407 int_stat *s = xzalloc(sizeof(*s));
408 s->collect = collect_int; 408 s->collect = collect_int;
409 if (param[0]=='\0') { 409 if (param[0] == '\0') {
410 s->no = 1; 410 s->no = 1;
411 } else { 411 } else {
412 int n = strtoul(param, NULL, 0); 412 int n = xatoi_u(param);
413 s->no = n+2; 413 s->no = n + 2;
414 } 414 }
415 return (s_stat*)s; 415 return (s_stat*)s;
416} 416}
@@ -438,7 +438,7 @@ static void collect_ctx(ctx_stat *s)
438 438
439static s_stat* init_ctx(const char *param ATTRIBUTE_UNUSED) 439static s_stat* init_ctx(const char *param ATTRIBUTE_UNUSED)
440{ 440{
441 ctx_stat *s = xmalloc(sizeof(ctx_stat)); 441 ctx_stat *s = xzalloc(sizeof(*s));
442 s->collect = collect_ctx; 442 s->collect = collect_ctx;
443 return (s_stat*)s; 443 return (s_stat*)s;
444} 444}
@@ -480,7 +480,7 @@ static void collect_blk(blk_stat *s)
480 480
481static s_stat* init_blk(const char *param ATTRIBUTE_UNUSED) 481static s_stat* init_blk(const char *param ATTRIBUTE_UNUSED)
482{ 482{
483 blk_stat *s = xmalloc(sizeof(blk_stat)); 483 blk_stat *s = xzalloc(sizeof(*s));
484 s->collect = collect_blk; 484 s->collect = collect_blk;
485 s->lookfor = "page"; 485 s->lookfor = "page";
486 return (s_stat*)s; 486 return (s_stat*)s;
@@ -520,7 +520,7 @@ static void collect_fork(fork_stat *s)
520 520
521static s_stat* init_fork(const char *param) 521static s_stat* init_fork(const char *param)
522{ 522{
523 fork_stat *s = xmalloc(sizeof(fork_stat)); 523 fork_stat *s = xzalloc(sizeof(*s));
524 if (*param == 'n') { 524 if (*param == 'n') {
525 s->collect = collect_thread_nr; 525 s->collect = collect_thread_nr;
526 } else { 526 } else {
@@ -560,16 +560,14 @@ static void collect_if(if_stat *s)
560 560
561static s_stat* init_if(const char *device) 561static s_stat* init_if(const char *device)
562{ 562{
563 if_stat *s = xmalloc(sizeof(if_stat)); 563 if_stat *s = xzalloc(sizeof(*s));
564 564
565 if (!device || !device[0]) 565 if (!device || !device[0])
566 bb_show_usage(); 566 bb_show_usage();
567 s->collect = collect_if; 567 s->collect = collect_if;
568 568
569 s->device = device; 569 s->device = device;
570 s->device_colon = xmalloc(strlen(device)+2); 570 s->device_colon = xasprintf("%s:", device);
571 strcpy(s->device_colon, device);
572 strcat(s->device_colon, ":");
573 return (s_stat*)s; 571 return (s_stat*)s;
574} 572}
575 573
@@ -650,7 +648,7 @@ static void collect_mem(mem_stat *s)
650 648
651static s_stat* init_mem(const char *param) 649static s_stat* init_mem(const char *param)
652{ 650{
653 mem_stat *s = xmalloc(sizeof(mem_stat)); 651 mem_stat *s = xzalloc(sizeof(*s));
654 s->collect = collect_mem; 652 s->collect = collect_mem;
655 s->opt = param[0]; 653 s->opt = param[0];
656 return (s_stat*)s; 654 return (s_stat*)s;
@@ -675,7 +673,7 @@ static void collect_swp(swp_stat *s ATTRIBUTE_UNUSED)
675 673
676static s_stat* init_swp(const char *param ATTRIBUTE_UNUSED) 674static s_stat* init_swp(const char *param ATTRIBUTE_UNUSED)
677{ 675{
678 swp_stat *s = xmalloc(sizeof(swp_stat)); 676 swp_stat *s = xzalloc(sizeof(*s));
679 s->collect = collect_swp; 677 s->collect = collect_swp;
680 return (s_stat*)s; 678 return (s_stat*)s;
681} 679}
@@ -698,7 +696,7 @@ static void collect_fd(fd_stat *s ATTRIBUTE_UNUSED)
698 696
699static s_stat* init_fd(const char *param ATTRIBUTE_UNUSED) 697static s_stat* init_fd(const char *param ATTRIBUTE_UNUSED)
700{ 698{
701 fd_stat *s = xmalloc(sizeof(fd_stat)); 699 fd_stat *s = xzalloc(sizeof(*s));
702 s->collect = collect_fd; 700 s->collect = collect_fd;
703 return (s_stat*)s; 701 return (s_stat*)s;
704} 702}
@@ -731,10 +729,10 @@ static void collect_time(time_stat *s)
731static s_stat* init_time(const char *param) 729static s_stat* init_time(const char *param)
732{ 730{
733 int prec; 731 int prec;
734 time_stat *s = xmalloc(sizeof(time_stat)); 732 time_stat *s = xzalloc(sizeof(*s));
735 733
736 s->collect = collect_time; 734 s->collect = collect_time;
737 prec = param[0]-'0'; 735 prec = param[0] - '0';
738 if (prec < 0) prec = 0; 736 if (prec < 0) prec = 0;
739 else if (prec > 6) prec = 6; 737 else if (prec > 6) prec = 6;
740 s->prec = prec; 738 s->prec = prec;
@@ -834,7 +832,7 @@ int nmeter_main(int argc, char **argv)
834 s = init_functions[p-options](param); 832 s = init_functions[p-options](param);
835 if (s) { 833 if (s) {
836 s->label = prev; 834 s->label = prev;
837 s->next = 0; 835 /*s->next = NULL; - all initXXX funcs use xzalloc */
838 if (!first) 836 if (!first)
839 first = s; 837 first = s;
840 else 838 else
@@ -849,7 +847,7 @@ int nmeter_main(int argc, char **argv)
849 if (prev[0]) { 847 if (prev[0]) {
850 s = init_literal(); 848 s = init_literal();
851 s->label = prev; 849 s->label = prev;
852 s->next = 0; 850 /*s->next = NULL; - all initXXX funcs use xzalloc */
853 if (!first) 851 if (!first)
854 first = s; 852 first = s;
855 else 853 else