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 boolean_t
memorystatus_proc_is_dirty_unsafe(void *v
);
39 kperf_task_snapshot_sample(struct kperf_task_snapshot
*tksn
,
40 struct kperf_context
*ctx
)
45 BUF_INFO(PERF_TK_SNAP_SAMPLE
| DBG_FUNC_START
);
50 thread
= ctx
->cur_thread
;
51 task
= get_threadtask(thread
);
53 tksn
->kptksn_flags
= 0;
54 if (task
->effective_policy
.tep_darwinbg
) {
55 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_DARWIN_BG
;
57 if (task
->requested_policy
.trp_role
== TASK_FOREGROUND_APPLICATION
) {
58 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_FOREGROUND
;
60 if (task
->requested_policy
.trp_boosted
== 1) {
61 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_BOOSTED
;
63 #if CONFIG_MEMORYSTATUS
64 if (memorystatus_proc_is_dirty_unsafe(task
->bsd_info
)) {
65 tksn
->kptksn_flags
|= KPERF_TASK_FLAG_DIRTY
;
69 tksn
->kptksn_suspend_count
= task
->suspend_count
;
70 tksn
->kptksn_pageins
= task
->pageins
;
71 tksn
->kptksn_user_time_in_terminated_threads
= task
->total_user_time
;
72 tksn
->kptksn_system_time_in_terminated_threads
= task
->total_system_time
;
74 BUF_INFO(PERF_TK_SNAP_SAMPLE
| DBG_FUNC_END
);
78 kperf_task_snapshot_log(struct kperf_task_snapshot
*tksn
)
83 BUF_DATA(PERF_TK_SNAP_DATA
, tksn
->kptksn_flags
,
84 ENCODE_UPPER_64(tksn
->kptksn_suspend_count
) |
85 ENCODE_LOWER_64(tksn
->kptksn_pageins
),
86 tksn
->kptksn_user_time_in_terminated_threads
,
87 tksn
->kptksn_system_time_in_terminated_threads
);
89 BUF_DATA(PERF_TK_SNAP_DATA1_32
, UPPER_32(tksn
->kptksn_flags
),
90 LOWER_32(tksn
->kptksn_flags
),
91 tksn
->kptksn_suspend_count
,
92 tksn
->kptksn_pageins
);
93 BUF_DATA(PERF_TK_SNAP_DATA2_32
, UPPER_32(tksn
->kptksn_user_time_in_terminated_threads
),
94 LOWER_32(tksn
->kptksn_user_time_in_terminated_threads
),
95 UPPER_32(tksn
->kptksn_system_time_in_terminated_threads
),
96 LOWER_32(tksn
->kptksn_system_time_in_terminated_threads
));
97 #endif /* defined(__LP64__) */