# 2.11BSD#431 - /usr/src/lib/libc/pdp/csu/mon.c

##### Functions

    moncontrol        X
    monitor           X
    monstartup        X

##### Macros

    ARCDENSITY        X
    HISTFRACTION      X
    MINARCS           X
    PERROR            X

##### struct's

    cnt               X
    phdr              X

       1: /*
       2:  * Copyright (c) 1987 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #if defined(LIBC_SCCS) && !defined(lint)
       8: static char sccsid[] = "@(#)mon.c	5.5 (GTE) 3/23/92";
       9: #endif LIBC_SCCS and not lint
      10:
      11: #define ARCDENSITY  1   /* density of routines per 100 bytes */
      12: #define MINARCS     50  /* minimum number of counters */
      13: #define HISTFRACTION    8   /* fraction of text space for histograms */
      14:
      15:
      16: struct phdr {       /* mon.out header */
      17:     int *lpc;       /* low pc of histogramed text space */
      18:     int *hpc;       /* high pc */
      19:     int ncnt;       /* number of functions counted */
      20: };
      21:
      22: struct cnt {        /* function entry count structure */
      23:     int (*pc)();    /* address of profiled function */
      24:     long    ncall;      /* number of time function called */
      25: };
      26:
      27: static struct cnt *countbase;   /* next free cnt struct */
      28: static struct cnt *countend;    /* first address past cnt structs */
      29:
      30: static short    *s_sbuf;    /* start of histogram buffer */
      31: static unsigned s_bufsize;  /* size of histogram buffer (in chars) */
      32: static char *s_lowpc;   /* low pc for histgram recording */
      33: static unsigned s_scale;    /* histogram scale */
      34:
      35: #define PERROR(s)   write(2, s, sizeof(s)-1)
      36:
      37: monstartup(lowpc, highpc)
      38:     char *lowpc;
      39:     char *highpc;
      40: {
      41:     unsigned int cntsize, monsize;
      42:     char *buffer;
      43:     extern char *sbrk();
      44:     extern char *minbrk;
      45:
      46:     cntsize = (unsigned)(highpc - lowpc) * ARCDENSITY / 100;
      47:     if (cntsize < MINARCS)
      48:         cntsize = MINARCS;
      49:     monsize = (unsigned)(highpc - lowpc + HISTFRACTION - 1) / HISTFRACTION
      50:         + sizeof(struct phdr) + cntsize * sizeof(struct cnt);
      51:     monsize = (monsize + 1) & ~1;
      52:     buffer = sbrk(monsize);
      53:     if (buffer == (char *)-1) {
      54:         PERROR("monstartup: no space for monitor buffer(s)\n");
      55:         return;
      56:     }
      57:     minbrk = sbrk(0);
      58:     monitor(lowpc, highpc, buffer, monsize>>1, cntsize);
      59: }
      60:
      61: monitor(lowpc, highpc, buf, bufsize, cntsize)
      62:     char *lowpc, *highpc;
      63:     char *buf;      /* really (short *) but easier this way */
      64:     unsigned bufsize, cntsize;
      65: {
      66:     register unsigned o;
      67:     register struct phdr *php;
      68:     static char *sbuf;  /* saved base of profiling buffer */
      69:     static unsigned ssize;  /* saved buffer size */
      70:
      71:     if (lowpc == 0) {
      72:         moncontrol(0);
      73:         o = creat("mon.out", 0666);
      74:         write(o, sbuf, ssize);
      75:         close(o);
      76:         return;
      77:     }
      78:     bufsize *= sizeof(short);
      79:     if (bufsize < sizeof(struct phdr)+sizeof(struct cnt)+sizeof(short)) {
      80:         PERROR("monitor: buffer too small");
      81:         return;
      82:     }
      83:     sbuf = buf;
      84:     ssize = bufsize;
      85:
      86:     countbase = (struct cnt *)(buf + sizeof(struct phdr));
      87:     o = sizeof(struct phdr) + cntsize * sizeof(struct cnt);
      88:     if (o > bufsize) {
      89:         cntsize = (bufsize - sizeof(struct phdr))/sizeof(struct cnt);
      90:         o = sizeof(struct phdr) + cntsize * sizeof(struct cnt);
      91:     }
      92:     countend = (struct cnt *)(buf + o);
      93:
      94:     php = (struct phdr *)buf;
      95:     php->lpc = (int *)lowpc;
      96:     php->hpc = (int *)highpc;
      97:     php->ncnt = cntsize;
      98:
      99:     s_sbuf = (short *)countend;
     100:     s_bufsize = bufsize - o;
     101:     s_lowpc = lowpc;
     102:     o = highpc - lowpc;
     103:     if(s_bufsize < o)
     104:         o = ((long)s_bufsize << 16) / o;
     105:     else
     106:         o = 0xffff;
     107:     s_scale = o;
     108:     moncontrol(1);
     109: }
     110:
     111: /*
     112:  * Control profiling
     113:  */
     114: moncontrol(mode)
     115:     int mode;
     116: {
     117:     if (mode) {
     118:         /* start */
     119:         profil(s_sbuf, s_bufsize, s_lowpc, s_scale);
     120:     } else {
     121:         /* stop */
     122:         profil((char *)0, 0, 0, 0);
     123:     }
     124: }

#### Defined functions

moncontrol defined in line 114; used 2 times

- in line 72, 108

monitor defined in line 61; used 6 times

- in line 58
- in /usr/src/bin/csh/sh.c line 593
- in /usr/src/bin/tcsh/sh.c line 1201
- in /usr/src/lib/libc/pdp/csu/crt0.s line 130-134(2)
- in /usr/src/new/jove/jove.c line 156

monstartup defined in line 37; used 2 times

- in /usr/src/lib/libc/pdp/csu/crt0.s line 106-110(2)

#### Defined variables

countbase defined in line 27; used 1 times

- in line 86

countend defined in line 28; used 2 times

- in line 92, 99

s_bufsize defined in line 31; used 4 times

- in line 100-104(3), 119

s_lowpc defined in line 32; used 2 times

- in line 101, 119

s_sbuf defined in line 30; used 2 times

- in line 99, 119

s_scale defined in line 33; used 2 times

- in line 107, 119

sccsid defined in line 8; never used

#### Defined struct's

cnt defined in line 22; used 18 times

- in line 27-28(4), 50(2), 79(2), 86-92(10)

phdr defined in line 16; used 16 times

- in line 50(2), 67(2), 79(2), 86-94(10)

#### Defined macros

ARCDENSITY defined in line 11; used 1 times

- in line 46

HISTFRACTION defined in line 13; used 2 times

- in line 49(2)

MINARCS defined in line 12; used 2 times

- in line 47-48(2)

PERROR defined in line 35; used 2 times

- in line 54, 80

Last modified: 1992-03-31 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 722 |