diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-03-15 17:54:17 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-03-15 17:54:17 +0100 |
commit | 0d1b71e8e61491cf50fc3a21ec0a412f6dca4d56 (patch) | |
tree | 327b1e1f7803e7b6d8dffa39635078ae7895bf27 /procps | |
parent | 41b1e2c39238ef1f333588b9a857e5af806bd157 (diff) | |
download | busybox-w32-0d1b71e8e61491cf50fc3a21ec0a412f6dca4d56.tar.gz busybox-w32-0d1b71e8e61491cf50fc3a21ec0a412f6dca4d56.tar.bz2 busybox-w32-0d1b71e8e61491cf50fc3a21ec0a412f6dca4d56.zip |
nmeter: reinstate and document -d-1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r-- | procps/nmeter.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/procps/nmeter.c b/procps/nmeter.c index d6c46c657..33de3790f 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c | |||
@@ -21,7 +21,7 @@ | |||
21 | //usage:#define nmeter_full_usage "\n\n" | 21 | //usage:#define nmeter_full_usage "\n\n" |
22 | //usage: "Monitor system in real time" | 22 | //usage: "Monitor system in real time" |
23 | //usage: "\n" | 23 | //usage: "\n" |
24 | //usage: "\n -d MSEC Milliseconds between updates (default:1000)" | 24 | //usage: "\n -d MSEC Milliseconds between updates, default:1000, none:-1" |
25 | //usage: "\n" | 25 | //usage: "\n" |
26 | //usage: "\nFormat specifiers:" | 26 | //usage: "\nFormat specifiers:" |
27 | //usage: "\n %Nc or %[cN] CPU. N - bar size (default:10)" | 27 | //usage: "\n %Nc or %[cN] CPU. N - bar size (default:10)" |
@@ -86,7 +86,7 @@ struct globals { | |||
86 | char final_char; | 86 | char final_char; |
87 | char *cur_outbuf; | 87 | char *cur_outbuf; |
88 | int delta; | 88 | int delta; |
89 | int deltanz; | 89 | unsigned deltanz; |
90 | struct timeval tv; | 90 | struct timeval tv; |
91 | #define first_proc_file proc_stat | 91 | #define first_proc_file proc_stat |
92 | proc_file proc_stat; // Must match the order of proc_name's! | 92 | proc_file proc_stat; // Must match the order of proc_name's! |
@@ -101,8 +101,6 @@ struct globals { | |||
101 | #define is26 (G.is26 ) | 101 | #define is26 (G.is26 ) |
102 | #define need_seconds (G.need_seconds ) | 102 | #define need_seconds (G.need_seconds ) |
103 | #define cur_outbuf (G.cur_outbuf ) | 103 | #define cur_outbuf (G.cur_outbuf ) |
104 | #define delta (G.delta ) | ||
105 | #define deltanz (G.deltanz ) | ||
106 | #define tv (G.tv ) | 104 | #define tv (G.tv ) |
107 | #define proc_stat (G.proc_stat ) | 105 | #define proc_stat (G.proc_stat ) |
108 | #define proc_loadavg (G.proc_loadavg ) | 106 | #define proc_loadavg (G.proc_loadavg ) |
@@ -114,7 +112,7 @@ struct globals { | |||
114 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 112 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
115 | cur_outbuf = outbuf; \ | 113 | cur_outbuf = outbuf; \ |
116 | G.final_char = '\n'; \ | 114 | G.final_char = '\n'; \ |
117 | deltanz = delta = 1000000; \ | 115 | G.deltanz = G.delta = 1000000; \ |
118 | } while (0) | 116 | } while (0) |
119 | 117 | ||
120 | // We depend on this being a char[], not char* - we take sizeof() of it | 118 | // We depend on this being a char[], not char* - we take sizeof() of it |
@@ -844,9 +842,9 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) | |||
844 | } | 842 | } |
845 | 843 | ||
846 | if (getopt32(argv, "d:", &opt_d)) { | 844 | if (getopt32(argv, "d:", &opt_d)) { |
847 | delta = xatou(opt_d) * 1000; | 845 | G.delta = xatoi(opt_d) * 1000; |
848 | deltanz = delta > 0 ? delta : 1; | 846 | G.deltanz = G.delta > 0 ? G.delta : 1; |
849 | need_seconds = (1000000 % deltanz) != 0; | 847 | need_seconds = (1000000 % G.deltanz) != 0; |
850 | } | 848 | } |
851 | argv += optind; | 849 | argv += optind; |
852 | 850 | ||
@@ -902,8 +900,8 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) | |||
902 | last->next = s; | 900 | last->next = s; |
903 | last = s; | 901 | last = s; |
904 | } else { | 902 | } else { |
905 | // %NNNNd or %r option. remove it from string | 903 | // %r option. remove it from string |
906 | strcpy(prev + strlen(prev), cur); | 904 | overlapping_strcpy(prev + strlen(prev), cur); |
907 | cur = prev; | 905 | cur = prev; |
908 | } | 906 | } |
909 | } | 907 | } |
@@ -921,9 +919,9 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) | |||
921 | // Generate first samples but do not print them, they're bogus | 919 | // Generate first samples but do not print them, they're bogus |
922 | collect_info(first); | 920 | collect_info(first); |
923 | reset_outbuf(); | 921 | reset_outbuf(); |
924 | if (delta >= 0) { | 922 | if (G.delta >= 0) { |
925 | gettimeofday(&tv, NULL); | 923 | gettimeofday(&tv, NULL); |
926 | usleep(delta > 1000000 ? 1000000 : delta - tv.tv_usec%deltanz); | 924 | usleep(G.delta > 1000000 ? 1000000 : G.delta - tv.tv_usec % G.deltanz); |
927 | } | 925 | } |
928 | 926 | ||
929 | while (1) { | 927 | while (1) { |
@@ -937,18 +935,18 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) | |||
937 | // time resolution ;) | 935 | // time resolution ;) |
938 | // TODO: detect and avoid useless updates | 936 | // TODO: detect and avoid useless updates |
939 | // (like: nothing happens except time) | 937 | // (like: nothing happens except time) |
940 | if (delta >= 0) { | 938 | if (G.delta >= 0) { |
941 | int rem; | 939 | int rem; |
942 | // can be commented out, will sacrifice sleep time precision a bit | 940 | // can be commented out, will sacrifice sleep time precision a bit |
943 | gettimeofday(&tv, NULL); | 941 | gettimeofday(&tv, NULL); |
944 | if (need_seconds) | 942 | if (need_seconds) |
945 | rem = delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % deltanz; | 943 | rem = G.delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % G.deltanz; |
946 | else | 944 | else |
947 | rem = delta - tv.tv_usec%deltanz; | 945 | rem = G.delta - (unsigned)tv.tv_usec % G.deltanz; |
948 | // Sometimes kernel wakes us up just a tiny bit earlier than asked | 946 | // Sometimes kernel wakes us up just a tiny bit earlier than asked |
949 | // Do not go to very short sleep in this case | 947 | // Do not go to very short sleep in this case |
950 | if (rem < delta/128) { | 948 | if (rem < (unsigned)G.delta / 128) { |
951 | rem += delta; | 949 | rem += G.delta; |
952 | } | 950 | } |
953 | usleep(rem); | 951 | usleep(rem); |
954 | } | 952 | } |