Annotation of researchv9/cmd/emacs/stat_proc.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <pwd.h>
        !             3: 
        !             4: /* EMACS_MODES: c !fill */
        !             5: 
        !             6: /* emacs statistics file processor -- this program analyzes the
        !             7:  * emacs statistics file to print useful summaries of usage */
        !             8: 
        !             9: 
        !            10: float tscale = 60.0;
        !            11: 
        !            12: main(argc,argv)
        !            13: 
        !            14: int  argc;
        !            15: char **argv;
        !            16: 
        !            17: {
        !            18:        char inbuf[256];        
        !            19:        float usrtime,systime,ninch,noutc,nmkline,nbread,nbwrite,nbseek;
        !            20:        float tustime,tsytime,tinch,toutc,tmkline,tbread,tbwrite,tbseek = 0.0;
        !            21:        float tsessions = 0.0;
        !            22: #define MAXPEOPLE 100
        !            23:        
        !            24: 
        !            25:        int myusers[MAXPEOPLE];
        !            26:        int nusers = 0;
        !            27:        int people[MAXPEOPLE];
        !            28:        int sessions[MAXPEOPLE];
        !            29:        int starflag = 0;
        !            30: 
        !            31:        char xbuf[BUFSIZ];
        !            32:        char sysbuf[100];
        !            33:        
        !            34:        
        !            35:        register i;
        !            36:        int uid;
        !            37:        struct passwd *pwd;
        !            38:        struct passwd mpwd;
        !            39:        int pipes[2];
        !            40:        long pplid;
        !            41:        char mpname[20];
        !            42:        
        !            43:        if (argv[0][0]=='3') tscale = 100.0; /* 3b20 statistics */
        !            44: 
        !            45:        if (argc > 1) {
        !            46:                close(0);
        !            47:                open(argv[1],0);
        !            48:                setbuf(stdin,xbuf);
        !            49:                if (*argv[2] == '-') {
        !            50:                        starflag++;
        !            51:                        argc = 0;
        !            52:                        pipe(pipes);
        !            53:                        if(fork()) {
        !            54:                                        /* parent */
        !            55:                                close(0);
        !            56:                                close(pipes[1]);
        !            57:                                dup(pipes[0]);
        !            58:                                close(pipes[0]);
        !            59:                        } else {
        !            60:                                close(1);
        !            61:                                dup(pipes[1]);
        !            62:                                close(pipes[0]);
        !            63:                                close(pipes[1]);
        !            64:                                execl("/bin/sort","sort",argv[1],0);
        !            65:                        }
        !            66:                }
        !            67:                while (nusers+2 < argc) {
        !            68: 
        !            69:                        pwd = getpwnam(argv[nusers+2]);
        !            70:                        if (pwd == NULL) {
        !            71:                                pwd = &mpwd;
        !            72:                                sscanf(argv[nusers+2],"%d",&(pwd->pw_uid));
        !            73:                        }
        !            74:                        myusers[nusers++] = pwd->pw_uid;
        !            75:                }
        !            76:        }
        !            77:        myusers[nusers] = -2;
        !            78:        for (i = 0; i < MAXPEOPLE; i++) {
        !            79:                people[i] = -1;
        !            80:                sessions[i] = 0;
        !            81:        }
        !            82:        printf("\n\n EMACS version %s User Statistics:\n\n",argv[1]+1);
        !            83:        while (1) {
        !            84: next_entry:    if (gets(inbuf) == NULL) {
        !            85:                        starflag = 0;
        !            86: nextuid:               if (tinch == 0.0) tinch = 1.0;
        !            87:                        if (toutc == 0.0) toutc = 1.0;
        !            88:                        if (tmkline == 0.0) tmkline = 1.0;
        !            89:                        for (i = 0; people[i] != -1; i++) {
        !            90:                                pwd = getpwuid(people[i]);
        !            91:                                if (pwd == NULL) {
        !            92:                                        pwd = &mpwd;
        !            93:                                        pwd->pw_name = mpname;
        !            94:                                        pplid = (unsigned) people[i];
        !            95:                                        sprintf(mpname,"%ld",pplid);
        !            96:                                }
        !            97:                                printf("%20s: %d\n",pwd->pw_name,sessions[i]);
        !            98:                        }
        !            99:                        if (i > 1) printf("%20s: %f\n","all",tsessions);
        !           100:                        
        !           101:                        
        !           102:                        printf ("\nusertime: %.3f systime: %.3f input: %.0f output: %.0f\n",
        !           103:                                tustime,tsytime,tinch,toutc);
        !           104:                        printf ("makeline: %.0f read: %.0f write: %.0f, seek:  %.0f\n\n",
        !           105:                                tmkline,tbread,tbwrite,tbseek);
        !           106:                        printf ("seconds/inchar: %.6f  seconds/outchar: %.6f  outchar/inchar: %.3f \n",
        !           107:                        tustime/tinch,tustime/toutc,toutc/tinch);
        !           108:                        printf ("input chars/session: %.2f      time/session: %.3f\n\n",tinch/tsessions,tustime/tsessions);
        !           109:                        
        !           110:                        printf ("r-w-s/inchar:  %.6f    %.6f    %.6f\n",tbread/tinch,tbwrite/tinch,tbseek/tinch);
        !           111:                        printf ("r-w-s/outchar: %.6f    %.6f    %.6f\n",tbread/toutc,tbwrite/toutc,tbseek/toutc);
        !           112:                        printf ("r-w-s/mkline:  %.6f    %.6f    %.6f\n\n",tbread/tmkline,tbwrite/tmkline,tbseek/tmkline);
        !           113:                        printf("\n");
        !           114:                        if (starflag) {
        !           115:                                tbread = tbwrite = tbseek = tmkline = toutc = tinch = tustime = tsytime = 0.0;
        !           116:                                people[0] = -1;
        !           117:                                sessions[0] = 0;
        !           118:                                tsessions = 0.0;
        !           119:                                goto adduid;
        !           120:                        }
        !           121:                        printf("");
        !           122:                        exit(0);
        !           123:                }
        !           124: 
        !           125:                sscanf(inbuf,"%d %f %f %f %f %f %f %f %f",
        !           126:                        &uid,&usrtime,&systime,&ninch,&noutc,&nmkline,
        !           127:                        &nbread,&nbwrite,&nbseek);
        !           128:                if (uid < 0) uid += 65536;
        !           129:                if (starflag && (people[0] != -1) && (people[0] != uid)) goto nextuid;
        !           130: 
        !           131: adduid:                if (nusers > 0) {
        !           132:                        for (i = 0; i < nusers; i++) {
        !           133:                                if (myusers[i] == uid) break;
        !           134:                        }
        !           135:                        if (myusers[i] != uid) goto next_entry;
        !           136:                }
        !           137:                tbread += nbread;
        !           138:                tbwrite += nbwrite;
        !           139:                tbseek +=  nbseek;
        !           140:                tmkline += nmkline;
        !           141:                if (nmkline < 0) tmkline += 65536.0;
        !           142:                toutc += noutc;
        !           143:                tinch += ninch;
        !           144:                if (ninch < 0) tinch += 65336.0;
        !           145:                tsessions += 1;
        !           146:                for (i = 0; i < MAXPEOPLE; i++) {
        !           147:                        if (people[i] == uid) {
        !           148:                                sessions[i] += 1;
        !           149:                                i = MAXPEOPLE; /* break loop */
        !           150:                        }
        !           151:                        if (people[i]!= -1) continue;
        !           152:                        people[i] = uid;
        !           153:                        i--;            /* next iteration counts */
        !           154:                }
        !           155:                tsytime += (systime/tscale);
        !           156:                tustime += (usrtime/tscale);
        !           157:        }
        !           158: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.