]>
git.saurik.com Git - apple/libc.git/blob - gmon/gmon.c
ff2f4edc43aeadba15e1efee2b62f2455d6ce0f3
2 * Copyright (c) 1999, 2003, 2004, 2007, 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #error This module cannot be compiled with profiling
28 * Copyright (c) 1983, 1992, 1993
29 * The Regents of the University of California. All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * 2-Mar-90 Gregg Kellogg (gk) at NeXT
62 * Changed include of kern/mach.h to kern/mach_interface.h
64 * 1-May-90 Matthew Self (mself) at NeXT
65 * Added prototypes, and added casts to remove all warnings.
66 * Made all private data static.
67 * vm_deallocate old data defore vm_allocate'ing new data.
68 * Added new functions monoutput and monreset.
70 * 18-Dec-92 Development Environment Group at NeXT
71 * Added multiple profile areas, the ability to profile shlibs and the
72 * ability to profile rld loaded code. Moved the machine dependent mcount
73 * routine out of this source file.
75 * 13-Dec-92 Development Environment Group at NeXT
76 * Added support for dynamic shared libraries. Also removed the code that
77 * had been ifdef'ed out for profiling fixed shared libraries and
80 * 29-Aug-11 Vishal Patel (vishal_patel) at Apple
81 * Removed code that made calls to deprecated syscalls profil() and
82 * add_profil(). The syscalls are not supported since 2008 and planned
83 * to be completely removed soon. Similarly the monitor apis are also
88 #if defined(LIBC_SCCS) && !defined(lint)
89 static char sccsid
[] = "@(#)gmon.c 5.2 (Berkeley) 6/21/85";
93 * see profil(2) where this (SCALE_1_TO_1) is describe (incorrectly).
95 * The correct description: scale is a fixed point value with
96 * the binary point in the middle of the 32 bit value. (Bit 16 is
97 * 1, bit 15 is .5, etc.)
99 * Setting the scale to "1" (i.e. 0x10000), results in the kernel
100 * choosing the profile bucket address 1 to 1 with the pc sampled.
101 * Since buckets are shorts, if the profiling base were 0, then a pc
102 * of 0 increments bucket 0, a pc of 2 increments bucket 1, and a pc
103 * of 4 increments bucket 2.) (Actually, this seems a little bogus,
104 * 1 to 1 should map pc's to buckets -- that's probably what was
105 * intended from the man page, but historically....
107 #define SCALE_1_TO_1 0x10000L
109 #define MSG "No space for monitor buffer(s)\n"
114 #include <sys/types.h>
115 #include <sys/gmon.h>
116 #include <sys/param.h>
117 #include <sys/sysctl.h>
118 #include <mach/mach.h>
119 #include <mach-o/loader.h>
120 #include <mach-o/dyld.h>
121 #include <mach-o/getsect.h>
124 * These are defined in here and these declarations need to be moved to libc.h
125 * where the other declarations for the monitor(3) routines are declared.
129 extern void monaddition(
132 extern void moncount(
135 extern void monreset(
137 extern void monoutput(
138 const char *filename
);
140 static char profiling
= -1; /* tas (test and set) location for NeXT */
141 static char init
= 0; /* set while moninit() is being serviced */
143 static unsigned long order
= 0; /* call order */
146 /* the address range and size this mon struct refers to */
149 unsigned long textsize
;
150 /* the data structures to support the arc's and their counts */
151 unsigned short *froms
; /* froms is unsigned shorts indexing into tos */
154 /* the pc-sample buffer, it's size and scale */
156 long ssiz
; /* includes the gmonhdr_t */
159 static mon_t
*mon
= NULL
;
160 static unsigned long nmon
= 0;
166 return; // Deprecated api. do nothing
174 return; // Deprecated api. do nothing
178 * monaddtion() is used for adding additional pc ranges to profile. This is
179 * used for profiling dyld loaded code.
186 return; // Deprecated api. do nothing
193 return; // Deprecated api. do nothing
198 const char *filename
)
200 return; // Deprecated api. do nothing
209 int nfunc
) /* nfunc is not used; available for compatability only. */
211 return; // Deprecated api. do nothing
216 * profiling is what mcount checks to see if
217 * all the data structures are ready.
223 return; // Deprecated api. do nothing
231 return; //Deprecated api. do nothing