Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: Source/wtf/StackStats.cpp

Issue 13890009: Simplify StackBounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/wtf/StackBounds.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 dataLogF(" === THREAD new stackStart %p ========\n", m_stackStart); 74 dataLogF(" === THREAD new stackStart %p ========\n", m_stackStart);
75 } 75 }
76 76
77 StackStats::CheckPoint::CheckPoint() 77 StackStats::CheckPoint::CheckPoint()
78 { 78 {
79 MutexLocker locker(*StackStats::s_sharedLock); 79 MutexLocker locker(*StackStats::s_sharedLock);
80 WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData()); 80 WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
81 StackStats::PerThreadStats& t = threadData->stackStats(); 81 StackStats::PerThreadStats& t = threadData->stackStats();
82 const StackBounds& stack = threadData->stack(); 82 const StackBounds& stack = threadData->stack();
83 83
84 bool isGrowingDownward = stack.isGrowingDownward();
85 bool needToLog = false; 84 bool needToLog = false;
86 char* current = reinterpret_cast<char*>(this); 85 char* current = reinterpret_cast<char*>(this);
87 char* last = reinterpret_cast<char*>(t.m_currentCheckPoint); 86 char* last = reinterpret_cast<char*>(t.m_currentCheckPoint);
88 87
89 // If there was no previous checkpoint, measure from the start of the stack: 88 // If there was no previous checkpoint, measure from the start of the stack:
90 if (!last) 89 if (!last)
91 last = t.m_stackStart; 90 last = t.m_stackStart;
92 91
93 // Update the reentry depth stats: 92 // Update the reentry depth stats:
94 t.m_reentryDepth++; 93 t.m_reentryDepth++;
95 if (t.m_reentryDepth > StackStats::s_maxReentryDepth) { 94 if (t.m_reentryDepth > StackStats::s_maxReentryDepth) {
96 StackStats::s_maxReentryDepth = t.m_reentryDepth; 95 StackStats::s_maxReentryDepth = t.m_reentryDepth;
97 needToLog = true; 96 needToLog = true;
98 } 97 }
99 98
100 // Update the stack height stats: 99 // Update the stack height stats:
101 int height = t.m_stackStart - current; 100 int height = t.m_stackStart - current;
102 if (!isGrowingDownward)
103 height = -height;
104 if (height > StackStats::s_maxStackHeight) { 101 if (height > StackStats::s_maxStackHeight) {
105 StackStats::s_maxStackHeight = height; 102 StackStats::s_maxStackHeight = height;
106 needToLog = true; 103 needToLog = true;
107 } 104 }
108 105
109 // Update the checkpoint diff stats: 106 // Update the checkpoint diff stats:
110 int diff = last - current; 107 int diff = last - current;
111 if (!isGrowingDownward)
112 diff = -diff;
113 if (diff > StackStats::s_maxCheckPointDiff) { 108 if (diff > StackStats::s_maxCheckPointDiff) {
114 StackStats::s_maxCheckPointDiff = diff; 109 StackStats::s_maxCheckPointDiff = diff;
115 needToLog = true; 110 needToLog = true;
116 } 111 }
117 112
118 // Push this checkpoint: 113 // Push this checkpoint:
119 m_prev = t.m_currentCheckPoint; 114 m_prev = t.m_currentCheckPoint;
120 t.m_currentCheckPoint = this; 115 t.m_currentCheckPoint = this;
121 116
122 #if ENABLE(VERBOSE_STACK_STATS) 117 #if ENABLE(VERBOSE_STACK_STATS)
(...skipping 16 matching lines...) Expand all
139 StackStats::PerThreadStats& t = threadData->stackStats(); 134 StackStats::PerThreadStats& t = threadData->stackStats();
140 135
141 // Pop to previous checkpoint: 136 // Pop to previous checkpoint:
142 t.m_currentCheckPoint = m_prev; 137 t.m_currentCheckPoint = m_prev;
143 --t.m_reentryDepth; 138 --t.m_reentryDepth;
144 139
145 // Log this checkpoint if needed: 140 // Log this checkpoint if needed:
146 #if ENABLE(VERBOSE_STACK_STATS) 141 #if ENABLE(VERBOSE_STACK_STATS)
147 if (!m_prev) { 142 if (!m_prev) {
148 const StackBounds& stack = threadData->stack(); 143 const StackBounds& stack = threadData->stack();
149 bool isGrowingDownward = stack.isGrowingDownward();
150 144
151 char* current = reinterpret_cast<char*>(this); 145 char* current = reinterpret_cast<char*>(this);
152 int height = t.m_stackStart - current; 146 int height = t.m_stackStart - current;
153 147
154 if (!isGrowingDownward)
155 height = -height;
156
157 dataLogF(" POP to %p diff max %.1fk | reentry %d/%d max | height %.1fk/m ax %.1fk | stack %p size %.1fk)\n", 148 dataLogF(" POP to %p diff max %.1fk | reentry %d/%d max | height %.1fk/m ax %.1fk | stack %p size %.1fk)\n",
158 this, StackStats::s_maxCheckPointDiff / 1024.0, 149 this, StackStats::s_maxCheckPointDiff / 1024.0,
159 t.m_reentryDepth, StackStats::s_maxReentryDepth, 150 t.m_reentryDepth, StackStats::s_maxReentryDepth,
160 height / 1024.0, StackStats::s_maxStackHeight / 1024.0, 151 height / 1024.0, StackStats::s_maxStackHeight / 1024.0,
161 stack.origin(), stack.size() / 1024.0); 152 stack.origin(), stack.size() / 1024.0);
162 } 153 }
163 #endif 154 #endif
164 } 155 }
165 156
166 void StackStats::probe() 157 void StackStats::probe()
167 { 158 {
168 MutexLocker locker(*StackStats::s_sharedLock); 159 MutexLocker locker(*StackStats::s_sharedLock);
169 WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData()); 160 WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
170 StackStats::PerThreadStats& t = threadData->stackStats(); 161 StackStats::PerThreadStats& t = threadData->stackStats();
171 const StackBounds& stack = threadData->stack(); 162 const StackBounds& stack = threadData->stack();
172 163
173 bool isGrowingDownward = stack.isGrowingDownward();
174
175 bool needToLog = false; 164 bool needToLog = false;
176 165
177 int dummy; 166 int dummy;
178 char* current = reinterpret_cast<char*>(&dummy); 167 char* current = reinterpret_cast<char*>(&dummy);
179 char* last = reinterpret_cast<char*>(t.m_currentCheckPoint); 168 char* last = reinterpret_cast<char*>(t.m_currentCheckPoint);
180 169
181 // If there was no previous checkpoint, measure from the start of the stack: 170 // If there was no previous checkpoint, measure from the start of the stack:
182 if (!last) 171 if (!last)
183 last = t.m_stackStart; 172 last = t.m_stackStart;
184 173
185 // We did not reach another checkpoint yet. Hence, we do not touch the 174 // We did not reach another checkpoint yet. Hence, we do not touch the
186 // reentry stats. 175 // reentry stats.
187 176
188 // Update the stack height stats: 177 // Update the stack height stats:
189 int height = t.m_stackStart - current; 178 int height = t.m_stackStart - current;
190 if (!isGrowingDownward)
191 height = -height;
192 if (height > StackStats::s_maxStackHeight) { 179 if (height > StackStats::s_maxStackHeight) {
193 StackStats::s_maxStackHeight = height; 180 StackStats::s_maxStackHeight = height;
194 needToLog = true; 181 needToLog = true;
195 } 182 }
196 183
197 // Update the checkpoint diff stats: 184 // Update the checkpoint diff stats:
198 int diff = last - current; 185 int diff = last - current;
199 if (!isGrowingDownward)
200 diff = -diff;
201 if (diff > StackStats::s_maxCheckPointDiff) { 186 if (diff > StackStats::s_maxCheckPointDiff) {
202 StackStats::s_maxCheckPointDiff = diff; 187 StackStats::s_maxCheckPointDiff = diff;
203 needToLog = true; 188 needToLog = true;
204 } 189 }
205 190
206 #if ENABLE(VERBOSE_STACK_STATS) 191 #if ENABLE(VERBOSE_STACK_STATS)
207 needToLog = true; // always log. 192 needToLog = true; // always log.
208 #endif 193 #endif
209 194
210 if (needToLog) 195 if (needToLog)
(...skipping 13 matching lines...) Expand all
224 // We'll do this probe before we commence with the layout checkpoint. 209 // We'll do this probe before we commence with the layout checkpoint.
225 // This is because the probe also locks the sharedLock. By calling the 210 // This is because the probe also locks the sharedLock. By calling the
226 // probe first, we can avoid re-entering the lock. 211 // probe first, we can avoid re-entering the lock.
227 StackStats::probe(); 212 StackStats::probe();
228 213
229 MutexLocker locker(*StackStats::s_sharedLock); 214 MutexLocker locker(*StackStats::s_sharedLock);
230 WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData()); 215 WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
231 StackStats::PerThreadStats& t = threadData->stackStats(); 216 StackStats::PerThreadStats& t = threadData->stackStats();
232 const StackBounds& stack = threadData->stack(); 217 const StackBounds& stack = threadData->stack();
233 218
234 bool isGrowingDownward = stack.isGrowingDownward();
235
236 // Push this checkpoint: 219 // Push this checkpoint:
237 m_prev = StackStats::s_topLayoutCheckPoint; 220 m_prev = StackStats::s_topLayoutCheckPoint;
238 if (m_prev) 221 if (m_prev)
239 m_depth = m_prev->m_depth + 1; 222 m_depth = m_prev->m_depth + 1;
240 else { 223 else {
241 StackStats::s_firstLayoutCheckPoint = this; 224 StackStats::s_firstLayoutCheckPoint = this;
242 m_depth = 0; 225 m_depth = 0;
243 } 226 }
244 StackStats::s_topLayoutCheckPoint = this; 227 StackStats::s_topLayoutCheckPoint = this;
245 228
246 // 229 //
247 char* current = reinterpret_cast<char*>(this); 230 char* current = reinterpret_cast<char*>(this);
248 char* last = reinterpret_cast<char*>(m_prev); 231 char* last = reinterpret_cast<char*>(m_prev);
249 char* root = reinterpret_cast<char*>(StackStats::s_firstLayoutCheckPoint); 232 char* root = reinterpret_cast<char*>(StackStats::s_firstLayoutCheckPoint);
250 bool needToLog = false; 233 bool needToLog = false;
251 234
252 int diff = last - current; 235 int diff = last - current;
253 if (!last) 236 if (!last)
254 diff = 0; 237 diff = 0;
255 int totalDiff = root - current; 238 int totalDiff = root - current;
256 if (!root) 239 if (!root)
257 totalDiff = 0; 240 totalDiff = 0;
258 241
259 // Update the stack height stats: 242 // Update the stack height stats:
260 int height = t.m_stackStart - current; 243 int height = t.m_stackStart - current;
261 if (!isGrowingDownward)
262 height = -height;
263 if (height > StackStats::s_maxStackHeight) { 244 if (height > StackStats::s_maxStackHeight) {
264 StackStats::s_maxStackHeight = height; 245 StackStats::s_maxStackHeight = height;
265 needToLog = true; 246 needToLog = true;
266 } 247 }
267 248
268 // Update the layout checkpoint diff stats: 249 // Update the layout checkpoint diff stats:
269 if (!isGrowingDownward)
270 diff = -diff;
271 if (diff > StackStats::s_maxLayoutCheckPointDiff) { 250 if (diff > StackStats::s_maxLayoutCheckPointDiff) {
272 StackStats::s_maxLayoutCheckPointDiff = diff; 251 StackStats::s_maxLayoutCheckPointDiff = diff;
273 needToLog = true; 252 needToLog = true;
274 } 253 }
275 254
276 // Update the total layout checkpoint diff stats: 255 // Update the total layout checkpoint diff stats:
277 if (!isGrowingDownward)
278 totalDiff = -totalDiff;
279 if (totalDiff > StackStats::s_maxTotalLayoutCheckPointDiff) { 256 if (totalDiff > StackStats::s_maxTotalLayoutCheckPointDiff) {
280 StackStats::s_maxTotalLayoutCheckPointDiff = totalDiff; 257 StackStats::s_maxTotalLayoutCheckPointDiff = totalDiff;
281 needToLog = true; 258 needToLog = true;
282 } 259 }
283 260
284 #if ENABLE(VERBOSE_STACK_STATS) 261 #if ENABLE(VERBOSE_STACK_STATS)
285 needToLog = true; // always log. 262 needToLog = true; // always log.
286 #endif 263 #endif
287 264
288 if (needToLog) 265 if (needToLog)
(...skipping 11 matching lines...) Expand all
300 // Pop to the previous layout checkpoint: 277 // Pop to the previous layout checkpoint:
301 StackStats::s_topLayoutCheckPoint = m_prev; 278 StackStats::s_topLayoutCheckPoint = m_prev;
302 if (!m_depth) 279 if (!m_depth)
303 StackStats::s_firstLayoutCheckPoint = 0; 280 StackStats::s_firstLayoutCheckPoint = 0;
304 } 281 }
305 282
306 } // namespace WTF 283 } // namespace WTF
307 284
308 #endif // ENABLE(STACK_STATS) 285 #endif // ENABLE(STACK_STATS)
309 286
OLDNEW
« no previous file with comments | « Source/wtf/StackBounds.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698