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;
34 #define bintree_ops_to_af(bintree_ops) \
35 container_of((bintree_ops), struct analyze_frames, ops)
37 static void count_pages(struct bintree *b, struct bintree_ops *ops)
39 struct pageframe *pf = tree_to_pageframe(b);
40 struct analyze_frames *af = bintree_ops_to_af(ops);
46 if (list_empty(&pf->ml->list)) {
47 ml = list_to_maps_list(&pf->ml->list);
48 if (ml->map->pid == af->pid)
51 list_for_each_entry(ml, &pf->ml->list, list) {
52 if (ml->map->pid == af->pid)
61 else if (pf->page_swapped)
66 * print_page_stats - Prints system wide page stats
68 void print_page_stats(struct pageframe *pf)
70 struct analyze_frames af;
72 memset(&af, 0, sizeof(af));
74 af.ops.callback = count_pages;
76 count = bintree_walk(&pf->tree, &af.ops);
77 printf("present pages: %ld, %lld %sB\n"
78 "Swapped pages: %ld, %lld %sB\n"
79 "Total %ld physical pages, %lld %sB\n",
81 PAGE_TO_NICE(af.pages_present),
82 PAGE_TO_NICE_UNIT(af.pages_present),
84 PAGE_TO_NICE(af.pages_swapped),
85 PAGE_TO_NICE_UNIT(af.pages_swapped),
88 PAGE_TO_NICE_UNIT(count));
91 void print_pid_stats(struct pageframe *pf, struct process *process_list,
92 struct parse_opts *opts)
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 total pid");
116 if (opts->with_threads)
123 list_for_each_entry(ps, &process_list->list, list) {
125 present = ps->pages_present;
126 swapped = ps->pages_swapped;
127 total = present + swapped;
129 second_biggest = (total < biggest) &&
130 (second_biggest < total) ?
131 total : second_biggest;
133 if (total != biggest)
139 printf("%5lld %sB %5lld %sB %5lld %sB %5d ",
140 PAGE_TO_NICE(present), PAGE_TO_NICE_UNIT(present),
141 PAGE_TO_NICE(swapped), PAGE_TO_NICE_UNIT(swapped),
142 PAGE_TO_NICE(total), PAGE_TO_NICE_UNIT(total),
145 if (opts->with_threads)
146 printf("%5d ", ps->tid);
148 printf("%s\n", ps->name);
155 biggest = second_biggest;
159 printf("Total %d processes\n", processes);
162 static void _dump_process_maps(struct process *ps)
165 long int swapped, present, total;
166 long int biggest = 0, second_biggest;
167 int count, processes = 0;
169 list_for_each_entry(map, &ps->maps->list, list) {
170 biggest = MAX(biggest, map->pages_present + map->pages_swapped);
173 printf("process: [%d] %s\n", ps->pid, ps->name);
174 printf(" size in ram swapped total name\n");
178 list_for_each_entry(map, &ps->maps->list, list) {
180 present = map->pages_present;
181 swapped = map->pages_swapped;
182 total = present + swapped;
184 second_biggest = (total < biggest) &&
185 (second_biggest < total) ?
186 total : second_biggest;
188 if (total != biggest)
191 printf("%5lld %sB %5lld %sB %5lld %sB %5lld %sB %s\n",
192 NICE_DIV(map->size), NICE_UNIT(map->size),
193 PAGE_TO_NICE(present), PAGE_TO_NICE_UNIT(present),
194 PAGE_TO_NICE(swapped), PAGE_TO_NICE_UNIT(swapped),
195 PAGE_TO_NICE(total), PAGE_TO_NICE_UNIT(total),
202 if (count > 0 && biggest > 0) {
203 biggest = second_biggest;
209 void dump_process_maps(struct process *process_list)
213 if (list_empty(&process_list->list))
214 _dump_process_maps(process_list);
216 list_for_each_entry(ps, &process_list->list, list) {
217 _dump_process_maps(ps);