10 void print_help_and_die(char *name)
12 printf("Usage: %s options \n"
13 "-p, --pid=PID scan maps belingin to a given pid\n"
14 "-m, --map=mapname scan maps with given mapping name\n"
15 "-h, --help show this help\n",
21 #define OPT_WITH_THREADS 0x101
23 void read_args(int argc, char *argv[], struct parse_opts *opts)
26 static struct option long_options[] = {
27 { .val = 'p', .name = "pid", .has_arg = 1, },
28 { .val = 'P', .name = "process", .has_arg = 1, },
29 { .val = 'm', .name = "map", .has_arg = 1, },
30 { .val = OPT_WITH_THREADS, .name = "with-threads" },
31 { .val = 'h', .name = "help", },
33 char short_options[] = "p:P:m:h";
37 c = getopt_long(argc, argv, short_options, long_options,
45 opts->pid = atoi(optarg);
46 opts->parse_mask |= PARSE_PID;
49 opts->parse_mask |= PARSE_PROCESS_NAME;
53 opts->parse_mask |= PARSE_MAP_NAME;
56 case OPT_WITH_THREADS:
57 opts->with_threads = 1;
60 print_help_and_die(argv[0]);
65 int main(int argc, char *argv[])
68 struct process *process_list = NULL;
69 struct parse_opts opts;
71 memset(&opts, 0, sizeof(opts));
73 read_args(argc, argv, &opts);
76 printf("A pid needs to be given as an argument\n");
77 print_help_and_die(argv[0]);
80 memset(&pf, 0, sizeof(pf));
82 if (scan_all_pids(&pf, &process_list, &opts))
85 print_pid_stats(&pf, process_list, &opts);
86 print_page_stats(&pf);