10 void print_help_and_die(char *name)
12 printf("Usage: %s options \n"
13 "-p, --pid=PID scan maps belonging to a given pid\n"
14 "-P, --process=PROCESS scan maps belonging to processes with "
16 "-m, --map=mapname scan maps with given mapping name\n"
17 "-d, --dump dump process maps\n"
18 "-h, --help show this help\n",
24 #define OPT_WITH_THREADS 0x101
26 void read_args(int argc, char *argv[], struct parse_opts *opts)
29 static struct option long_options[] = {
30 { .val = 'p', .name = "pid", .has_arg = 1, },
31 { .val = 'P', .name = "process", .has_arg = 1, },
32 { .val = 'm', .name = "map", .has_arg = 1, },
33 { .val = OPT_WITH_THREADS, .name = "with-threads" },
34 { .val = 'd', .name = "dump", },
35 { .val = 'h', .name = "help", },
37 char short_options[] = "p:P:m:dh";
41 c = getopt_long(argc, argv, short_options, long_options,
49 opts->pid = atoi(optarg);
50 opts->parse_mask |= PARSE_PID;
53 opts->parse_mask |= PARSE_PROCESS_NAME;
57 opts->parse_mask |= PARSE_MAP_NAME;
60 case OPT_WITH_THREADS:
61 opts->with_threads = 1;
64 opts->parse_mask |= PARSE_DUMP;
67 print_help_and_die(argv[0]);
73 int main(int argc, char *argv[])
76 struct process *process_list = NULL;
77 struct parse_opts opts;
79 memset(&opts, 0, sizeof(opts));
81 read_args(argc, argv, &opts);
84 printf("A pid needs to be given as an argument\n");
85 print_help_and_die(argv[0]);
88 memset(&pf, 0, sizeof(pf));
90 if (scan_all_pids(&pf, &process_list, &opts))
93 if (opts.parse_mask & PARSE_DUMP)
94 dump_process_maps(process_list);
96 print_pid_stats(&pf, process_list, &opts);
98 print_page_stats(&pf);