diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-06 14:42:06 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-06 14:42:06 +0200 |
| commit | 0b05a4e71e181fa47c319546fc9ad9fb1b3f6f24 (patch) | |
| tree | b19794218bb90288e60529f0de4493492ed426a4 /libbb | |
| parent | 47d27cdaff8e07783683a076359dd975b822bc86 (diff) | |
| download | busybox-w32-0b05a4e71e181fa47c319546fc9ad9fb1b3f6f24.tar.gz busybox-w32-0b05a4e71e181fa47c319546fc9ad9fb1b3f6f24.tar.bz2 busybox-w32-0b05a4e71e181fa47c319546fc9ad9fb1b3f6f24.zip | |
top,pmap: speed up /smaps parsing
function old new delta
procps_read_smaps 515 529 +14
procps_get_maps 685 665 -20
.rodata 105847 105820 -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 14/-47) Total: -33 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/procps.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index d512993e8..de640d29e 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
| @@ -195,7 +195,7 @@ static NOINLINE void procps_read_smaps(pid_t pid, procps_status_t *sp) | |||
| 195 | 195 | ||
| 196 | FILE *file; | 196 | FILE *file; |
| 197 | char filename[sizeof("/proc/%u/smaps") + sizeof(int)*3]; | 197 | char filename[sizeof("/proc/%u/smaps") + sizeof(int)*3]; |
| 198 | char buf[PROCPS_BUFSIZE]; | 198 | char buf[PROCPS_BUFSIZE] ALIGN4; |
| 199 | 199 | ||
| 200 | sprintf(filename, "/proc/%u/smaps", (int)pid); | 200 | sprintf(filename, "/proc/%u/smaps", (int)pid); |
| 201 | 201 | ||
| @@ -211,20 +211,27 @@ static NOINLINE void procps_read_smaps(pid_t pid, procps_status_t *sp) | |||
| 211 | // ..... | 211 | // ..... |
| 212 | 212 | ||
| 213 | char *tp; | 213 | char *tp; |
| 214 | 214 | #define bytes4 *(uint32_t*)buf | |
| 215 | if (buf[0] == 'S' || buf[0] == 'P') { | 215 | #define Priv PACK32_BYTES('P','r','i','v') |
| 216 | #define Shar PACK32_BYTES('S','h','a','r') | ||
| 216 | #define SCAN(S, X) \ | 217 | #define SCAN(S, X) \ |
| 217 | if (memcmp(buf, S, sizeof(S)-1) == 0) { \ | 218 | if (memcmp(buf+4, S, sizeof(S)-1) == 0) { \ |
| 218 | tp = skip_whitespace(buf + sizeof(S)-1); \ | 219 | tp = skip_whitespace(buf+4 + sizeof(S)-1); \ |
| 219 | sp->X += fast_strtoul_10(&tp); \ | 220 | sp->X += fast_strtoul_10(&tp); \ |
| 220 | continue; \ | 221 | continue; \ |
| 221 | } | 222 | } |
| 222 | SCAN("Private_Dirty:", private_dirty) | 223 | if (bytes4 == Priv) { |
| 223 | SCAN("Private_Clean:", private_clean) | 224 | SCAN("ate_Dirty:", private_dirty) |
| 224 | SCAN("Shared_Dirty:" , shared_dirty ) | 225 | SCAN("ate_Clean:", private_clean) |
| 225 | SCAN("Shared_Clean:" , shared_clean ) | 226 | } |
| 226 | #undef SCAN | 227 | if (bytes4 == Shar) { |
| 228 | SCAN("ed_Dirty:" , shared_dirty ) | ||
| 229 | SCAN("ed_Clean:" , shared_clean ) | ||
| 227 | } | 230 | } |
| 231 | #undef bytes4 | ||
| 232 | #undef Priv | ||
| 233 | #undef Shar | ||
| 234 | #undef SCAN | ||
| 228 | tp = strchr(buf, '-'); | 235 | tp = strchr(buf, '-'); |
| 229 | if (tp) { | 236 | if (tp) { |
| 230 | // We reached next mapping - the line of this form: | 237 | // We reached next mapping - the line of this form: |
