12 void print_help_and_die(char *name)
14 printf("Usage: %s options\n"
15 "-p, --pid=PID scan maps belonging to a given pid\n"
16 "-P, --process=PROCESS scan maps belonging to processes with "
18 "-m, --map=mapname scan maps with given mapping name\n"
19 "-d, --dump dump process maps\n"
20 "-h, --help show this help\n",
26 #define OPT_WITH_THREADS 0x101
28 void read_args(int argc, char *argv[], struct parse_opts *opts)
31 static struct option long_options[] = {
32 { .val = 'p', .name = "pid", .has_arg = 1, },
33 { .val = 'P', .name = "process", .has_arg = 1, },
34 { .val = 'm', .name = "map", .has_arg = 1, },
35 { .val = OPT_WITH_THREADS, .name = "with-threads" },
36 { .val = 'd', .name = "dump", },
37 { .val = 'h', .name = "help", },
39 char short_options[] = "p:P:m:dh";
43 c = getopt_long(argc, argv, short_options, long_options,
52 struct pidlist *pid = alloc_pidlist();
58 pid->pid = atoi(optarg);
59 opts->parse_mask |= PARSE_PID;
60 list_add_tail(&pid->list, &opts->pidlist);
64 opts->parse_mask |= PARSE_PROCESS_NAME;
68 opts->parse_mask |= PARSE_MAP_NAME;
71 case OPT_WITH_THREADS:
72 opts->with_threads = 1;
75 opts->parse_mask |= PARSE_DUMP;
78 print_help_and_die(argv[0]);
84 int main(int argc, char *argv[])
87 struct process process_list;
88 struct parse_opts opts;
91 printf("WARNING: Running without root priviledges. "
92 "Results may be inaccurate\n");
95 init_parse_opts(&opts);
97 read_args(argc, argv, &opts);
100 printf("A pid needs to be given as an argument\n");
101 print_help_and_die(argv[0]);
104 clear_pageframe(&pf);
106 memset(&process_list, 0, sizeof(process_list));
107 INIT_LIST_HEAD(&process_list.list);
109 if (scan_all_pids(&pf, &process_list, &opts))
112 if (opts.parse_mask & PARSE_DUMP)
113 dump_process_maps(&process_list);
115 print_pid_stats(&pf, &process_list, &opts);
117 print_page_stats(&pf);