io statistics
[unix-history] / usr / src / usr.bin / window / cmd2.c
CommitLineData
708ccf0a 1#ifndef lint
39b49130 2static char *sccsid = "@(#)cmd2.c 1.6 83/07/27";
708ccf0a
EW
3#endif
4
5#include "defs.h"
6
7struct ww *getwin();
8struct ww *openwin();
9char *strtime();
10
11dohelp()
12{
13 register struct ww *w;
14
8c4fb896
EW
15 if ((w = openwin(22, "Help")) == 0) {
16 wwputs("Can't open help window. ", cmdwin);
708ccf0a 17 return;
8c4fb896 18 }
708ccf0a
EW
19 wwprintf(w, "The escape character is ^P, which gets you into command mode.\r\n");
20 wwprintf(w, "The commands are:\r\n");
093074d6
EW
21 wwprintf(w, "[1-9] Select window [1-9] and exit command mode.\r\n");
22 wwprintf(w, "%%[1-9] Select window [1-9].\r\n");
23 wwprintf(w, "c[1-9] Close window [1-9].\r\n");
24 wwprintf(w, "C Close all empty windows.\r\n");
25 wwprintf(w, "Z Close all windows.\r\n");
26 wwprintf(w, "Q Show all windows in sequence.\r\n");
27 wwprintf(w, "R Force refresh after every newline (current window only).\r\n");
28 wwprintf(w, "r Don't refresh every line.\r\n");
29 wwprintf(w, "w Open a new window.\r\n");
30 wwprintf(w, "^U Scroll up.\r\n");
31 wwprintf(w, "^D Scroll down.\r\n");
32 wwprintf(w, "[hjkl] Move cursor [left, down, up, right].\r\n");
33 /*
34 wwprintf(w, "s Print IO statistics.\r\n");
35 wwprintf(w, "t Print resource usage of this program.\r\n");
36 wwprintf(w, "T Print resource usage of children.\r\n");
37 */
38 wwprintf(w, "escape Exit command mode.\r\n");
39 wwprintf(w, "^L Redraw screen.\r\n");
40 wwprintf(w, "^Z Suspend.\r\n");
41 wwprintf(w, ". Quit.\r\n");
b4be6cd6 42 waitnl(w);
708ccf0a
EW
43 closewin(w);
44}
45
46dotime(flag)
47{
48 register struct ww *w;
49 struct rusage rusage;
50 struct timeval timeval;
51
c417b691 52 if ((w = openwin(8, "Timing and Resource Usage")) == 0) {
8c4fb896 53 wwputs("Can't open time window. ", cmdwin);
708ccf0a 54 return;
8c4fb896 55 }
708ccf0a
EW
56
57 gettimeofday(&timeval, &timezone);
58 timeval.tv_sec -= starttime.tv_sec;
59 if ((timeval.tv_usec -= starttime.tv_usec) < 0) {
60 timeval.tv_sec--;
61 timeval.tv_usec += 1000000;
62 }
63 getrusage(flag, &rusage);
64
65 wwprintf(w, "time\t\tutime\t\tstime\t\tmaxrss\tixrss\tidrss\tisrss\r\n");
66 wwprintf(w, "%-16s", strtime(&timeval));
67 wwprintf(w, "%-16s", strtime(&rusage.ru_utime));
68 wwprintf(w, "%-16s", strtime(&rusage.ru_stime));
69 wwprintf(w, "%D\t%D\t%D\t%D\r\n",
70 rusage.ru_maxrss, rusage.ru_ixrss,
71 rusage.ru_idrss, rusage.ru_isrss);
72 wwprintf(w, "minflt\tmajflt\tnswap\tinblk\toublk\tmsgsnd\tmsgrcv\tnsigs\tnvcsw\tnivcsw\r\n");
73 wwprintf(w, "%D\%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\r\n",
74 rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap,
75 rusage.ru_inblock, rusage.ru_oublock,
76 rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals,
77 rusage.ru_nvcsw, rusage.ru_nivcsw);
78
b4be6cd6 79 waitnl(w);
708ccf0a
EW
80 closewin(w);
81}
82
83char *
84strtime(t)
85register struct timeval *t;
86{
87 char fill = 0;
88 static char buf[20];
89 register char *p = buf;
90
91 if (t->tv_sec > 60*60) {
92 sprintf(p, "%D:", t->tv_sec / (60*60));
93 while (*p++)
94 ;
95 p--;
96 t->tv_sec %= 60*60;
97 fill++;
98 }
99 if (t->tv_sec > 60) {
100 sprintf(p, fill ? "%02D:" : "%D:", t->tv_sec / 60);
101 while (*p++)
102 ;
103 p--;
104 t->tv_sec %= 60;
105 fill++;
106 }
107 sprintf(p, fill ? "%02D.%02d" : "%D.%02D",
108 t->tv_sec, t->tv_usec / 10000);
109 return buf;
110}
111
c417b691
EW
112dostat()
113{
114 register struct ww *w;
115
39b49130 116 if ((w = openwin(6, "IO Statics")) == 0) {
c417b691
EW
117 wwputs("Can't open statistics window. ", cmdwin);
118 return;
119 }
39b49130
EW
120 wwprintf(w, "nread\tnreadz\tnreade\tnreadc\tnwrite\tnwritec\r\n");
121 wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\r\n",
122 nread, nreadz, nreade, nreadc, wwnwrite, wwnwritec);
c417b691
EW
123 waitnl(w);
124 closewin(w);
125}
126
8c4fb896
EW
127doquit()
128{
093074d6 129 wwputs("Really quit [yn]? ", cmdwin);
8c4fb896
EW
130 wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
131 while (bpeekc() < 0)
132 bread();
133 if (bgetc() == 'y') {
134 wwputs("Yes", cmdwin);
135 quit++;
136 } else
137 wwputs("\r\n", cmdwin);
138}
139
708ccf0a
EW
140struct ww *
141openwin(nrow, label)
142char *label;
143{
144 register struct ww *w;
145
c417b691 146 if ((w = wwopen(WW_NONE, 0, nrow, wwncol, 1, 0)) == 0)
708ccf0a 147 return 0;
708ccf0a
EW
148 wwframe(w);
149 wwlabel(w, label, WINVERSE);
8c4fb896 150 wwsetcurwin(w);
708ccf0a
EW
151 return w;
152}
153
b4be6cd6 154waitnl(w)
708ccf0a
EW
155register struct ww *w;
156{
8c4fb896 157 wwsetcurwin(w);
708ccf0a
EW
158 wwprintf(w, "\r\nType return to continue: ");
159 wwsetcursor(WCurRow(w->ww_win), WCurCol(w->ww_win));
b4be6cd6 160 while (bgetc() < 0)
708ccf0a 161 bread();
b4be6cd6
EW
162}
163
164closewin(w)
165register struct ww *w;
166{
708ccf0a 167 wwclose(w);
8c4fb896 168 wwsetcurwin(cmdwin);
708ccf0a 169}