diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-08-16 02:49:21 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-08-16 02:49:21 +0200 |
commit | c9b9750a0e2a85d3d045cc8d0217d4605f2d7989 (patch) | |
tree | 00168254b5f9e960ce42ea36d6d4a78bd269eae4 /procps/iostat.c | |
parent | a4160e15ec866005f3ad30c967bc4829fbb1c8e3 (diff) | |
download | busybox-w32-c9b9750a0e2a85d3d045cc8d0217d4605f2d7989.tar.gz busybox-w32-c9b9750a0e2a85d3d045cc8d0217d4605f2d7989.tar.bz2 busybox-w32-c9b9750a0e2a85d3d045cc8d0217d4605f2d7989.zip |
libbb: factor out common code from mpstat/iostat
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps/iostat.c')
-rw-r--r-- | procps/iostat.c | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/procps/iostat.c b/procps/iostat.c index 76c5353cc..e8e321b8d 100644 --- a/procps/iostat.c +++ b/procps/iostat.c | |||
@@ -114,26 +114,6 @@ static void print_header(void) | |||
114 | buf, uts.machine, G.total_cpus); | 114 | buf, uts.machine, G.total_cpus); |
115 | } | 115 | } |
116 | 116 | ||
117 | static int get_number_of_cpus(void) | ||
118 | { | ||
119 | #ifdef _SC_NPROCESSORS_CONF | ||
120 | return sysconf(_SC_NPROCESSORS_CONF); | ||
121 | #else | ||
122 | char buf[128]; | ||
123 | int n = 0; | ||
124 | FILE *fp; | ||
125 | |||
126 | fp = xfopen_for_read("/proc/cpuinfo"); | ||
127 | |||
128 | while (fgets(buf, sizeof(buf), fp)) | ||
129 | if (strncmp(buf, "processor\t:", 11) == 0) | ||
130 | n++; | ||
131 | |||
132 | fclose(fp); | ||
133 | return n; | ||
134 | #endif | ||
135 | } | ||
136 | |||
137 | static void get_localtime(struct tm *ptm) | 117 | static void get_localtime(struct tm *ptm) |
138 | { | 118 | { |
139 | time_t timer; | 119 | time_t timer; |
@@ -148,12 +128,6 @@ static void print_timestamp(void) | |||
148 | printf("%s\n", buf); | 128 | printf("%s\n", buf); |
149 | } | 129 | } |
150 | 130 | ||
151 | /* Does str start with "cpu"? */ | ||
152 | static int starts_with_cpu(const char *str) | ||
153 | { | ||
154 | return ((str[0] - 'c') | (str[1] - 'p') | (str[2] - 'u')) == 0; | ||
155 | } | ||
156 | |||
157 | /* Fetch CPU statistics from /proc/stat */ | 131 | /* Fetch CPU statistics from /proc/stat */ |
158 | static void get_cpu_statistics(struct stats_cpu *sc) | 132 | static void get_cpu_statistics(struct stats_cpu *sc) |
159 | { | 133 | { |
@@ -509,7 +483,9 @@ int iostat_main(int argc, char **argv) | |||
509 | G.clk_tck = get_user_hz(); | 483 | G.clk_tck = get_user_hz(); |
510 | 484 | ||
511 | /* Determine number of CPUs */ | 485 | /* Determine number of CPUs */ |
512 | G.total_cpus = get_number_of_cpus(); | 486 | G.total_cpus = get_cpu_count(); |
487 | if (G.total_cpus == 0) | ||
488 | G.total_cpus = 1; | ||
513 | 489 | ||
514 | /* Parse and process arguments */ | 490 | /* Parse and process arguments */ |
515 | /* -k and -m are mutually exclusive */ | 491 | /* -k and -m are mutually exclusive */ |