1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#ifndef _PROFILE_INTERNAL_H
31#define _PROFILE_INTERNAL_H
32
33
34
35
36
37
38#if !defined(MACH_KERNEL) && !defined(_KERNEL)
39#include <stdio.h>
40#endif
41
42
43
44
45
46#define SCALE_1_TO_1 0x10000L
47
48
49
50
51
52
53struct profile_vars;
54struct profile_stats;
55struct profile_md;
56struct profile_dci;
57struct profile_profil;
58struct callback;
59struct gprof_arc;
60struct prof_ext;
61
62
63
64
65
66typedef enum profile_type {
67 PROFILE_NONE,
68 PROFILE_GPROF,
69 PROFILE_PROF
70} profile_type_t;
71
72
73
74
75
76typedef enum profile_alloc_mem {
77 PROFILE_ALLOC_MEM_NO,
78 PROFILE_ALLOC_MEM_YES
79} profile_alloc_mem_t;
80
81
82
83
84
85typedef enum acontext_type {
86 ACONTEXT_PROF,
87 ACONTEXT_GPROF,
88 ACONTEXT_GFUNC,
89 ACONTEXT_MISC,
90 ACONTEXT_PROFIL,
91 ACONTEXT_DCI,
92 ACONTEXT_BASIC_BLOCK,
93 ACONTEXT_CALLBACK,
94 ACONTEXT_MAX = 32
95} acontext_type_t;
96
97#define ACONTEXT_FIRST ACONTEXT_PROF
98
99#define ACONTEXT_NAMES { \
100 "prof", \
101 "gprof", \
102 "gfunc", \
103 "misc", \
104 "profil", \
105 "dci", \
106 "bb", \
107 "callback", \
108 "#8", \
109 "#9", \
110 "#10", \
111 "#11", \
112 "#12", \
113 "#13", \
114 "#14", \
115 "#15", \
116 "#16", \
117 "#17", \
118 "#18", \
119 "#19", \
120 "#20", \
121 "#21", \
122 "#22", \
123 "#23", \
124 "#24", \
125 "#25", \
126 "#26", \
127 "#27", \
128 "#28", \
129 "#29", \
130 "#30", \
131 "#31", \
132 }
133
134
135
136
137
138typedef enum kgmon_control {
139 KGMON_UNUSED,
140 KGMON_GET_STATUS,
141 KGMON_GET_PROFILE_VARS,
142 KGMON_GET_PROFILE_STATS,
143 KGMON_GET_DEBUG,
144
145 KGMON_SET_PROFILE_ON = 50,
146 KGMON_SET_PROFILE_OFF,
147 KGMON_SET_PROFILE_RESET,
148 KGMON_SET_DEBUG_ON,
149 KGMON_SET_DEBUG_OFF
150} kgmon_control_t;
151
152#define KGMON_GET_MIN KGMON_GET_STATUS
153#define KGMON_GET_MAX KGMON_GET_DEBUG
154#define KGMON_SET_MIN KGMON_SET_PROFILE_ON
155#define KGMON_SET_MAX KGMON_SET_DEBUG_OFF
156
157#define ENCODE_KGMON(num, control, cpu_thread) \
158 ((num) = ((cpu_thread) << 8) | (control))
159
160#define DECODE_KGMON(num, control, cpu_thread) \
161do { \
162 control = (num) & 0xff; \
163 cpu_thread = (num) >> 8; \
164} while (0)
165
166#define LEGAL_KGMON(num) (((unsigned long)(num)) <= 0xffff)
167
168
169
170
171
172#include <profiling/machine/profile-md.h>
173
174
175
176
177
178#define ROUNDDOWN(x,y) (((x)/(y))*(y))
179#define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
180
181
182
183
184
185struct page_list {
186 void *first;
187 void *ptr;
188 struct page_list *next;
189 size_t bytes_free;
190 size_t bytes_allocated;
191 size_t num_allocations;
192};
193
194
195
196
197
198struct alloc_context {
199 struct alloc_context *next;
200 struct page_list *plist;
201 prof_lock_t lock;
202};
203
204
205
206
207
208
209
210#define STR_MAX 32
211
212struct callback {
213 void *sec_ptr;
214
215 size_t (*callback)(struct profile_vars *, struct callback *);
216 long sec_val1;
217 long sec_val2;
218 size_t sec_recsize;
219 size_t sec_length;
220 char sec_name[STR_MAX];
221};
222
223
224
225
226
227struct profile_profil {
228 prof_uptrint_t lowpc;
229 prof_uptrint_t highpc;
230 size_t text_len;
231 size_t profil_len;
232 size_t counter_size;
233 unsigned long scale;
234 unsigned long profil_unused[8];
235};
236
237
238
239
240
241struct profile_vars {
242 int major_version;
243 int minor_version;
244 size_t vars_size;
245 size_t plist_size;
246 size_t acontext_size;
247 size_t callback_size;
248 profile_type_t type;
249 const char *error_msg;
250 const char *filename;
251 char *str_ptr;
252
253#if !defined(MACH_KERNEL) && !defined(_KERNEL)
254 FILE *stream;
255 FILE *diag_stream;
256
257 size_t (*fwrite_func)(const void *, size_t, size_t, FILE *);
258#else
259 void *stream;
260 void *diag_stream;
261
262 size_t (*fwrite_func)(const void *, size_t, size_t, void *);
263#endif
264
265 size_t page_size;
266 size_t str_bytes;
267 size_t str_total;
268 long clock_ticks;
269
270
271 struct profile_profil profil_info;
272 HISTCOUNTER *profil_buf;
273
274
275 void (*output_init)(struct profile_vars *);
276 void (*output)(struct profile_vars *);
277 void *output_ptr;
278
279
280 struct alloc_context *acontext[(int)ACONTEXT_MAX];
281
282 void (*bogus_func)(void);
283 prof_uptrint_t vars_unused[63];
284
285
286 prof_flag_t init;
287 prof_flag_t active;
288 prof_flag_t do_profile;
289 prof_flag_t use_dci;
290
291 prof_flag_t use_profil;
292 prof_flag_t recursive_alloc;
293 prof_flag_t output_uarea;
294 prof_flag_t output_stats;
295
296 prof_flag_t output_clock;
297 prof_flag_t multiple_sections;
298 prof_flag_t have_bb;
299 prof_flag_t init_format;
300
301 prof_flag_t debug;
302 prof_flag_t check_funcs;
303 prof_flag_t flag_unused[62];
304
305 struct profile_stats stats;
306 struct profile_md md;
307};
308
309
310
311
312
313extern struct profile_vars _profile_vars;
314
315
316
317
318
319
320#if (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(lint)
321#define __attribute__(arg)
322#endif
323
324#if defined(_KERNEL) || defined(MACH_KERNEL)
325#define _profile_printf printf
326#else
327extern int _profile_printf(const char *, ...) __attribute__((format(printf,1,2)));
328#endif
329
330extern void *_profile_alloc_pages (size_t);
331extern void _profile_free_pages (void *, size_t);
332extern void _profile_error(struct profile_vars *);
333
334
335
336
337
338extern void _profile_md_init(struct profile_vars *, profile_type_t, profile_alloc_mem_t);
339extern int _profile_md_start(void);
340extern int _profile_md_stop(void);
341extern void *_profile_alloc(struct profile_vars *, size_t, acontext_type_t);
342extern size_t _gprof_write(struct profile_vars *, struct callback *);
343extern size_t _prof_write(struct profile_vars *, struct callback *);
344extern void _profile_update_stats(struct profile_vars *);
345extern void _profile_reset(struct profile_vars *);
346
347#if !defined(_KERNEL) && !defined(MACH_KERNEL)
348extern void _profile_print_stats(FILE *, const struct profile_stats *, const struct profile_profil *);
349extern void _profile_merge_stats(struct profile_stats *, const struct profile_stats *);
350#else
351
352
353
354
355
356extern long _profile_kgmon(int,
357 size_t,
358 long,
359 int,
360 void **,
361 void (*)(kgmon_control_t));
362#ifdef _KERNEL
363extern void kgmon_server_control(kgmon_control_t);
364
365#endif
366#endif
367
368#endif
369