175 const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %5u %2u %2u %2u %2u\n";
176 unsigned int tog=0; /* toggle switch for cleaner code */
177 unsigned int i;
178 unsigned int hz = Hertz; 179 unsigned int running,blocked,dummy_1,dummy_2; 180 jiff cpu_use[2], cpu_nic[2], cpu_sys[2], cpu_idl[2], cpu_iow[2], cpu_xxx[2], cpu_yyy[2]; 181 jiff duse, dsys, didl, diow, Div, divo2; 182 unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2]; 183 unsigned int intr[2], ctxt[2]; 184 unsigned int sleep_half;
185 unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
186 int debt = 0; // handle idle ticks running backwards
188 sleep_half=(sleep_time/2);
189 new_header();
190 meminfo();
192 getstat(cpu_use,cpu_nic,cpu_sys,cpu_idl,cpu_iow,cpu_xxx,cpu_yyy, 193 pgpgin,pgpgout,pswpin,pswpout, 194 intr,ctxt, 195 &running,&blocked, 196 &dummy_1, &dummy_2);
198 duse= *cpu_use + *cpu_nic;
カーネルコードの実行に使用した時間 (システム時間)。
199 dsys= *cpu_sys + *cpu_xxx + *cpu_yyy;
200 didl= *cpu_idl; 201 diow= *cpu_iow; 202 Div= duse+dsys+didl+diow; 203 divo2= Div/2UL;
204 printf(format,
205 running, blocked,
206 unitConvert(kb_swap_used), unitConvert(kb_main_free), 207 unitConvert(a_option?kb_inactive:kb_main_buffers), 208 unitConvert(a_option?kb_active:kb_main_cached),
209 (unsigned)( (*pswpin * unitConvert(kb_per_page) * hz + divo2) / Div ), 210 (unsigned)( (*pswpout * unitConvert(kb_per_page) * hz + divo2) / Div ),
211 (unsigned)( (*pgpgin * hz + divo2) / Div ), 212 (unsigned)( (*pgpgout * hz + divo2) / Div ),
213 (unsigned)( (*intr * hz + divo2) / Div ), 214 (unsigned)( (*ctxt * hz + divo2) / Div ),
215 (unsigned)( (100*duse + divo2) / Div ), 216 (unsigned)( (100*dsys + divo2) / Div ), 217 (unsigned)( (100*didl + divo2) / Div ), 218 (unsigned)( (100*diow + divo2) / Div )
221 for(i=1;i<num_updates;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */
222 sleep(sleep_time);
223 if (moreheaders && ((i%height)==0)) new_header();
224 tog= !tog;
226 meminfo();
228 getstat(cpu_use+tog,cpu_nic+tog,cpu_sys+tog,cpu_idl+tog,cpu_iow+tog,cpu_xxx+tog,cpu_yyy+
228 tog,
229 pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog,
230 intr+tog,ctxt+tog,
231 &running,&blocked,
232 &dummy_1,&dummy_2);
233
234 duse= cpu_use[tog]-cpu_use[!tog] + cpu_nic[tog]-cpu_nic[!tog];
235 dsys= cpu_sys[tog]-cpu_sys[!tog] + cpu_xxx[tog]-cpu_xxx[!tog] + cpu_yyy[tog]-cpu_yyy[!to
235 g];
236 didl= cpu_idl[tog]-cpu_idl[!tog];
237 diow= cpu_iow[tog]-cpu_iow[!tog];
238
239 /* idle can run backwards for a moment -- kernel "feature" */
240 if(debt){
241 didl = (int)didl + debt;
242 debt = 0;
243 }
244 if( (int)didl < 0 ){
245 debt = (int)didl;
246 didl = 0;
247 }
248
249 Div= duse+dsys+didl+diow;
250 divo2= Div/2UL;
251 printf(format,
252 running, blocked,
253 unitConvert(kb_swap_used),unitConvert(kb_main_free),
254 unitConvert(a_option?kb_inactive:kb_main_buffers),
255 unitConvert(a_option?kb_active:kb_main_cached),
256 (unsigned)( ( (pswpin [tog] - pswpin [!tog])*unitConvert(kb_per_page)+sleep_half
256 )/sleep_time ), /*si*/
257 (unsigned)( ( (pswpout[tog] - pswpout[!tog])*unitConvert(kb_per_page)+sleep_half
257 )/sleep_time ), /*so*/
258 (unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time
258 ), /*bi*/
259 (unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time
259 ), /*bo*/
260 (unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time
260 ), /*in*/
261 (unsigned)( ( ctxt [tog] - ctxt [!tog] +sleep_half )/sleep_time
261 ), /*cs*/
262 (unsigned)( (100*duse+divo2)/Div ), /*us*/
263 (unsigned)( (100*dsys+divo2)/Div ), /*sy*/
264 (unsigned)( (100*didl+divo2)/Div ), /*id*/
265 (unsigned)( (100*diow+divo2)/Div ) /*wa*/
266 );
267 }
268 }
174 static void new_format(void) {
175 const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %5u %2u %2u %2u %2u\n
175 ";
176 unsigned int tog=0; /* toggle switch for cleaner code */
177 unsigned int i;
178 unsigned int hz = Hertz;
179 unsigned int running,blocked,dummy_1,dummy_2;
180 jiff cpu_use[2], cpu_nic[2], cpu_sys[2], cpu_idl[2], cpu_iow[2], cpu_xxx[2], cpu_yyy[2];
181 jiff duse, dsys, didl, diow, Div, divo2;
182 unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
183 unsigned int intr[2], ctxt[2];
184 unsigned int sleep_half;
185 unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
186 int debt = 0; // handle idle ticks running backwards
187
188 sleep_half=(sleep_time/2);
189 new_header();
190 meminfo();
191
192 getstat(cpu_use,cpu_nic,cpu_sys,cpu_idl,cpu_iow,cpu_xxx,cpu_yyy,
193 pgpgin,pgpgout,pswpin,pswpout,
194 intr,ctxt,
195 &running,&blocked,
196 &dummy_1, &dummy_2);
197
198 duse= *cpu_use + *cpu_nic;
199 dsys= *cpu_sys + *cpu_xxx + *cpu_yyy;
200 didl= *cpu_idl;
201 diow= *cpu_iow;
202 Div= duse+dsys+didl+diow;
203 divo2= Div/2UL;
204 printf(format,
205 running, blocked,
206 unitConvert(kb_swap_used), unitConvert(kb_main_free),
207 unitConvert(a_option?kb_inactive:kb_main_buffers),
208 unitConvert(a_option?kb_active:kb_main_cached),
209 (unsigned)( (*pswpin * unitConvert(kb_per_page) * hz + divo2) / Div ),
210 (unsigned)( (*pswpout * unitConvert(kb_per_page) * hz + divo2) / Div ),
211 (unsigned)( (*pgpgin * hz + divo2) / Div ),
212 (unsigned)( (*pgpgout * hz + divo2) / Div ),
213 (unsigned)( (*intr * hz + divo2) / Div ),
214 (unsigned)( (*ctxt * hz + divo2) / Div ),
215 (unsigned)( (100*duse + divo2) / Div ),
216 (unsigned)( (100*dsys + divo2) / Div ),
217 (unsigned)( (100*didl + divo2) / Div ),
218 (unsigned)( (100*diow + divo2) / Div )
219 );
220
221 for(i=1;i<num_updates;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */
222 sleep(sleep_time);
223 if (moreheaders && ((i%height)==0)) new_header();
224 tog= !tog;
225
226 meminfo();
227
228 getstat(cpu_use+tog,cpu_nic+tog,cpu_sys+tog,cpu_idl+tog,cpu_iow+tog,cpu_xxx+tog,cpu_yyy+
228 tog,
229 pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog,
230 intr+tog,ctxt+tog,
231 &running,&blocked,
232 &dummy_1,&dummy_2);
233
234 duse= cpu_use[tog]-cpu_use[!tog] + cpu_nic[tog]-cpu_nic[!tog];
235 dsys= cpu_sys[tog]-cpu_sys[!tog] + cpu_xxx[tog]-cpu_xxx[!tog] + cpu_yyy[tog]-cpu_yyy[!to
235 g];
236 didl= cpu_idl[tog]-cpu_idl[!tog];
237 diow= cpu_iow[tog]-cpu_iow[!tog];
238
239 /* idle can run backwards for a moment -- kernel "feature" */
240 if(debt){
241 didl = (int)didl + debt;
242 debt = 0;
243 }
244 if( (int)didl < 0 ){
245 debt = (int)didl;
246 didl = 0;
247 }
248
249 Div= duse+dsys+didl+diow;
250 divo2= Div/2UL;
251 printf(format,
252 running, blocked,
253 unitConvert(kb_swap_used),unitConvert(kb_main_free),
254 unitConvert(a_option?kb_inactive:kb_main_buffers),
255 unitConvert(a_option?kb_active:kb_main_cached),
256 (unsigned)( ( (pswpin [tog] - pswpin [!tog])*unitConvert(kb_per_page)+sleep_half
256 )/sleep_time ), /*si*/
257 (unsigned)( ( (pswpout[tog] - pswpout[!tog])*unitConvert(kb_per_page)+sleep_half
257 )/sleep_time ), /*so*/
258 (unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time
258 ), /*bi*/
259 (unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time
259 ), /*bo*/
260 (unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time
260 ), /*in*/
261 (unsigned)( ( ctxt [tog] - ctxt [!tog] +sleep_half )/sleep_time
261 ), /*cs*/
262 (unsigned)( (100*duse+divo2)/Div ), /*us*/
263 (unsigned)( (100*dsys+divo2)/Div ), /*sy*/
264 (unsigned)( (100*didl+divo2)/Div ), /*id*/
265 (unsigned)( (100*diow+divo2)/Div ) /*wa*/
266 );
267 }
268 }
*1 sleep_time = atoi(*argv