2 * Copyright (c) 2016 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <kperf/task_samplers.h>
30 #include <kperf/context.h>
31 #include <kperf/buffer.h>
32 #include <kern/thread.h>
34 #include <kern/task.h>
36 extern void memorystatus_proc_flags_unsafe(void * v
, boolean_t
*is_dirty
,
37 boolean_t
*is_dirty_tracked
, boolean_t
*allow_idle_exit
);
40 kperf_task_snapshot_sample(task_t task
, struct kperf_task_snapshot
*tksn
)
42 BUF_INFO(PERF_TK_SNAP_SAMPLE
| DBG_FUNC_START
);
46 tksn
->kptksn_flags
= 0;
47 if (task
->effective_policy
.tep_darwinbg
) {
48 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_DARWIN_BG
;
50 if (task
->requested_policy
.trp_role
== TASK_FOREGROUND_APPLICATION
) {
51 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_FOREGROUND
;
53 if (task
->requested_policy
.trp_boosted
== 1) {
54 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_BOOSTED
;
56 #if CONFIG_MEMORYSTATUS
57 boolean_t dirty
= FALSE
, dirty_tracked
= FALSE
, allow_idle_exit
= FALSE
;
58 memorystatus_proc_flags_unsafe(task
->bsd_info
, &dirty
, &dirty_tracked
, &allow_idle_exit
);
60 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_DIRTY
;
63 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_DIRTY_TRACKED
;
65 if (allow_idle_exit
) {
66 tksn
->kptksn_flags
|= KPERF_TASK_ALLOW_IDLE_EXIT
;
70 tksn
->kptksn_suspend_count
= task
->suspend_count
;
71 tksn
->kptksn_pageins
= task
->pageins
;
72 tksn
->kptksn_user_time_in_terminated_threads
= task
->total_user_time
;
73 tksn
->kptksn_system_time_in_terminated_threads
= task
->total_system_time
;
75 BUF_INFO(PERF_TK_SNAP_SAMPLE
| DBG_FUNC_END
);
79 kperf_task_snapshot_log(struct kperf_task_snapshot
*tksn
)
84 BUF_DATA(PERF_TK_SNAP_DATA
, tksn
->kptksn_flags
,
85 ENCODE_UPPER_64(tksn
->kptksn_suspend_count
) |
86 ENCODE_LOWER_64(tksn
->kptksn_pageins
),
87 tksn
->kptksn_user_time_in_terminated_threads
,
88 tksn
->kptksn_system_time_in_terminated_threads
);
90 BUF_DATA(PERF_TK_SNAP_DATA1_32
, UPPER_32(tksn
->kptksn_flags
),
91 LOWER_32(tksn
->kptksn_flags
),
92 tksn
->kptksn_suspend_count
,
93 tksn
->kptksn_pageins
);
94 BUF_DATA(PERF_TK_SNAP_DATA2_32
, UPPER_32(tksn
->kptksn_user_time_in_terminated_threads
),
95 LOWER_32(tksn
->kptksn_user_time_in_terminated_threads
),
96 UPPER_32(tksn
->kptksn_system_time_in_terminated_threads
),
97 LOWER_32(tksn
->kptksn_system_time_in_terminated_threads
));
98 #endif /* defined(__LP64__) */
102 kperf_task_info_log(struct kperf_context
*ctx
)
106 BUF_DATA(PERF_TK_INFO_DATA
, ctx
->cur_pid
);