]> git.saurik.com Git - apple/libc.git/blame - gmon/gmon.c
Libc-1158.50.2.tar.gz
[apple/libc.git] / gmon / gmon.c
CommitLineData
e9ce8d39 1/*
34e8f829 2 * Copyright (c) 1999, 2003, 2004, 2007, 2008 Apple Inc. All rights reserved.
e9ce8d39
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
734aad71
A
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
11 * file.
12 *
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
e9ce8d39
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
734aad71
A
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.
e9ce8d39
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#if defined(PROFILE)
24#error This module cannot be compiled with profiling
25#endif
26
27/*-
28 * Copyright (c) 1983, 1992, 1993
29 * The Regents of the University of California. All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
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.
46 *
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
57 * SUCH DAMAGE.
58 */
59/*
60 * History
61 * 2-Mar-90 Gregg Kellogg (gk) at NeXT
62 * Changed include of kern/mach.h to kern/mach_interface.h
63 *
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.
69 *
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.
74 *
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
78 * objective-C.
ad3c9f2a
A
79 *
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
84 * deprecated.
85 *
e9ce8d39
A
86 */
87
88#if defined(LIBC_SCCS) && !defined(lint)
89static char sccsid[] = "@(#)gmon.c 5.2 (Berkeley) 6/21/85";
90#endif
91
92/*
93 * see profil(2) where this (SCALE_1_TO_1) is describe (incorrectly).
94 *
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.)
98 *
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....
106 */
107#define SCALE_1_TO_1 0x10000L
108
109#define MSG "No space for monitor buffer(s)\n"
110
111#include <stdio.h>
112#include <libc.h>
e9ce8d39
A
113#include <monitor.h>
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>
224c7076 121#include <mach-o/getsect.h>
e9ce8d39
A
122
123/*
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.
126 */
127extern void moninit(
128 void);
129extern void monaddition(
130 char *lowpc,
131 char *highpc);
132extern void moncount(
133 char *frompc,
134 char *selfpc);
135extern void monreset(
136 void);
137extern void monoutput(
138 const char *filename);
e9ce8d39 139
e9ce8d39
A
140void
141moninit(
142void)
143{
ad3c9f2a 144 return; // Deprecated api. do nothing
e9ce8d39
A
145}
146
147void
148monstartup(
149char *lowpc,
150char *highpc)
151{
ad3c9f2a 152 return; // Deprecated api. do nothing
e9ce8d39
A
153}
154
155/*
156 * monaddtion() is used for adding additional pc ranges to profile. This is
157 * used for profiling dyld loaded code.
158 */
159void
160monaddition(
161char *lowpc,
162char *highpc)
163{
ad3c9f2a 164 return; // Deprecated api. do nothing
e9ce8d39
A
165}
166
167void
168monreset(
169void)
170{
ad3c9f2a 171 return; // Deprecated api. do nothing
e9ce8d39
A
172}
173
174void
175monoutput(
176const char *filename)
177{
ad3c9f2a 178 return; // Deprecated api. do nothing
e9ce8d39
A
179}
180
181void
182monitor(
183char *lowpc,
184char *highpc,
185char *buf,
186int bufsiz,
187int nfunc) /* nfunc is not used; available for compatability only. */
188{
ad3c9f2a 189 return; // Deprecated api. do nothing
e9ce8d39
A
190}
191
192/*
193 * Control profiling
194 * profiling is what mcount checks to see if
195 * all the data structures are ready.
196 */
197void
198moncontrol(
199int mode)
200{
ad3c9f2a 201 return; // Deprecated api. do nothing
e9ce8d39
A
202}
203
204void
205moncount(
206char *frompc,
207char *selfpc)
208{
ad3c9f2a 209 return; //Deprecated api. do nothing
e9ce8d39 210}