|
|
1.1 ! root 1: /* ! 2: * libc/gen/monitor.c ! 3: * Runtime profiling. ! 4: */ ! 5: ! 6: /* ! 7: * monitor() is an interface to the profil() system call. ! 8: * It is called _profon() and _profoff() in crt/_prof.c. ! 9: * If 'low' is non-NULL, it starts the profiling. ! 10: * Otherwise, it dumps out statistics and turns off profiling. ! 11: * The region of memory profiled is from 'low' to 'high', ! 12: * not including 'high'. ! 13: * 'buff' is an array of 'blen' shorts into which profiling counts are stored. ! 14: * On the z8001, only stack monitoring and call counting are supported. ! 15: * After the profil() system call enables profiling, ! 16: * the system examines the user PC on each clock tick and bumps ! 17: * the appropriate counter in short buff[]. ! 18: */ ! 19: ! 20: #include <mon.h> ! 21: ! 22: #define MODE 0666 /* mon.out creation mode */ ! 23: ! 24: /* ! 25: * The call counting routine scount() references _mhdr.m.low_sp and _fnclst. ! 26: * The list pointed to by m_flst is never empty; ! 27: * it always has a dummy entry on the end which has m_link field NULL. ! 28: */ ! 29: static struct m_flst dummy[]; ! 30: struct m_flst *_fnclst = dummy; ! 31: struct m_hdr _mhdr; ! 32: static short *baddr; /* buffer address */ ! 33: ! 34: #ifndef Z8001 ! 35: monitor(low, high, buff, blen) caddr_t low, high; short buff[]; int blen; ! 36: /* monitor(low, high, buff, blen) vaddr_t low, high; short buff[]; int blen; */ ! 37: #else ! 38: monitor(low) ! 39: vaddr_t low; ! 40: #endif ! 41: { ! 42: /* if (low == (vaddr_t)0) { */ ! 43: if (low == (caddr_t)0) { ! 44: endmon(); ! 45: return; ! 46: } ! 47: ! 48: #ifndef Z8001 ! 49: baddr = buff; /* save buffer address for endmon() */ ! 50: if (blen >= (high-low)/2) { ! 51: blen = (high-low)/2; ! 52: _mhdr.m_scale = (unsigned short)-1; ! 53: } else ! 54: _mhdr.m_scale = ((long)blen << 17) / (high-low); ! 55: _mhdr.m_nbins = blen; ! 56: _mhdr.m_lowpc = low; ! 57: ! 58: /* Without getting incredibly involved, this will do */ ! 59: /* _mhdr.m_lowsp = ((vaddr_t)&blen) + sizeof(blen); */ ! 60: _mhdr.m_lowsp = ((caddr_t)&blen) + sizeof(blen); ! 61: #else ! 62: _mhdr.m_lowsp = 0xFFFEL; ! 63: #endif ! 64: _mhdr.m_hisp = _mhdr.m_lowsp; ! 65: ! 66: #ifndef Z8001 ! 67: /* Turn on profiling. */ ! 68: profil(buff, blen * sizeof *buff, low, _mhdr.m_scale); /* turn it on */ ! 69: #endif ! 70: } ! 71: ! 72: /* ! 73: * End profiling. ! 74: * Shut off system profiling and write the mon.out file. ! 75: * /bin/prof reads and interprets the mon.out. ! 76: */ ! 77: static ! 78: endmon() ! 79: { ! 80: register int fd, ! 81: cnt; ! 82: register struct m_flst *flp; ! 83: ! 84: #ifndef Z8001 ! 85: /* Shut off system profiling. */ ! 86: profil(NULL, 0, 0, 0); ! 87: #endif ! 88: ! 89: for (flp = _fnclst, cnt = 0; flp != dummy; flp = flp->m_link) ! 90: ++cnt; /* count function call entries */ ! 91: _mhdr.m_nfuncs = cnt; ! 92: ! 93: /* Create the mon.out file. */ ! 94: if ((fd = creat("mon.out", MODE)) < 0) ! 95: return; ! 96: write(fd, &_mhdr, sizeof _mhdr); /* write header */ ! 97: for (flp = _fnclst; flp != dummy; flp = flp->m_link) ! 98: write(fd, &flp->m_data, sizeof flp->m_data); /* write call data */ ! 99: #ifndef Z8001 ! 100: write(fd, baddr, _mhdr.m_nbins * sizeof *baddr); /* write bin data */ ! 101: #endif ! 102: close(fd); ! 103: } ! 104: ! 105: /* end of libc/gen/monitor.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.