]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Scan threads only when requested
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Thu, 22 Jul 2010 09:12:07 +0000 (12:12 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Thu, 22 Jul 2010 09:30:13 +0000 (12:30 +0300)
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 <kaapeli@itanic.dy.fi>
main.c
pagemap.h
parse.c

diff --git a/main.c b/main.c
index 22a6a6d0f580f37b00c106738824d3b0c6e299f6..4ac6ccbe45aa7c4e37440bea506ced2c43badb78 100644 (file)
--- 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]);
                }
index 3de6650ac4335b5ddfe12e897bd23e8f1bbe1574..ee6bcc6203a54a0aa04792156febe4e51d500de8 100644 (file)
--- 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 dfbcba6e8f60276d1f52dce26509d2ac4628cf63..d5962c86cd91944182e1ca70681a3cc9fe4b6915 100644 (file)
--- 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;
        }
 }