2
* Copyright (C) 2012 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
29
#include "ExportMacros.h"
30
#include "ThreadingPrimitives.h"
33
// Define this flag to enable Stack stats collection. This feature is useful
34
// for getting a sample of native stack usage sizes.
36
// Enabling this will cause stats to be collected and written to a log file at
37
// various instrumented points in the code. It will result in noticeable
38
// performance loss. Hence, this should only be enable when you want to do
39
// some stats location in your local build. This code is provided here as a
40
// convenience for collecting that data. It is not meant to be enabled by
41
// default on release or debug builds.
43
// #define ENABLE_STACK_STATS 1
48
#if !ENABLE(STACK_STATS)
52
// The CheckPoint class is for marking check points corresponding
53
// each location in code where a stack recursion check is being done.
60
class PerThreadStats {
65
class LayoutCheckPoint {
67
LayoutCheckPoint() { }
70
static void initialize() { }
71
static void probe() { }
74
#else // ENABLE(STACK_STATS)
78
// The CheckPoint class is for marking check points corresponding
79
// each location in code where a stack recursion check is being done.
89
class PerThreadStats {
96
CheckPoint* m_currentCheckPoint;
98
friend class CheckPoint;
99
friend class StackStats;
102
class LayoutCheckPoint {
104
WTF_EXPORT_PRIVATE LayoutCheckPoint();
105
WTF_EXPORT_PRIVATE ~LayoutCheckPoint();
108
LayoutCheckPoint* m_prev;
112
// Initializes locks and the log file. Should only be called once.
113
static void initialize();
115
// Used for probing the stack at places where we suspect to be high
116
// points of stack usage but are NOT check points where stack recursion
119
// The more places where we add this probe, the more accurate our
120
// stats data will be. However, adding too many probes will also
121
// result in unnecessary performance loss. So, only add these probes
122
// judiciously where appropriate.
126
// CheckPoint management:
127
static Mutex* s_sharedLock;
128
static CheckPoint* s_topCheckPoint;
129
static LayoutCheckPoint* s_firstLayoutCheckPoint;
130
static LayoutCheckPoint* s_topLayoutCheckPoint;
132
// High watermark stats:
133
static int s_maxCheckPointDiff;
134
static int s_maxStackHeight;
135
static int s_maxReentryDepth;
137
static int s_maxLayoutCheckPointDiff;
138
static int s_maxTotalLayoutCheckPointDiff;
139
static int s_maxLayoutReentryDepth;
141
friend class CheckPoint;
142
friend class LayoutCheckPoint;
145
#endif // ENABLE(STACK_STATS)
149
using WTF::StackStats;
151
#endif // StackStats_h