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 "-h, --help show this help\n",
23 #define OPT_WITH_THREADS 0x101
25 void read_args(int argc, char *argv[], struct parse_opts *opts)
28 static struct option long_options[] = {
29 { .val = 'p', .name = "pid", .has_arg = 1, },
30 { .val = 'P', .name = "process", .has_arg = 1, },
31 { .val = 'm', .name = "map", .has_arg = 1, },
32 { .val = OPT_WITH_THREADS, .name = "with-threads" },
33 { .val = 'h', .name = "help", },
35 char short_options[] = "p:P:m:h";
39 c = getopt_long(argc, argv, short_options, long_options,
47 opts->pid = atoi(optarg);
48 opts->parse_mask |= PARSE_PID;
51 opts->parse_mask |= PARSE_PROCESS_NAME;
55 opts->parse_mask |= PARSE_MAP_NAME;
58 case OPT_WITH_THREADS:
59 opts->with_threads = 1;
62 print_help_and_die(argv[0]);
67 int main(int argc, char *argv[])
70 struct process *process_list = NULL;
71 struct parse_opts opts;
73 memset(&opts, 0, sizeof(opts));
75 read_args(argc, argv, &opts);
78 printf("A pid needs to be given as an argument\n");
79 print_help_and_die(argv[0]);
82 memset(&pf, 0, sizeof(pf));
84 if (scan_all_pids(&pf, &process_list, &opts))
87 print_pid_stats(&pf, process_list, &opts);
88 print_page_stats(&pf);