From d5334b051774d1b7480a6bf19b7378c44a393a4e Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Thu, 22 Jul 2010 12:12:07 +0300 Subject: [PATCH] Scan threads only when requested Usually there is no need to scan every threads for every processes, as they are very likely to share their address space between each others. Thus, scanning only one of them is mostly enough. Signed-off-by: Timo Kokkonen --- main.c | 7 +++++++ pagemap.h | 1 + parse.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 22a6a6d..4ac6ccb 100644 --- a/main.c +++ b/main.c @@ -18,12 +18,15 @@ void print_help_and_die(char *name) exit(0); } +#define OPT_WITH_THREADS 0x101 + void read_args(int argc, char *argv[], struct parse_opts *opts) { int optind = 0, c; static struct option long_options[] = { { .val = 'p', .name = "pid", .has_arg = 1, }, { .val = 'm', .name = "map", .has_arg = 1, }, + { .val = OPT_WITH_THREADS, .name = "with-threads" }, { .val = 'h', .name = "help", }, }; char short_options[] = "p:m:h"; @@ -36,6 +39,7 @@ void read_args(int argc, char *argv[], struct parse_opts *opts) if (c == -1) break; + printf("%c: %s\n", c, optarg); switch (c) { case 'p': opts->pid = atoi(optarg); @@ -45,6 +49,9 @@ void read_args(int argc, char *argv[], struct parse_opts *opts) opts->parse_mask |= PARSE_MAP_NAME; opts->map_name = optarg; break; + case OPT_WITH_THREADS: + opts->with_threads = 1; + break; case 'h': print_help_and_die(argv[0]); } diff --git a/pagemap.h b/pagemap.h index 3de6650..ee6bcc6 100644 --- a/pagemap.h +++ b/pagemap.h @@ -68,6 +68,7 @@ struct parse_opts { int parse_mask; int pid; char *map_name; + int with_threads; }; #endif diff --git a/parse.c b/parse.c index dfbcba6..d5962c8 100644 --- a/parse.c +++ b/parse.c @@ -368,12 +368,18 @@ static void read_pageframe_with_threads(int pid, int tid; while (1) { - tid = get_next_tid(pid, &dir); + if (opts->with_threads) + tid = get_next_tid(pid, &dir); + else + tid = pid; if (tid <= 0) return; - read_pageframe(pid, pid, pageframe, process_list, opts); + read_pageframe(pid, tid, pageframe, process_list, opts); + + if (!opts->with_threads) + break; } } -- 2.44.0