void rusage(void) { double sys, user, idle; double per; sys = SECS(ru_stop.ru_stime) - SECS(ru_start.ru_stime); user = SECS(ru_stop.ru_utime) - SECS(ru_start.ru_utime); idle = timespent() - (sys + user); per = idle / timespent() * 100; if (!ftiming) ftiming = stderr; fprintf(ftiming, "real=%.2f sys=%.2f user=%.2f idle=%.2f stall=%.0f%% ", timespent(), sys, user, idle, per); fprintf(ftiming, "rd=%d wr=%d min=%d maj=%d ctx=%d\n", mine(ru_inblock), mine(ru_oublock), mine(ru_minflt), mine(ru_majflt), mine(ru_nvcsw) + mine(ru_nivcsw)); }
int main(int argc, char **argv) { long elaps[2]; ulong_t etime, stime; unsigned long mem; #ifdef uts float expand(); #else ulong_t expand(); #endif while (fread(&ab, sizeof(ab), 1, stdin) == 1) { if (!MYKIND(ab.ac_flag)) continue; pb.pt_uid = ab.ac_uid; CPYN(pb.pt_name, NULL); /* * approximate cpu P/NP split as same as elapsed time */ if ((etime = SECS(expand(ab.ac_etime))) == 0) etime = 1; stime = expand(ab.ac_stime) + expand(ab.ac_utime); mem = expand(ab.ac_mem); if(pnpsplit(ab.ac_btime, etime, elaps) == 0) { fprintf(stderr, "acctprc: could not calculate prime/non-prime hours\n"); exit(1); } pb.pt_cpu[0] = (double)stime * (double)elaps[0] / etime; pb.pt_cpu[1] = (stime > pb.pt_cpu[0])? stime - pb.pt_cpu[0] : 0; pb.pt_cpu[1] = stime - pb.pt_cpu[0]; if (stime) pb.pt_mem = (mem + stime - 1) / stime; else pb.pt_mem = 0; /* unlikely */ enter(&pb); } output(); exit(0); }
main() { unsigned char digcnt, // digit counter segcnt, // segment counter debounce, // debounce timer button, // button press timer cntcnt, // counter timer for speed up beep_cnt, // beep timer curval; // current value unsigned int tick_cnt, // delay timer powerdown, // powerdown timer tock_cnt; // tick-tock reload value OPTION = 1; PORTA = 0x0C; // Enable both buttons PORTB = 0x80; // set bits low TRISA = ~0x0F; // bits 0-3 are output TRISB = ~0x7F; // bits 0-6 are output #ifdef _16C71 ADCON1 = 3; #endif btn_1 = 0; btn_2 = 0; if((STATUS & TOUT)) { // power on-reset? rate = 60; // initialize rate beep_cnt = CYCLES; display = 1; powerdown = SECS(PWRDOWN); } else { // watchdog reset if(PORTB & 0x80) { // no buttons pressed - back to sleep TRISA = 0xFF; // hi-Z all pins TRISB = 0xFF; OPTION = 0xB; // WDT prescaled by 8 - about 150 ms asm(" sleep"); } display = 1; powerdown = SECS(PWRDOWN); } spkr = 0; debounce = 0; button = 0; counting = 0; tock_cnt = (unsigned)(60*1000000/INTVL)/rate; tick_cnt = tock_cnt; for(;;) { if(powerdown) if(--powerdown == 0) { display = 0; if(!spkr) { TRISA = 0xFF; // hi-Z all pins TRISB = 0xFF; OPTION = 0xB; // WDT prescaled by 8 - about 150 ms asm(" sleep"); } } curval = rate; digcnt = 0; do { segcnt = 1; // least sig. segment do { asm(" clrwdt"); while((TMR0 & 0x80) == 0) // sync with TMR0 continue; if(beep_cnt && wave[--beep_cnt]) PORTA ^= 0x8; // toggle speaker bit while(TMR0 & 0x80) continue; TMR0 = -DIVIDE; // reprogram TMR0 if(--tick_cnt == 0) { tick_cnt = tock_cnt; if(spkr) beep_cnt = CYCLES; } if(beep_cnt && wave[--beep_cnt]) PORTA ^= 0x8; // toggle speaker bit PORTA |= 0x7; // all digits off PORTA &= ~(1 << digcnt); // enable one digit PORTB = 0x80; // all segments off if(display) PORTB |= segcnt & digits[curval % 10]; // convert digit to seg pattern segcnt <<= 1; if(digcnt == 0 && !btn_2) { // scan button 1 if((PORTB & 0x80) == 0) { if(!btn_1) { debounce = 0; button = 0; cntcnt = 0; fast = 0; } btn_1 = 1; if(++debounce == DEBOUNCE) { debounce = 0; button++; } display = 1; powerdown = SECS(PWRDOWN); } else { if(!counting && btn_1 && button > 1 && button < COUNT/3) spkr = 0; btn_1 = 0; button = 0; } } else if(digcnt == 1 && !btn_1) { // scan button 2 if((PORTB & 0x80) == 0) { if(!btn_2) { debounce = 0; button = 0; cntcnt = 0; fast = 0; } btn_2 = 1; if(++debounce == DEBOUNCE) { debounce = 0; button++; } display = 1; powerdown = SECS(PWRDOWN); } else { if(!counting && btn_2 && button > 1 && button < COUNT/3) spkr = 1; btn_2 = 0; button = 0; } } if(button >= COUNT/3) { if(fast) { if(btn_1) rate -= 10; else rate += 10; } else { if(btn_1) rate--; else rate++; if(++cntcnt == 5) fast = 1; } if(rate < 10) rate = 10; if(rate > 200) rate = 200; counting = 1; button = 0; } } while(!(segcnt & 0x80)); if(counting && !btn_1 && !btn_2) { tock_cnt = (unsigned)(60*1000000/INTVL)/rate; counting = 0; } curval /= 10; } while(++digcnt != 3); } }
int main(int argc, char **argv) { long elaps[2]; ulong_t etime, stime; unsigned long mem; ulong_t expand(); int ver; /* version of acct struct */ int aread(); if ((ur = (struct urec *) calloc(a_usize, sizeof (struct urec))) == NULL) { fprintf(stderr, "acctpr1: Cannot allocate memory\n"); exit(3); } urlast = ur; if ((sr = (struct srec *) calloc(a_ssize, sizeof (struct srec))) == NULL) { fprintf(stderr, "acctpr1: Cannot allocate memory\n"); exit(3); } while (--argc > 0) { if (**++argv == '-') switch(*++*argv) { } else { readctmp(*argv); } } if (fread((char *)&ab, sizeof(struct acct), 1, stdin) != 1) exit(1); else if (ab.ac_flag & AEXPND) ver = 2; /* 4.0 acct structure */ else ver = 1; /* 3.x acct structure */ rewind(stdin); while (aread(ver) == 1) { if (!MYKIND(ab.ac_flag)) continue; pb.pt_uid = ab.ac_uid; CPYN(pb.pt_name, getname(ab.ac_uid, ab.ac_tty, ab.ac_btime)); /* * approximate cpu P/NP split as same as elapsed time */ if ((etime = SECS(expand(ab.ac_etime))) == 0) etime = 1; stime = expand(ab.ac_stime) + expand(ab.ac_utime); mem = expand(ab.ac_mem); if(pnpsplit(ab.ac_btime, etime, elaps) == 0) { fprintf(stderr, "acctprc1: could not calculate prime/non-prime hours\n"); exit(1); } pb.pt_cpu[0] = (double)stime * (double)elaps[0] / etime; pb.pt_cpu[1] = (stime > pb.pt_cpu[0])? stime - pb.pt_cpu[0] : 0; pb.pt_cpu[1] = stime - pb.pt_cpu[0]; if (stime) pb.pt_mem = (mem + stime - 1) / stime; else pb.pt_mem = 0; /* unlikely */ printf("%ld\t%.*s\t%lu\t%lu\t%u\n", pb.pt_uid, OUTPUT_NSZ, pb.pt_name, pb.pt_cpu[0], pb.pt_cpu[1], pb.pt_mem); } exit(0); }