From df91296e75262e040af7fa27a3fcabef833a2c42 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Fri, 23 Jul 2010 19:40:30 +0300 Subject: [PATCH] Dump process page maps when requested If dumping is requested, only the given processes are being scanned, not all pids in the system. Signed-off-by: Timo Kokkonen --- main.c | 16 +++++++++++++--- pagemap.h | 1 + parse.c | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index e189dbe..36fefaa 100644 --- a/main.c +++ b/main.c @@ -14,6 +14,7 @@ void print_help_and_die(char *name) "-P, --process=PROCESS scan maps belonging to processes with " "given name\n" "-m, --map=mapname scan maps with given mapping name\n" + "-d, --dump dump process maps\n" "-h, --help show this help\n", name); @@ -30,9 +31,10 @@ void read_args(int argc, char *argv[], struct parse_opts *opts) { .val = 'P', .name = "process", .has_arg = 1, }, { .val = 'm', .name = "map", .has_arg = 1, }, { .val = OPT_WITH_THREADS, .name = "with-threads" }, + { .val = 'd', .name = "dump", }, { .val = 'h', .name = "help", }, }; - char short_options[] = "p:P:m:h"; + char short_options[] = "p:P:m:dh"; opts->parse_mask = 0; while (1) { @@ -58,8 +60,12 @@ void read_args(int argc, char *argv[], struct parse_opts *opts) case OPT_WITH_THREADS: opts->with_threads = 1; break; + case 'd': + opts->parse_mask |= PARSE_DUMP; + break; case 'h': print_help_and_die(argv[0]); + break; } } } @@ -84,8 +90,12 @@ int main(int argc, char *argv[]) if (scan_all_pids(&pf, &process_list, &opts)) return 1; - print_pid_stats(&pf, process_list, &opts); - print_page_stats(&pf); + if (opts.parse_mask & PARSE_DUMP) + dump_process_maps(process_list); + else { + print_pid_stats(&pf, process_list, &opts); + print_page_stats(&pf); + } return 0; } diff --git a/pagemap.h b/pagemap.h index cd28c41..fae18f0 100644 --- a/pagemap.h +++ b/pagemap.h @@ -66,6 +66,7 @@ struct process { #define PARSE_PID 0x1 #define PARSE_MAP_NAME 0x2 #define PARSE_PROCESS_NAME 0x4 +#define PARSE_DUMP 0x8 struct parse_opts { int parse_mask; diff --git a/parse.c b/parse.c index b405706..386e50d 100644 --- a/parse.c +++ b/parse.c @@ -473,6 +473,9 @@ int scan_all_pids(struct pageframe *pf, struct process **process_list, return -1; } + if (opts->parse_mask & PARSE_DUMP) + return 0; + while (1) { pid = get_next_pid(&dir); if (pid <= 0) -- 2.45.0