]>
git.saurik.com Git - apple/dyld.git/blob - dyld3/Tracing.cpp
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #include <mach/mach.h>
34 static uint64_t elapsed(const time_value_t start
, const time_value_t end
) {
36 duration
= 1000000*(end
.seconds
- start
.seconds
);
37 duration
+= (end
.microseconds
- start
.microseconds
);
45 void kdebug_trace_dyld_image(const uint32_t code
,
46 const uuid_t
* uuid_bytes
,
47 const fsobj_id_t fsobjid
,
49 const mach_header
* load_addr
)
52 uint64_t *uuid
= (uint64_t *)uuid_bytes
[0];
53 kdebug_trace(KDBG_CODE(DBG_DYLD
, DBG_DYLD_UUID
, code
), uuid
[0],
54 uuid
[1], (uint64_t)load_addr
,
55 (uint64_t)fsid
.val
[0] | ((uint64_t)fsid
.val
[1] << 32));
56 kdebug_trace(KDBG_CODE(DBG_DYLD
, DBG_DYLD_UUID
, code
+ 1),
57 (uint64_t)fsobjid
.fid_objno
|
58 ((uint64_t)fsobjid
.fid_generation
<< 32),
61 uint32_t *uuid
= (uint32_t *)uuid_bytes
[0];
62 kdebug_trace(KDBG_CODE(DBG_DYLD
, DBG_DYLD_UUID
, code
+ 2), uuid
[0],
63 uuid
[1], uuid
[2], uuid
[3]);
64 kdebug_trace(KDBG_CODE(DBG_DYLD
, DBG_DYLD_UUID
, code
+ 3),
65 (uint32_t)load_addr
, fsid
.val
[0], fsid
.val
[1],
67 kdebug_trace(KDBG_CODE(DBG_DYLD
, DBG_DYLD_UUID
, code
+ 4),
68 fsobjid
.fid_generation
, 0, 0, 0);
73 // We get distinct copies of this in libdyld and dyld. Eventually we can fix it,
74 // for now we will just offset the values.
77 static std::atomic
<uint64_t> trace_pair_id(0);
79 static std::atomic
<uint64_t> trace_pair_id(1LL<<63);
83 bool kdebug_trace_dyld_enabled(uint32_t code
) {
84 return kdebug_is_enabled(code
);
88 void kdebug_trace_dyld_marker(uint32_t code
, kt_arg data1
, kt_arg data2
, kt_arg data3
, kt_arg data4
) {
89 if (kdebug_is_enabled(code
)) {
94 kdebug_trace(code
, data1
.value(), data2
.value(), data3
.value(), data4
.value());
103 uint64_t kdebug_trace_dyld_duration_start(uint32_t code
, kt_arg data1
, kt_arg data2
, kt_arg data3
) {
105 if (kdebug_is_enabled(code
)) {
106 result
= ++trace_pair_id
;
110 kdebug_trace(code
| DBG_FUNC_START
, result
, data1
.value(), data2
.value(), data3
.value());
119 void kdebug_trace_dyld_duration_end(uint64_t trace_id
, uint32_t code
, kt_arg data1
, kt_arg data2
, kt_arg data3
) {
120 if (trace_id
!= 0 && kdebug_is_enabled(code
)) {
124 kdebug_trace(code
| DBG_FUNC_END
, trace_id
, data1
.value(), data2
.value(), data3
.value());
131 void ScopedTimer::startTimer() {
132 current_trace_id
= kdebug_trace_dyld_duration_start(code
, data1
, data2
, data3
);
135 void ScopedTimer::endTimer() {
136 kdebug_trace_dyld_duration_end(current_trace_id
, code
, data4
, data5
, data6
);