]> git.itanic.dy.fi Git - scan-pagemap/blob - main.c
Add support for parsing all threads, not just thead parents
[scan-pagemap] / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <getopt.h>
6
7 #include "parse.h"
8 #include "analyze.h"
9
10 void read_args(int argc, char *argv[], struct parse_opts *opts)
11 {
12         int optind = 0, c;
13         static struct option long_options[] = {
14                 { .val = 'p', .name = "pid", .has_arg = 1, },
15                 { .val = 'm', .name = "map", .has_arg = 1, },
16         };
17         char short_options[] = "p:m:";
18         opts->parse_mask = 0;
19
20         while (1) {
21                 c = getopt_long(argc, argv, short_options, long_options,
22                                 &optind);
23
24                 if (c == -1)
25                         break;
26
27                 printf("%c: %s\n", c, optarg);
28                 switch (c) {
29                 case 'p':
30                         opts->pid = atoi(optarg);
31                         opts->parse_mask |= PARSE_PID;
32                         break;
33                 case 'm':
34                         opts->parse_mask |= PARSE_MAP_NAME;
35                         opts->map_name = optarg;
36                         break;
37                 }
38         }
39 }
40
41 int main(int argc, char *argv[])
42 {
43         struct pageframe pf;
44         struct process *process_list = NULL;
45         struct parse_opts opts;
46
47         if (argc < 3) {
48                 printf("A pid needs to be given as an argument\n");
49                 return 1;
50         }
51
52         read_args(argc, argv, &opts);
53
54         memset(&pf, 0, sizeof(pf));
55
56         scan_all_pids(&pf, &process_list, &opts);
57         print_pid_stats(&pf, process_list);
58         print_page_stats(&pf);
59
60         return 0;
61 }