26
26
#define REPORT_CHROME_HANGS
27
27
#endif
28
28
29
- namespace mozilla { namespace HangMonitor {
29
+ namespace mozilla {
30
+ namespace HangMonitor {
30
31
31
32
/* *
32
33
* A flag which may be set from within a debugger to disable the hang
@@ -112,21 +113,22 @@ Crash()
112
113
113
114
#ifdef REPORT_CHROME_HANGS
114
115
static void
115
- ChromeStackWalker (void * aPC, void * aSP, void * aClosure)
116
+ ChromeStackWalker (void * aPC, void * aSP, void * aClosure)
116
117
{
117
118
MOZ_ASSERT (aClosure);
118
- std::vector<uintptr_t > * stack =
119
+ std::vector<uintptr_t >* stack =
119
120
static_cast <std::vector<uintptr_t >*>(aClosure);
120
- if (stack->size () == MAX_CALL_STACK_PCS)
121
+ if (stack->size () == MAX_CALL_STACK_PCS) {
121
122
return ;
123
+ }
122
124
MOZ_ASSERT (stack->size () < MAX_CALL_STACK_PCS);
123
125
stack->push_back (reinterpret_cast <uintptr_t >(aPC));
124
126
}
125
127
126
128
static void
127
- GetChromeHangReport (Telemetry::ProcessedStack & aStack,
128
- int32_t & aSystemUptime,
129
- int32_t & aFirefoxUptime)
129
+ GetChromeHangReport (Telemetry::ProcessedStack& aStack,
130
+ int32_t & aSystemUptime,
131
+ int32_t & aFirefoxUptime)
130
132
{
131
133
MOZ_ASSERT (winMainThreadHandle);
132
134
@@ -135,14 +137,16 @@ GetChromeHangReport(Telemetry::ProcessedStack &aStack,
135
137
std::vector<uintptr_t > rawStack;
136
138
rawStack.reserve (MAX_CALL_STACK_PCS);
137
139
DWORD ret = ::SuspendThread (winMainThreadHandle);
138
- if (ret == -1 )
140
+ if (ret == -1 ) {
139
141
return ;
142
+ }
140
143
NS_StackWalk (ChromeStackWalker, /* skipFrames */ 0 , /* maxFrames */ 0 ,
141
144
reinterpret_cast <void *>(&rawStack),
142
145
reinterpret_cast<uintptr_t>(winMainThreadHandle), nullptr);
143
146
ret = ::ResumeThread (winMainThreadHandle);
144
- if (ret == -1 )
147
+ if (ret == -1 ) {
145
148
return ;
149
+ }
146
150
aStack = Telemetry::GetStackAndModules (rawStack);
147
151
148
152
// Record system uptime (in minutes) at the time of the hang
@@ -217,8 +221,7 @@ ThreadMain(void*)
217
221
}
218
222
}
219
223
#endif
220
- }
221
- else {
224
+ } else {
222
225
#ifdef REPORT_CHROME_HANGS
223
226
if (waitCount >= 2 ) {
224
227
uint32_t hangDuration = PR_IntervalToSeconds (now - lastTimestamp);
@@ -234,8 +237,7 @@ ThreadMain(void*)
234
237
PRIntervalTime timeout;
235
238
if (gTimeout <= 0 ) {
236
239
timeout = PR_INTERVAL_NO_TIMEOUT;
237
- }
238
- else {
240
+ } else {
239
241
timeout = PR_MillisecondsToInterval (gTimeout * 500 );
240
242
}
241
243
lock.Wait (timeout);
@@ -248,8 +250,9 @@ Startup()
248
250
// The hang detector only runs in chrome processes. If you change this,
249
251
// you must also deal with the threadsafety of AnnotateCrashReport in
250
252
// non-chrome processes!
251
- if (GeckoProcessType_Default != XRE_GetProcessType ())
253
+ if (GeckoProcessType_Default != XRE_GetProcessType ()) {
252
254
return ;
255
+ }
253
256
254
257
MOZ_ASSERT (!gMonitor , " Hang monitor already initialized" );
255
258
gMonitor = new Monitor (" HangMonitor" );
@@ -261,8 +264,9 @@ Startup()
261
264
Preferences::RegisterCallback (PrefChanged, kTelemetryPrefName , nullptr );
262
265
winMainThreadHandle =
263
266
OpenThread (THREAD_ALL_ACCESS, FALSE , GetCurrentThreadId ());
264
- if (!winMainThreadHandle)
267
+ if (!winMainThreadHandle) {
265
268
return ;
269
+ }
266
270
#endif
267
271
268
272
// Don't actually start measuring hangs until we hit the main event loop.
@@ -280,12 +284,14 @@ Startup()
280
284
void
281
285
Shutdown ()
282
286
{
283
- if (GeckoProcessType_Default != XRE_GetProcessType ())
287
+ if (GeckoProcessType_Default != XRE_GetProcessType ()) {
284
288
return ;
289
+ }
285
290
286
291
MOZ_ASSERT (gMonitor , " Hang monitor not started" );
287
292
288
- { // Scope the lock we're going to delete later
293
+ {
294
+ // Scope the lock we're going to delete later
289
295
MonitorAutoLock lock (*gMonitor );
290
296
gShutdown = true ;
291
297
lock.Notify ();
@@ -307,11 +313,11 @@ IsUIMessageWaiting()
307
313
#ifndef XP_WIN
308
314
return false ;
309
315
#else
310
- #define NS_WM_IMEFIRST WM_IME_SETCONTEXT
311
- #define NS_WM_IMELAST WM_IME_KEYUP
316
+ #define NS_WM_IMEFIRST WM_IME_SETCONTEXT
317
+ #define NS_WM_IMELAST WM_IME_KEYUP
312
318
BOOL haveUIMessageWaiting = FALSE ;
313
319
MSG msg;
314
- haveUIMessageWaiting |= ::PeekMessageW (&msg, nullptr , WM_KEYFIRST,
320
+ haveUIMessageWaiting |= ::PeekMessageW (&msg, nullptr , WM_KEYFIRST,
315
321
WM_IME_KEYLAST, PM_NOREMOVE);
316
322
haveUIMessageWaiting |= ::PeekMessageW (&msg, nullptr , NS_WM_IMEFIRST,
317
323
NS_WM_IMELAST, PM_NOREMOVE);
@@ -322,32 +328,32 @@ IsUIMessageWaiting()
322
328
}
323
329
324
330
void
325
- NotifyActivity (ActivityType activityType )
331
+ NotifyActivity (ActivityType aActivityType )
326
332
{
327
333
MOZ_ASSERT (NS_IsMainThread(),
328
334
" HangMonitor::Notify called from off the main thread." );
329
335
330
336
// Determine the activity type more specifically
331
- if (activityType == kGeneralActivity ) {
332
- activityType = IsUIMessageWaiting () ? kActivityUIAVail :
333
- kActivityNoUIAVail ;
337
+ if (aActivityType == kGeneralActivity ) {
338
+ aActivityType = IsUIMessageWaiting () ? kActivityUIAVail :
339
+ kActivityNoUIAVail ;
334
340
}
335
341
336
342
// Calculate the cumulative amount of lag time since the last UI message
337
343
static uint32_t cumulativeUILagMS = 0 ;
338
- switch (activityType ) {
339
- case kActivityNoUIAVail :
340
- cumulativeUILagMS = 0 ;
341
- break ;
342
- case kActivityUIAVail :
343
- case kUIActivity :
344
- if (gTimestamp != PR_INTERVAL_NO_WAIT) {
345
- cumulativeUILagMS += PR_IntervalToMilliseconds (PR_IntervalNow () -
346
- gTimestamp );
347
- }
348
- break ;
349
- default :
350
- break ;
344
+ switch (aActivityType ) {
345
+ case kActivityNoUIAVail :
346
+ cumulativeUILagMS = 0 ;
347
+ break ;
348
+ case kActivityUIAVail :
349
+ case kUIActivity :
350
+ if (gTimestamp != PR_INTERVAL_NO_WAIT) {
351
+ cumulativeUILagMS += PR_IntervalToMilliseconds (PR_IntervalNow () -
352
+ gTimestamp );
353
+ }
354
+ break ;
355
+ default :
356
+ break ;
351
357
}
352
358
353
359
// This is not a locked activity because PRTimeStamp is a 32-bit quantity
@@ -357,7 +363,7 @@ NotifyActivity(ActivityType activityType)
357
363
358
364
// If we have UI activity we should reset the timer and report it if it is
359
365
// significant enough.
360
- if (activityType == kUIActivity ) {
366
+ if (aActivityType == kUIActivity ) {
361
367
// The minimum amount of lag time that we should report for telemetry data.
362
368
// Mozilla's UI responsiveness goal is 50ms
363
369
static const uint32_t kUIResponsivenessThresholdMS = 50 ;
@@ -387,4 +393,5 @@ Suspend()
387
393
}
388
394
}
389
395
390
- } } // namespace mozilla::HangMonitor
396
+ } // namespace HangMonitor
397
+ } // namespace mozilla
0 commit comments