9 #define SI_M (SI_k * SI_k)
10 #define SI_G (SI_M * SI_k)
12 #define PRETTY_THRESH 100
14 ((a) < SI_k * PRETTY_THRESH ? (a) : \
15 (a < SI_M * PRETTY_THRESH ? ((a) / SI_k) : \
16 (a < SI_G * PRETTY_THRESH ? ((a) / SI_M) : \
19 #define NICE_UNIT(a) \
20 ((a) < (SI_k * PRETTY_THRESH) ? " " : \
21 ((a) < (SI_M * PRETTY_THRESH) ? "k" : \
22 ((a) < (SI_G * PRETTY_THRESH) ? "M" : "G")))
24 #define PAGE_TO_NICE(a) NICE_DIV((long long)a * PAGE_SIZE)
25 #define PAGE_TO_NICE_UNIT(a) NICE_UNIT((long long)a * PAGE_SIZE)
27 struct analyze_frames {
28 struct bintree_ops ops;
29 long int pages_present;
30 long int pages_swapped;
31 long int pages_unused;
35 #define bintree_ops_to_af(bintree_ops) \
36 container_of((bintree_ops), struct analyze_frames, ops)
38 static void count_pages(struct bintree *b, struct bintree_ops *ops)
40 struct pageframe *pf = tree_to_pageframe(b);
41 struct analyze_frames *af = bintree_ops_to_af(ops);
45 list_for_each_entry(ml, &pf->ml->list, list) {
46 if (ml->map->pid == af->pid)
53 if (pf->page_present) {
55 } else if (pf->page_swapped) {
63 * print_page_stats - Prints system wide page stats
65 void print_page_stats(struct pageframe *pf)
67 struct analyze_frames af;
69 memset(&af, 0, sizeof(af));
71 af.ops.callback = count_pages;
73 count = bintree_walk(&pf->tree, &af.ops);
74 printf("present pages: %ld, %lld %sB\n"
75 "Swapped pages: %ld, %lld %sB\n"
76 "Unused pages: %ld, %lld %sB\n"
77 "Total %ld physical pages, %lld %sB\n",
79 PAGE_TO_NICE(af.pages_present),
80 PAGE_TO_NICE_UNIT(af.pages_present),
82 PAGE_TO_NICE(af.pages_swapped),
83 PAGE_TO_NICE_UNIT(af.pages_swapped),
85 PAGE_TO_NICE(af.pages_unused),
86 PAGE_TO_NICE_UNIT(af.pages_unused),
89 PAGE_TO_NICE_UNIT(count));
92 void print_pid_stats(struct pageframe *pf, struct process *process_list)
94 struct analyze_frames af;
96 long int swapped, present, total;
97 long int biggest = 0, second_biggest;
98 int count, processes = 0;
101 * walk through all processes, find the one with most present
104 list_for_each_entry(ps, &process_list->list, list) {
105 memset(&af, 0, sizeof(af));
106 af.ops.callback = count_pages;
109 bintree_walk(&pf->tree, &af.ops);
110 ps->pages_present = af.pages_present;
111 ps->pages_swapped = af.pages_swapped;
112 biggest = MAX(biggest, ps->pages_present + ps->pages_swapped);
115 printf(" in ram swapped pid name\n");
120 list_for_each_entry(ps, &process_list->list, list) {
122 present = ps->pages_present;
123 swapped = ps->pages_swapped;
124 total = present + swapped;
126 second_biggest = (total < biggest) &&
127 (second_biggest < total) ?
128 total : second_biggest;
130 if (total != biggest)
136 printf("%6lld %sB %6lld %sB %5d %s\n",
137 PAGE_TO_NICE(present), PAGE_TO_NICE_UNIT(present),
138 PAGE_TO_NICE(swapped), PAGE_TO_NICE_UNIT(swapped),
145 biggest = second_biggest;
149 printf("Total %d processes\n", processes);