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,
51 opts->pid = atoi(optarg);
52 opts->parse_mask |= PARSE_PID;
55 opts->parse_mask |= PARSE_PROCESS_NAME;
59 opts->parse_mask |= PARSE_MAP_NAME;
62 case OPT_WITH_THREADS:
63 opts->with_threads = 1;
66 opts->parse_mask |= PARSE_DUMP;
69 print_help_and_die(argv[0]);
75 int main(int argc, char *argv[])
78 struct process *process_list = NULL;
79 struct parse_opts opts;
82 printf("WARNING: Running without root priviledges. "
83 "Results may be inaccurate\n");
86 memset(&opts, 0, sizeof(opts));
88 read_args(argc, argv, &opts);
91 printf("A pid needs to be given as an argument\n");
92 print_help_and_die(argv[0]);
95 memset(&pf, 0, sizeof(pf));
97 if (scan_all_pids(&pf, &process_list, &opts))
100 if (opts.parse_mask & PARSE_DUMP)
101 dump_process_maps(process_list);
103 print_pid_stats(&pf, process_list, &opts);
105 print_page_stats(&pf);