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 = 'm', .name = "map", .has_arg = 1, },
29 { .val = OPT_WITH_THREADS, .name = "with-threads" },
30 { .val = 'h', .name = "help", },
32 char short_options[] = "p:m:h";
36 c = getopt_long(argc, argv, short_options, long_options,
42 printf("%c: %s\n", c, optarg);
45 opts->pid = atoi(optarg);
46 opts->parse_mask |= PARSE_PID;
49 opts->parse_mask |= PARSE_MAP_NAME;
52 case OPT_WITH_THREADS:
53 opts->with_threads = 1;
56 print_help_and_die(argv[0]);
61 int main(int argc, char *argv[])
64 struct process *process_list = NULL;
65 struct parse_opts opts;
67 read_args(argc, argv, &opts);
70 printf("A pid needs to be given as an argument\n");
71 print_help_and_die(argv[0]);
74 memset(&pf, 0, sizeof(pf));
76 scan_all_pids(&pf, &process_list, &opts);
77 print_pid_stats(&pf, process_list, &opts);
78 print_page_stats(&pf);