Fixes to allow versionless packages on cd
[minix3.git] / servers / is / dmp_vm.c
blob6fafb5b05f3c92bfc43b3646b42510d1460df4b1
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, int *n)
13 static int vri_count, vri_prev_set;
14 static struct vm_region_info vri_prev;
15 char c;
16 int is_repeat;
18 /* part of a contiguous identical run? */
19 is_repeat =
20 vri &&
21 vri_prev_set &&
22 vri->vri_seg == vri_prev.vri_seg &&
23 vri->vri_prot == vri_prev.vri_prot &&
24 vri->vri_flags == vri_prev.vri_flags &&
25 vri->vri_length == vri_prev.vri_length &&
26 vri->vri_addr == vri_prev.vri_addr + vri_prev.vri_length;
27 if (vri) {
28 vri_prev_set = 1;
29 vri_prev = *vri;
30 } else {
31 vri_prev_set = 0;
33 if (is_repeat) {
34 vri_count++;
35 return;
38 if (vri_count > 0) {
39 printf(" (contiguously repeated %d more times)\n", vri_count);
40 (*n)++;
41 vri_count = 0;
44 /* NULL indicates the end of a list of mappings, nothing else to do */
45 if (!vri) return;
47 /* first in a run, print all info */
48 switch (vri->vri_seg) {
49 case T: c = 'T'; break;
50 case D: c = 'D'; break;
51 default: c = '?';
54 printf(" %c %08lx-%08lx %c%c%c %c (%lu kB)\n", c, vri->vri_addr,
55 vri->vri_addr + vri->vri_length,
56 (vri->vri_prot & PROT_READ) ? 'r' : '-',
57 (vri->vri_prot & PROT_WRITE) ? 'w' : '-',
58 (vri->vri_prot & PROT_EXEC) ? 'x' : '-',
59 (vri->vri_flags & MAP_IPC_SHARED) ? 's' : 'p',
60 vri->vri_length / 1024L);
61 (*n)++;
64 PUBLIC void vm_dmp()
66 static struct proc proc[NR_TASKS + NR_PROCS];
67 static struct vm_region_info vri[LINES];
68 struct vm_stats_info vsi;
69 struct vm_usage_info vui;
70 static int prev_i = -1;
71 static vir_bytes prev_base = 0;
72 int r, r2, i, j, first, n = 0;
74 if (prev_i == -1) {
75 if ((r = vm_info_stats(&vsi)) != OK) {
76 printf("IS: warning: couldn't talk to VM: %d\n", r);
77 return;
80 printf("Total %lu kB, free %lu kB, largest free %lu kB, cached %lu kB\n",
81 vsi.vsi_total * (vsi.vsi_pagesize / 1024),
82 vsi.vsi_free * (vsi.vsi_pagesize / 1024),
83 vsi.vsi_largest * (vsi.vsi_pagesize / 1024),
84 vsi.vsi_cached * (vsi.vsi_pagesize / 1024));
85 n++;
86 printf("\n");
87 n++;
89 prev_i++;
92 if ((r = sys_getproctab(proc)) != OK) {
93 printf("IS: warning: couldn't get copy of process table: %d\n", r);
94 return;
97 for (i = prev_i; i < NR_TASKS + NR_PROCS && n < LINES; i++, prev_base = 0) {
98 if (i < NR_TASKS || isemptyp(&proc[i])) continue;
100 /* The first batch dump for each process contains a header line. */
101 first = prev_base == 0;
103 r = vm_info_region(proc[i].p_endpoint, vri, LINES - first, &prev_base);
105 if (r < 0) {
106 printf("Process %d (%s): error %d\n",
107 proc[i].p_endpoint, proc[i].p_name, r);
108 n++;
109 continue;
112 if (first) {
113 /* The entire batch should fit on the screen. */
114 if (n + 1 + r > LINES) {
115 prev_base = 0; /* restart on next page */
116 break;
119 if ((r2 = vm_info_usage(proc[i].p_endpoint, &vui)) != OK) {
120 printf("Process %d (%s): error %d\n",
121 proc[i].p_endpoint, proc[i].p_name, r2);
122 n++;
123 continue;
126 printf("Process %d (%s): total %lu kB, common %lu kB, "
127 "shared %lu kB\n",
128 proc[i].p_endpoint, proc[i].p_name,
129 vui.vui_total / 1024L, vui.vui_common / 1024L,
130 vui.vui_shared / 1024L);
131 n++;
134 while (r > 0) {
135 for (j = 0; j < r; j++) {
136 print_region(&vri[j], &n);
139 if (LINES - n - 1 <= 0) break;
140 r = vm_info_region(proc[i].p_endpoint, vri, LINES - n - 1,
141 &prev_base);
143 if (r < 0) {
144 printf("Process %d (%s): error %d\n",
145 proc[i].p_endpoint, proc[i].p_name, r);
146 n++;
149 print_region(NULL, &n);
151 if (n > LINES) printf("IS: internal error\n");
152 if (n == LINES) break;
154 /* This may have to wipe out the "--more--" from below. */
155 printf(" \n");
156 n++;
159 if (i >= NR_TASKS + NR_PROCS) {
160 i = -1;
161 prev_base = 0;
163 else printf("--more--\r");
164 prev_i = i;