diff options
author | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-02-14 10:36:38 +0000 |
---|---|---|
committer | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-02-14 10:36:38 +0000 |
commit | 3afdfecf7ed6c5cd21837b2354128d107808ca43 (patch) | |
tree | 2d4f51d99c7f82a40a46dab93c088987bfefa038 | |
parent | 465300ced9320a4e8bdf9db00fd4f8e0a35e4a4c (diff) | |
download | busybox-w32-3afdfecf7ed6c5cd21837b2354128d107808ca43.tar.gz busybox-w32-3afdfecf7ed6c5cd21837b2354128d107808ca43.tar.bz2 busybox-w32-3afdfecf7ed6c5cd21837b2354128d107808ca43.zip |
restore change by Denis Vlasenko: file_to_buf must vary fast, best if inline
-rw-r--r-- | procps/top.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/procps/top.c b/procps/top.c index 17addd0f5..f2e798bde 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -130,9 +130,9 @@ static unsigned long Hertz; | |||
130 | * | 130 | * |
131 | */ | 131 | */ |
132 | 132 | ||
133 | static int file_to_buf(char *buf, int bufsize, char *filename, int *d) | 133 | #define file_to_buf_bufsize 80 |
134 | static inline int file_to_buf(char *buf, const char *filename, int fd) | ||
134 | { | 135 | { |
135 | int fd = *d; | ||
136 | int sz; | 136 | int sz; |
137 | 137 | ||
138 | if (fd == -1) { | 138 | if (fd == -1) { |
@@ -142,13 +142,12 @@ static int file_to_buf(char *buf, int bufsize, char *filename, int *d) | |||
142 | } else { | 142 | } else { |
143 | lseek(fd, 0L, SEEK_SET); | 143 | lseek(fd, 0L, SEEK_SET); |
144 | } | 144 | } |
145 | sz = read(fd, buf, bufsize - 1); | 145 | sz = read(fd, buf, file_to_buf_bufsize - 1); |
146 | if (sz < 0) { | 146 | if (sz < 0) { |
147 | bb_perror_msg_and_die("%s", filename); | 147 | bb_perror_msg_and_die("%s", filename); |
148 | } | 148 | } |
149 | buf[sz] = '\0'; | 149 | buf[sz] = '\0'; |
150 | *d = fd; | 150 | return fd; |
151 | return sz; | ||
152 | } | 151 | } |
153 | 152 | ||
154 | static void init_Hertz_value(void) | 153 | static void init_Hertz_value(void) |
@@ -165,11 +164,11 @@ static void init_Hertz_value(void) | |||
165 | if(smp_num_cpus<1) smp_num_cpus=1; | 164 | if(smp_num_cpus<1) smp_num_cpus=1; |
166 | 165 | ||
167 | do { | 166 | do { |
168 | file_to_buf(buf, sizeof(buf), "uptime", &uptime_fd); | 167 | uptime_fd = file_to_buf(buf, "uptime", uptime_fd); |
169 | up_1 = strtod(buf, 0); | 168 | up_1 = strtod(buf, 0); |
170 | file_to_buf(buf, sizeof(buf), "stat", &stat_fd); | 169 | stat_fd = file_to_buf(buf, "stat", stat_fd); |
171 | sscanf(buf, "cpu %lu %lu %lu %lu", &user_j, &nice_j, &sys_j, &other_j); | 170 | sscanf(buf, "cpu %lu %lu %lu %lu", &user_j, &nice_j, &sys_j, &other_j); |
172 | file_to_buf(buf, sizeof(buf), "uptime", &uptime_fd); | 171 | uptime_fd = file_to_buf(buf, "uptime", uptime_fd); |
173 | up_2 = strtod(buf, 0); | 172 | up_2 = strtod(buf, 0); |
174 | } while((long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */ | 173 | } while((long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */ |
175 | close(uptime_fd); | 174 | close(uptime_fd); |