make includes fix from trunk
[minix.git] / servers / is / dmp_vm.c
blob6cda9d5fb5b838433e4ac8dec0e34438c490792b
1 /* Debugging dump procedures for the VM server. */
3 #include "inc.h"
4 #include <sys/mman.h>
5 #include <minix/vm.h>
6 #include <timers.h>
7 #include "kernel/proc.h"
9 #define LINES 24
11 PRIVATE void print_region(struct vm_region_info *vri)
13 char c;
15 switch (vri->vri_seg) {
16 case T: c = 'T'; break;
17 case D: c = 'D'; break;
18 default: c = '?';
21 printf(" %c %08lx-%08lx %c%c%c %c (%lu kB)\n", c, vri->vri_addr,
22 vri->vri_addr + vri->vri_length,
23 (vri->vri_prot & PROT_READ) ? 'r' : '-',
24 (vri->vri_prot & PROT_WRITE) ? 'w' : '-',
25 (vri->vri_prot & PROT_EXEC) ? 'x' : '-',
26 (vri->vri_flags & MAP_SHARED) ? 's' : 'p',
27 vri->vri_length / 1024L);
30 PUBLIC void vm_dmp()
32 static struct proc proc[NR_TASKS + NR_PROCS];
33 static struct vm_region_info vri[LINES];
34 struct vm_stats_info vsi;
35 struct vm_usage_info vui;
36 static int prev_i = -1;
37 static vir_bytes prev_base = 0;
38 int r, r2, i, j, first, n = 0;
40 if (prev_i == -1) {
41 if ((r = vm_info_stats(&vsi)) != OK) {
42 printf("IS: warning: couldn't talk to VM: %d\n", r);
43 return;
46 printf("Total %u kB, free %u kB, largest free area %u kB\n",
47 vsi.vsi_total * (vsi.vsi_pagesize / 1024),
48 vsi.vsi_free * (vsi.vsi_pagesize / 1024),
49 vsi.vsi_largest * (vsi.vsi_pagesize / 1024));
50 n++;
51 printf("\n");
52 n++;
54 prev_i++;
57 if ((r = sys_getproctab(proc)) != OK) {
58 printf("IS: warning: couldn't get copy of process table: %d\n", r);
59 return;
62 for (i = prev_i; i < NR_TASKS + NR_PROCS && n < LINES; i++, prev_base = 0) {
63 if (i < NR_TASKS || isemptyp(&proc[i])) continue;
65 /* The first batch dump for each process contains a header line. */
66 first = prev_base == 0;
68 r = vm_info_region(proc[i].p_endpoint, vri, LINES - first, &prev_base);
70 if (r < 0) {
71 printf("Process %d (%s): error %d\n",
72 proc[i].p_endpoint, proc[i].p_name, r);
73 n++;
74 continue;
77 if (first) {
78 /* The entire batch should fit on the screen. */
79 if (n + 1 + r > LINES) {
80 prev_base = 0; /* restart on next page */
81 break;
84 if ((r2 = vm_info_usage(proc[i].p_endpoint, &vui)) != OK) {
85 printf("Process %d (%s): error %d\n",
86 proc[i].p_endpoint, proc[i].p_name, r2);
87 n++;
88 continue;
91 printf("Process %d (%s): total %lu kB, common %lu kB, "
92 "shared %lu kB\n",
93 proc[i].p_endpoint, proc[i].p_name,
94 vui.vui_total / 1024L, vui.vui_common / 1024L,
95 vui.vui_shared / 1024L);
96 n++;
99 for (j = 0; j < r; j++) {
100 print_region(&vri[j]);
101 n++;
104 if (n > LINES) printf("IS: internal error\n");
105 if (n == LINES) break;
107 /* This may have to wipe out the "--more--" from below. */
108 printf(" \n");
109 n++;
112 if (i >= NR_TASKS + NR_PROCS) {
113 i = -1;
114 prev_base = 0;
116 else printf("--more--\r");
117 prev_i = i;