1/*
2 * Copyright (c) 2011 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29/* wrapper around kdebug */
30
31#include <sys/kdebug.h>
32
33/* KDEBUG codes */
34#define PERF_CODE(SubClass, code) KDBG_CODE(DBG_PERF, SubClass, code)
35
36/* broad sub-classes */
37#define PERF_GENERIC    (0)
38#define PERF_THREADINFO (1)
39#define PERF_CALLSTACK  (2)
40#define PERF_TIMER      (3)
41#define PERF_PET        (4)
42#define PERF_AST        (5)  /* not confusing at all */
43
44/* sub-class codes */
45#define PERF_GEN_CODE(code) PERF_CODE(PERF_GENERIC, code)
46#define PERF_GEN_EVENT      PERF_GEN_CODE(0)
47
48#define PERF_TI_CODE(code) PERF_CODE(PERF_THREADINFO, code)
49#define PERF_TI_SAMPLE     PERF_TI_CODE(0)
50#define PERF_TI_DATA       PERF_TI_CODE(1)
51#define PERF_TI_XSAMPLE    PERF_TI_CODE(2)
52#define PERF_TI_XPEND      PERF_TI_CODE(3)
53#define PERF_TI_XDATA      PERF_TI_CODE(4)
54
55#define PERF_CS_CODE(code) PERF_CODE(PERF_CALLSTACK, code)
56#define PERF_CS_KSAMPLE    PERF_CS_CODE(0)
57#define PERF_CS_UPEND      PERF_CS_CODE(1)
58#define PERF_CS_USAMPLE    PERF_CS_CODE(2)
59#define PERF_CS_KDATA      PERF_CS_CODE(3)
60#define PERF_CS_UDATA      PERF_CS_CODE(4)
61
62#define PERF_TM_CODE(code) PERF_CODE(PERF_TIMER, code)
63#define PERF_TM_ASCHED     PERF_TM_CODE(0)
64#define PERF_TM_SCHED      PERF_TM_CODE(1)
65#define PERF_TM_HNDLR      PERF_TM_CODE(2)
66
67#define PERF_PET_CODE(code) PERF_CODE(PERF_PET, code)
68#define PERF_PET_THREAD     PERF_PET_CODE(0)
69#define PERF_PET_ERROR      PERF_PET_CODE(1)
70#define PERF_PET_RUN        PERF_PET_CODE(2)
71#define PERF_PET_PAUSE      PERF_PET_CODE(3)
72#define PERF_PET_IDLE       PERF_PET_CODE(4)
73#define PERF_PET_SAMPLE     PERF_PET_CODE(5)
74
75#define PERF_AST_CODE(code) PERF_CODE(PERF_AST, code)
76#define PERF_AST_HNDLR      PERF_TM_CODE(0)
77#define PERF_AST_ERROR      PERF_PET_CODE(1)
78
79/* error sub-codes for trace data */
80enum
81{
82	ERR_TASK,
83	ERR_THREAD,
84	ERR_PID,
85	ERR_FRAMES,
86	ERR_GETSTACK,
87	ERR_NOMEM,
88};
89
90/* for logging information / debugging -- optional */
91#define BUF_INFO( id, a0, a1, a2, a3) KERNEL_DEBUG_CONSTANT(id,a0,a1,a2,a3,0)
92
93#define BUF_INFO1( id, a0 )         BUF_INFO(id, a0,  0,  0,  0 )
94#define BUF_INFO2( id, a0, a1 )     BUF_INFO(id, a0, a1,  0,  0 )
95#define BUF_INFO3( id, a0, a1, a2 ) BUF_INFO(id, a0, a1, a2,  0 )
96
97/* for logging actual data -- never compiled out */
98#define BUF_DATA( id, a0, a1, a2, a3) KERNEL_DEBUG_CONSTANT(id,a0,a1,a2,a3,0)
99
100/* code neatness */
101#define BUF_DATA1( id, a0 )         BUF_DATA(id, a0, 0, 0, 0 )
102#define BUF_DATA2( id, a0, a1 )     BUF_DATA(id, a0, a1, 0, 0 )
103#define BUF_DATA3( id, a0, a1, a3 ) BUF_DATA(id, a0, a1, a2, a3 )
104