1/*
2 * Copyright (C) 2016 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#if USE(APPLE_INTERNAL_SDK)
29#include <System/sys/kdebug.h>
30#define HAVE_KDEBUG_H 1
31#endif
32
33// No namespaces because this file has to be includable from C and Objective-C.
34
35// Reserved component code. Do not change this.
36#define WEBKIT_COMPONENT 47
37
38// Trace point codes can be up to 14 bits (0-16383).
39// When adding or changing these codes, update Tools/Tracing/SystemTracePoints.plist to match.
40enum TracePointCode {
41 WTFRange = 0,
42
43 JavaScriptRange = 2500,
44 VMEntryScopeStart,
45 VMEntryScopeEnd,
46 WebAssemblyCompileStart,
47 WebAssemblyCompileEnd,
48 WebAssemblyExecuteStart,
49 WebAssemblyExecuteEnd,
50
51 WebCoreRange = 5000,
52 MainResourceLoadDidStartProvisional,
53 MainResourceLoadDidEnd,
54 SubresourceLoadWillStart,
55 SubresourceLoadDidEnd,
56 FetchCookiesStart,
57 FetchCookiesEnd,
58 StyleRecalcStart,
59 StyleRecalcEnd,
60 RenderTreeBuildStart,
61 RenderTreeBuildEnd,
62 LayoutStart,
63 LayoutEnd,
64 PaintLayerStart,
65 PaintLayerEnd,
66 AsyncImageDecodeStart,
67 AsyncImageDecodeEnd,
68 RAFCallbackStart,
69 RAFCallbackEnd,
70 MemoryPressureHandlerStart,
71 MemoryPressureHandlerEnd,
72 UpdateTouchRegionsStart,
73 UpdateTouchRegionsEnd,
74 DisplayListRecordStart,
75 DisplayListRecordEnd,
76 DisplayRefreshDispatchingToMainThread,
77 ComputeEventRegionsStart,
78 ComputeEventRegionsEnd,
79
80 WebKitRange = 10000,
81 WebHTMLViewPaintStart,
82 WebHTMLViewPaintEnd,
83
84 WebKit2Range = 12000,
85 BackingStoreFlushStart,
86 BackingStoreFlushEnd,
87 BuildTransactionStart,
88 BuildTransactionEnd,
89 SyncMessageStart,
90 SyncMessageEnd,
91 SyncTouchEventStart,
92 SyncTouchEventEnd,
93 InitializeWebProcessStart,
94 InitializeWebProcessEnd,
95
96 UIProcessRange = 14000,
97 CommitLayerTreeStart,
98 CommitLayerTreeEnd,
99 ProcessLaunchStart,
100 ProcessLaunchEnd,
101 InitializeSandboxStart,
102 InitializeSandboxEnd,
103};
104
105#ifdef __cplusplus
106
107namespace WTF {
108
109inline void tracePoint(TracePointCode code, uint64_t data1 = 0, uint64_t data2 = 0, uint64_t data3 = 0, uint64_t data4 = 0)
110{
111#if HAVE(KDEBUG_H)
112 kdebug_trace(ARIADNEDBG_CODE(WEBKIT_COMPONENT, code), data1, data2, data3, data4);
113#else
114 UNUSED_PARAM(code);
115 UNUSED_PARAM(data1);
116 UNUSED_PARAM(data2);
117 UNUSED_PARAM(data3);
118 UNUSED_PARAM(data4);
119#endif
120}
121
122class TraceScope {
123public:
124
125 TraceScope(TracePointCode entryCode, TracePointCode exitCode, uint64_t data1 = 0, uint64_t data2 = 0, uint64_t data3 = 0, uint64_t data4 = 0)
126 : m_exitCode(exitCode)
127 {
128 tracePoint(entryCode, data1, data2, data3, data4);
129 }
130
131 ~TraceScope()
132 {
133 tracePoint(m_exitCode);
134 }
135
136private:
137 TracePointCode m_exitCode;
138};
139
140} // namespace WTF
141
142using WTF::TraceScope;
143using WTF::tracePoint;
144
145#endif // __cplusplus
146