From 0834a6d3b9daec1f460c3cc836136ace12c53df0 Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Sat, 28 Aug 2010 23:20:34 +0200 Subject: pmap: new applet. +1k. pmap is a tool used to look at processes' memory maps, normally found in procps package. It provides more readable and easily sortable output (one line per mapping) from maps/smaps files in /proc/PID/. This would help in debugging memory usage issues, especially on devices where lots of typing is not a viable option. This patch does'n implement -d and -A command line options of GNU pmap, since those are not that must have features and I was afraid of going blind from looking at its code. The implementation takes smaps scanning part out of procps_scan() function and moves it into procps_read_smaps(), which does more detailed processing of a single PID's smaps data. Signed-off-by: Alexander Shishkin Signed-off-by: Denys Vlasenko --- include/libbb.h | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/libbb.h b/include/libbb.h index 3fd7545..43e525c 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1387,6 +1387,29 @@ enum { COMM_LEN = TASK_COMM_LEN }; enum { COMM_LEN = 16 }; # endif #endif + +struct smaprec { + unsigned long mapped_rw; + unsigned long mapped_ro; + unsigned long shared_clean; + unsigned long shared_dirty; + unsigned long private_clean; + unsigned long private_dirty; + unsigned long stack; + unsigned long smap_pss, smap_swap; + unsigned long smap_size; + unsigned long smap_start; + char smap_mode[5]; + char *smap_name; +}; + +#if !ENABLE_PMAP +#define procps_read_smaps(pid, total, cb, data) \ + procps_read_smaps(pid, total) +#endif +int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, + void (*cb)(struct smaprec *, void *), void *data); + typedef struct procps_status_t { DIR *dir; IF_FEATURE_SHOW_THREADS(DIR *task_dir;) @@ -1415,13 +1438,7 @@ typedef struct procps_status_t { #endif unsigned tty_major,tty_minor; #if ENABLE_FEATURE_TOPMEM - unsigned long mapped_rw; - unsigned long mapped_ro; - unsigned long shared_clean; - unsigned long shared_dirty; - unsigned long private_clean; - unsigned long private_dirty; - unsigned long stack; + struct smaprec smaps; #endif char state[4]; /* basename of executable in exec(2), read from /proc/N/stat -- cgit v1.1