gmon.c (48838) | gmon.c (55837) |
---|---|
1/*- 2 * Copyright (c) 1983, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. | 1/*- 2 * Copyright (c) 1983, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. |
32 * 33 * $FreeBSD: head/lib/libc/gmon/gmon.c 55837 2000-01-12 09:23:48Z jasone $ |
|
32 */ 33 34#if !defined(lint) && defined(LIBC_SCCS) 35static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93"; 36#endif 37 38#include <sys/param.h> 39#include <sys/time.h> --- 15 unchanged lines hidden (view full) --- 55extern char *__progname; 56 57struct gmonparam _gmonparam = { GMON_PROF_OFF }; 58 59static int s_scale; 60/* see profil(2) where this is describe (incorrectly) */ 61#define SCALE_1_TO_1 0x10000L 62 | 34 */ 35 36#if !defined(lint) && defined(LIBC_SCCS) 37static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93"; 38#endif 39 40#include <sys/param.h> 41#include <sys/time.h> --- 15 unchanged lines hidden (view full) --- 57extern char *__progname; 58 59struct gmonparam _gmonparam = { GMON_PROF_OFF }; 60 61static int s_scale; 62/* see profil(2) where this is describe (incorrectly) */ 63#define SCALE_1_TO_1 0x10000L 64 |
63#define ERR(s) write(2, s, sizeof(s)) | 65#define ERR(s) _libc_write(2, s, sizeof(s)) |
64 65void moncontrol __P((int)); 66static int hertz __P((void)); 67 68void 69monstartup(lowpc, highpc) 70 u_long lowpc; 71 u_long highpc; --- 93 unchanged lines hidden (view full) --- 165 if (clockinfo.hz != 0) 166 clockinfo.profhz = clockinfo.hz; 167 else 168 clockinfo.profhz = hertz(); 169 } 170 171 moncontrol(0); 172 snprintf(outname,sizeof(outname),"%s.gmon",__progname); | 66 67void moncontrol __P((int)); 68static int hertz __P((void)); 69 70void 71monstartup(lowpc, highpc) 72 u_long lowpc; 73 u_long highpc; --- 93 unchanged lines hidden (view full) --- 167 if (clockinfo.hz != 0) 168 clockinfo.profhz = clockinfo.hz; 169 else 170 clockinfo.profhz = hertz(); 171 } 172 173 moncontrol(0); 174 snprintf(outname,sizeof(outname),"%s.gmon",__progname); |
173 fd = open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666); | 175 fd = _libc_open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666); |
174 if (fd < 0) { 175 warnx("_mcleanup: %s - %s",outname,strerror(errno)); 176 return; 177 } 178#ifdef DEBUG | 176 if (fd < 0) { 177 warnx("_mcleanup: %s - %s",outname,strerror(errno)); 178 return; 179 } 180#ifdef DEBUG |
179 log = open("gmon.log", O_CREAT|O_TRUNC|O_WRONLY, 0664); | 181 log = _libc_open("gmon.log", O_CREAT|O_TRUNC|O_WRONLY, 0664); |
180 if (log < 0) { 181 perror("_mcleanup: gmon.log"); 182 return; 183 } 184 len = sprintf(buf, "[mcleanup1] kcount 0x%x ssiz %d\n", 185 p->kcount, p->kcountsize); | 182 if (log < 0) { 183 perror("_mcleanup: gmon.log"); 184 return; 185 } 186 len = sprintf(buf, "[mcleanup1] kcount 0x%x ssiz %d\n", 187 p->kcount, p->kcountsize); |
186 write(log, buf, len); | 188 _libc_write(log, buf, len); |
187#endif 188 hdr = (struct gmonhdr *)&gmonhdr; 189 hdr->lpc = p->lowpc; 190 hdr->hpc = p->highpc; 191 hdr->ncnt = p->kcountsize + sizeof(gmonhdr); 192 hdr->version = GMONVERSION; 193 hdr->profrate = clockinfo.profhz; | 189#endif 190 hdr = (struct gmonhdr *)&gmonhdr; 191 hdr->lpc = p->lowpc; 192 hdr->hpc = p->highpc; 193 hdr->ncnt = p->kcountsize + sizeof(gmonhdr); 194 hdr->version = GMONVERSION; 195 hdr->profrate = clockinfo.profhz; |
194 write(fd, (char *)hdr, sizeof *hdr); 195 write(fd, p->kcount, p->kcountsize); | 196 _libc_write(fd, (char *)hdr, sizeof *hdr); 197 _libc_write(fd, p->kcount, p->kcountsize); |
196 endfrom = p->fromssize / sizeof(*p->froms); 197 for (fromindex = 0; fromindex < endfrom; fromindex++) { 198 if (p->froms[fromindex] == 0) 199 continue; 200 201 frompc = p->lowpc; 202 frompc += fromindex * p->hashfraction * sizeof(*p->froms); 203 for (toindex = p->froms[fromindex]; toindex != 0; 204 toindex = p->tos[toindex].link) { 205#ifdef DEBUG 206 len = sprintf(buf, 207 "[mcleanup2] frompc 0x%x selfpc 0x%x count %d\n" , 208 frompc, p->tos[toindex].selfpc, 209 p->tos[toindex].count); | 198 endfrom = p->fromssize / sizeof(*p->froms); 199 for (fromindex = 0; fromindex < endfrom; fromindex++) { 200 if (p->froms[fromindex] == 0) 201 continue; 202 203 frompc = p->lowpc; 204 frompc += fromindex * p->hashfraction * sizeof(*p->froms); 205 for (toindex = p->froms[fromindex]; toindex != 0; 206 toindex = p->tos[toindex].link) { 207#ifdef DEBUG 208 len = sprintf(buf, 209 "[mcleanup2] frompc 0x%x selfpc 0x%x count %d\n" , 210 frompc, p->tos[toindex].selfpc, 211 p->tos[toindex].count); |
210 write(log, buf, len); | 212 _libc_write(log, buf, len); |
211#endif 212 rawarc.raw_frompc = frompc; 213 rawarc.raw_selfpc = p->tos[toindex].selfpc; 214 rawarc.raw_count = p->tos[toindex].count; | 213#endif 214 rawarc.raw_frompc = frompc; 215 rawarc.raw_selfpc = p->tos[toindex].selfpc; 216 rawarc.raw_count = p->tos[toindex].count; |
215 write(fd, &rawarc, sizeof rawarc); | 217 _libc_write(fd, &rawarc, sizeof rawarc); |
216 } 217 } | 218 } 219 } |
218 close(fd); | 220 _libc_close(fd); |
219} 220 221/* 222 * Control profiling 223 * profiling is what mcount checks to see if 224 * all the data structures are ready. 225 */ 226void --- 35 unchanged lines hidden --- | 221} 222 223/* 224 * Control profiling 225 * profiling is what mcount checks to see if 226 * all the data structures are ready. 227 */ 228void --- 35 unchanged lines hidden --- |