xref: /xnu-8796.101.5/tests/ktrace/kperf_helpers.c (revision aca3beaa3dfbd42498b42c5e5ce20a938e6554e5)
1 // Copyright (c) 2018-2020 Apple Inc.  All rights reserved.
2 
3 #include "kperf_helpers.h"
4 
5 #include <darwintest.h>
6 #include <kperf/kperf.h>
7 #include <unistd.h>
8 
9 void
configure_kperf_stacks_timer(pid_t pid,unsigned int period_ms,bool quiet)10 configure_kperf_stacks_timer(pid_t pid, unsigned int period_ms, bool quiet)
11 {
12 	kperf_reset();
13 
14 	(void)kperf_action_count_set(1);
15 	(void)kperf_timer_count_set(1);
16 
17 	if (quiet) {
18 		T_QUIET;
19 	}
20 	T_ASSERT_POSIX_SUCCESS(kperf_action_samplers_set(1,
21 	    KPERF_SAMPLER_USTACK | KPERF_SAMPLER_KSTACK), NULL);
22 
23 	if (pid != -1) {
24 		if (quiet) {
25 			T_QUIET;
26 		}
27 		T_ASSERT_POSIX_SUCCESS(kperf_action_filter_set_by_pid(1, pid), NULL);
28 	}
29 
30 	if (quiet) {
31 		T_QUIET;
32 	}
33 	T_ASSERT_POSIX_SUCCESS(kperf_timer_action_set(0, 1), NULL);
34 	if (quiet) {
35 		T_QUIET;
36 	}
37 	T_ASSERT_POSIX_SUCCESS(kperf_timer_period_set(0,
38 	    kperf_ns_to_ticks(period_ms * NSEC_PER_MSEC)), NULL);
39 }
40