]>
Commit | Line | Data |
---|---|---|
316670eb | 1 | /* |
39037602 | 2 | * Copyright (c) 2016 Apple Computer, Inc. All rights reserved. |
316670eb A |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
39037602 | 5 | * |
316670eb 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. 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. | |
39037602 | 14 | * |
316670eb A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
39037602 | 17 | * |
316670eb A |
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. | |
39037602 | 25 | * |
316670eb A |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ | |
28 | ||
39037602 A |
29 | #ifndef KPERF_ACTION_H |
30 | #define KPERF_ACTION_H | |
31 | ||
32 | #include <mach/kern_return.h> | |
d9a64523 | 33 | #include <stdint.h> |
5ba3f43e | 34 | #include <stdbool.h> |
39037602 | 35 | |
316670eb | 36 | struct kperf_sample; |
94ff46dc | 37 | struct kperf_usample; |
316670eb A |
38 | struct kperf_context; |
39 | ||
316670eb | 40 | /* bits for defining what to do on an action */ |
39037602 A |
41 | #define SAMPLER_TH_INFO (1U << 0) |
42 | #define SAMPLER_TH_SNAPSHOT (1U << 1) | |
43 | #define SAMPLER_KSTACK (1U << 2) | |
44 | #define SAMPLER_USTACK (1U << 3) | |
45 | #define SAMPLER_PMC_THREAD (1U << 4) | |
46 | #define SAMPLER_PMC_CPU (1U << 5) | |
47 | #define SAMPLER_PMC_CONFIG (1U << 6) | |
48 | #define SAMPLER_MEMINFO (1U << 7) | |
49 | #define SAMPLER_TH_SCHEDULING (1U << 8) | |
50 | #define SAMPLER_TH_DISPATCH (1U << 9) | |
51 | #define SAMPLER_TK_SNAPSHOT (1U << 10) | |
5ba3f43e A |
52 | #define SAMPLER_SYS_MEM (1U << 11) |
53 | #define SAMPLER_TH_INSCYC (1U << 12) | |
d9a64523 A |
54 | #define SAMPLER_TK_INFO (1U << 13) |
55 | ||
56 | #define SAMPLER_TASK_MASK (SAMPLER_MEMINFO | SAMPLER_TK_SNAPSHOT | \ | |
0a7de745 | 57 | SAMPLER_TK_INFO) |
d9a64523 | 58 | #define SAMPLER_THREAD_MASK (SAMPLER_TH_INFO | SAMPLER_TH_SNAPSHOT | \ |
0a7de745 A |
59 | SAMPLER_KSTACK | SAMPLER_USTACK | SAMPLER_PMC_THREAD | \ |
60 | SAMPLER_TH_SCHEDULING | SAMPLER_TH_DISPATCH | SAMPLER_TH_INSCYC) | |
39037602 A |
61 | |
62 | /* flags for sample calls */ | |
39236c6e | 63 | |
5ba3f43e | 64 | /* pend samplers requiring copyin until AST boundary */ |
39037602 A |
65 | #define SAMPLE_FLAG_PEND_USER (1U << 0) |
66 | /* sample idle threads */ | |
67 | #define SAMPLE_FLAG_IDLE_THREADS (1U << 1) | |
68 | /* do not sample callstacks */ | |
69 | #define SAMPLE_FLAG_EMPTY_CALLSTACK (1U << 2) | |
70 | /* use the continuation as a kernel backtrace */ | |
71 | #define SAMPLE_FLAG_CONTINUATION (1U << 3) | |
72 | /* sample is occurring outside of interrupt context */ | |
73 | #define SAMPLE_FLAG_NON_INTERRUPT (1U << 4) | |
5ba3f43e A |
74 | /* sample should include system samplers */ |
75 | #define SAMPLE_FLAG_SYSTEM (1U << 5) | |
76 | /* sample should not include non-system samplers */ | |
77 | #define SAMPLE_FLAG_ONLY_SYSTEM (1U << 6) | |
d9a64523 A |
78 | /* sample should only include task samplers */ |
79 | #define SAMPLE_FLAG_TASK_ONLY (1U << 7) | |
80 | /* sample should only include thread samplers */ | |
81 | #define SAMPLE_FLAG_THREAD_ONLY (1U << 8) | |
316670eb A |
82 | |
83 | /* Take a sample into "sbuf" using current thread "cur_thread" */ | |
39037602 | 84 | kern_return_t kperf_sample(struct kperf_sample *sbuf, |
0a7de745 A |
85 | struct kperf_context *ctx, |
86 | unsigned actionid, | |
87 | unsigned sample_flags); | |
316670eb | 88 | |
94ff46dc A |
89 | /* |
90 | * Sample user space. | |
91 | */ | |
92 | void kperf_sample_user(struct kperf_usample *sbuf, struct kperf_context *ctx, | |
93 | unsigned int actionid, unsigned int sample_flags); | |
94 | ||
5ba3f43e | 95 | /* Whether the action provided samples non-system values. */ |
d9a64523 A |
96 | bool kperf_action_has_non_system(unsigned actionid); |
97 | bool kperf_action_has_thread(unsigned int actionid); | |
98 | bool kperf_action_has_task(unsigned int actionid); | |
5ba3f43e | 99 | |
316670eb A |
100 | /* return codes from taking a sample |
101 | * either keep trigger, or something went wrong (or we're shutting down) | |
102 | * so turn off. | |
103 | */ | |
104 | #define SAMPLE_CONTINUE (0) | |
105 | #define SAMPLE_SHUTDOWN (1) | |
39236c6e | 106 | #define SAMPLE_OFF (2) |
316670eb | 107 | |
39037602 | 108 | void kperf_action_reset(void); |
316670eb A |
109 | |
110 | /* Interface functions */ | |
39037602 A |
111 | unsigned kperf_action_get_count(void); |
112 | int kperf_action_set_count(unsigned count); | |
113 | ||
114 | int kperf_action_set_samplers(unsigned int actionid, uint32_t samplers); | |
115 | int kperf_action_get_samplers(unsigned int actionid, uint32_t *samplers_out); | |
116 | ||
117 | int kperf_action_set_userdata(unsigned int actionid, uint32_t userdata); | |
118 | int kperf_action_get_userdata(unsigned int actionid, uint32_t *userdata_out); | |
316670eb | 119 | |
39037602 A |
120 | int kperf_action_set_ucallstack_depth(unsigned int actionid, uint32_t depth); |
121 | int kperf_action_get_ucallstack_depth(unsigned int actionid, uint32_t * depth_out); | |
122 | int kperf_action_set_kcallstack_depth(unsigned int actionid, uint32_t depth); | |
123 | int kperf_action_get_kcallstack_depth(unsigned int actionid, uint32_t * depth_out); | |
316670eb | 124 | |
39037602 A |
125 | int kperf_action_set_filter(unsigned int actionid, int pid); |
126 | int kperf_action_get_filter(unsigned int actionid, int *pid_out); | |
39236c6e | 127 | |
d9a64523 A |
128 | void kperf_kdebug_handler(uint32_t debugid, uintptr_t *starting_fp); |
129 | ||
130 | /* whether to output tracepoints on context-switch */ | |
131 | extern int kperf_kdebug_cswitch; | |
132 | int kperf_kdbg_cswitch_get(void); | |
133 | int kperf_kdbg_cswitch_set(int newval); | |
134 | ||
39037602 | 135 | #endif /* !defined(KPERF_ACTION_H) */ |