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 DumpJITMemoryStart,
51 DumpJITMemoryStop,
52
53 WebCoreRange = 5000,
54 MainResourceLoadDidStartProvisional,
55 MainResourceLoadDidEnd,
56 SubresourceLoadWillStart,
57 SubresourceLoadDidEnd,
58 FetchCookiesStart,
59 FetchCookiesEnd,
60 StyleRecalcStart,
61 StyleRecalcEnd,
62 RenderTreeBuildStart,
63 RenderTreeBuildEnd,
64 LayoutStart,
65 LayoutEnd,
66 PaintLayerStart,
67 PaintLayerEnd,
68 AsyncImageDecodeStart,
69 AsyncImageDecodeEnd,
70 RAFCallbackStart,
71 RAFCallbackEnd,
72 MemoryPressureHandlerStart,
73 MemoryPressureHandlerEnd,
74 UpdateTouchRegionsStart,
75 UpdateTouchRegionsEnd,
76 DisplayListRecordStart,
77 DisplayListRecordEnd,
78 DisplayRefreshDispatchingToMainThread,
79 ComputeEventRegionsStart,
80 ComputeEventRegionsEnd,
81 ScheduleRenderingUpdate,
82 TriggerRenderingUpdate,
83 RenderingUpdateStart,
84 RenderingUpdateEnd,
85 CompositingUpdateStart,
86 CompositingUpdateEnd,
87 DispatchTouchEventsStart,
88 DispatchTouchEventsEnd,
89
90 WebKitRange = 10000,
91 WebHTMLViewPaintStart,
92 WebHTMLViewPaintEnd,
93
94 WebKit2Range = 12000,
95 BackingStoreFlushStart,
96 BackingStoreFlushEnd,
97 BuildTransactionStart,
98 BuildTransactionEnd,
99 SyncMessageStart,
100 SyncMessageEnd,
101 SyncTouchEventStart,
102 SyncTouchEventEnd,
103 InitializeWebProcessStart,
104 InitializeWebProcessEnd,
105
106 UIProcessRange = 14000,
107 CommitLayerTreeStart,
108 CommitLayerTreeEnd,
109 ProcessLaunchStart,
110 ProcessLaunchEnd,
111 InitializeSandboxStart,
112 InitializeSandboxEnd,
113};
114
115#ifdef __cplusplus
116
117namespace WTF {
118
119inline void tracePoint(TracePointCode code, uint64_t data1 = 0, uint64_t data2 = 0, uint64_t data3 = 0, uint64_t data4 = 0)
120{
121#if HAVE(KDEBUG_H)
122 kdebug_trace(ARIADNEDBG_CODE(WEBKIT_COMPONENT, code), data1, data2, data3, data4);
123#else
124 UNUSED_PARAM(code);
125 UNUSED_PARAM(data1);
126 UNUSED_PARAM(data2);
127 UNUSED_PARAM(data3);
128 UNUSED_PARAM(data4);
129#endif
130}
131
132class TraceScope {
133 WTF_MAKE_FAST_ALLOCATED;
134public:
135
136 TraceScope(TracePointCode entryCode, TracePointCode exitCode, uint64_t data1 = 0, uint64_t data2 = 0, uint64_t data3 = 0, uint64_t data4 = 0)
137 : m_exitCode(exitCode)
138 {
139 tracePoint(entryCode, data1, data2, data3, data4);
140 }
141
142 ~TraceScope()
143 {
144 tracePoint(m_exitCode);
145 }
146
147private:
148 TracePointCode m_exitCode;
149};
150
151} // namespace WTF
152
153using WTF::TraceScope;
154using WTF::tracePoint;
155
156#endif // __cplusplus
157