]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Dump process page maps when requested
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Fri, 23 Jul 2010 16:40:30 +0000 (19:40 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Fri, 23 Jul 2010 16:40:30 +0000 (19:40 +0300)
If dumping is requested, only the given processes are being scanned,
not all pids in the system.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c
pagemap.h
parse.c

diff --git a/main.c b/main.c
index e189dbe6b9769ca2e40f659a4a8589180a5ec721..36fefaa53f3f729610aeb7e72a19d9922a827bc7 100644 (file)
--- 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;
 }
index cd28c4100e1f05f3dfde9748444cb5e68631aaeb..fae18f01422d14b7c2b3cfd035c8b437ad361b36 100644 (file)
--- 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 b4057064516ffefb7fc83cc7b39a12b14fc4d364..386e50dab082c29b2163d2f41da2cae14f72ef7c 100644 (file)
--- 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)