{
struct pageframe pf;
struct process *process_list = NULL;
+ struct parse_opts opts;
int pid;
if (argc < 2) {
pid = atoi(argv[1]);
memset(&pf, 0, sizeof(pf));
- scan_all_pids(&pf, &process_list, pid);
+ opts.parse_mask = PARSE_PID;
+ opts.pid = pid;
+
+ scan_all_pids(&pf, &process_list, &opts);
print_pid_stats(&pf, process_list);
print_page_stats(&pf);
static void pageframe_to_struct(unsigned long long p, struct pageframe *pf)
{
+ /* Refer Documentation/vm/pagemap.txt for the format */
pf->page_present = !!(BITRANGE(63, 63) & p);
pf->page_swapped = !!(BITRANGE(62, 62) & p);
pf->page_shift = (BITRANGE(55, 60) & p) >> 55;
.compare = compare_pageframe,
};
+static int check_parse_opts(struct parse_opts *opts, struct pageframe *pf,
+ struct maps *map)
+{
+ if (opts->parse_mask & PARSE_PID) {
+ if (opts->pid == map->pid)
+ return 1;
+ }
+
+ if (opts->parse_mask & PARSE_MAP_NAME) {
+ if (!strcmp(opts->map_name, map->name))
+ return 1;
+ }
+
+ return 0;
+}
+
/* Read data from the /proc/pid/pagemap file */
static int parse_pageframe(FILE *file, struct pageframe *pf_tree,
- struct maps *maps, int add_to_tree)
+ struct maps *maps, struct parse_opts *opts)
{
struct maps *map;
struct maps_list *tmp;
pageframe_to_struct(pf[ret / sizeof(pf[0])], pageframe);
- if (add_to_tree) {
+ if (check_parse_opts(opts, pageframe, map)) {
match = tree_to_pageframe(
bintree_add(&pf_tree->tree,
&pageframe->tree,
}
void read_pageframe(int pid, struct pageframe *pageframe,
- struct process **process_list, int add_to_tree)
+ struct process **process_list, struct parse_opts *opts)
{
struct maps *maps;
struct process *process;
if (!file)
return;
- parse_pageframe(file, pageframe, maps, add_to_tree);
+ parse_pageframe(file, pageframe, maps, opts);
fclose(file);
snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
}
void scan_all_pids(struct pageframe *pf, struct process **process_list,
- int interesting_pid)
+ struct parse_opts *opts)
{
int pid;
- read_pageframe(interesting_pid, pf, process_list, 1);
-
while(1) {
pid = get_next_pid();
if (pid <= 0)
break;
- read_pageframe(pid, pf, process_list, 0);
+ read_pageframe(pid, pf, process_list, opts);
}
}