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,
43 printf("%c: %s\n", c, optarg);
46 opts->pid = atoi(optarg);
47 opts->parse_mask |= PARSE_PID;
50 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 read_args(argc, argv, &opts);
74 printf("A pid needs to be given as an argument\n");
75 print_help_and_die(argv[0]);
78 memset(&pf, 0, sizeof(pf));
80 scan_all_pids(&pf, &process_list, &opts);
81 print_pid_stats(&pf, process_list, &opts);
82 print_page_stats(&pf);