Bug 959214 - Use unwinder when getting ANR native stack; r=blassey

This commit is contained in:
Jim Chen 2014-02-05 12:37:54 -06:00
Родитель 8a047f2d54
Коммит 8cc0f19e61
3 изменённых файлов: 26 добавлений и 10 удалений

Просмотреть файл

@ -54,7 +54,7 @@ public final class ANRReporter extends BroadcastReceiver
private Handler mHandler; private Handler mHandler;
private volatile boolean mPendingANR; private volatile boolean mPendingANR;
private static native boolean requestNativeStack(); private static native boolean requestNativeStack(boolean unwind);
private static native String getNativeStack(); private static native String getNativeStack();
private static native void releaseNativeStack(); private static native void releaseNativeStack();
@ -460,7 +460,9 @@ public final class ANRReporter extends BroadcastReceiver
private static void processTraces(Reader traces, File pingFile) { private static void processTraces(Reader traces, File pingFile) {
boolean haveNativeStack = requestNativeStack(); // Unwinding is memory intensive; only unwind if we have enough memory
boolean haveNativeStack = requestNativeStack(
/* unwind */ SysInfo.getMemSize() >= 640);
try { try {
OutputStream ping = new BufferedOutputStream( OutputStream ping = new BufferedOutputStream(
new FileOutputStream(pingFile), TRACES_BLOCK_SIZE); new FileOutputStream(pingFile), TRACES_BLOCK_SIZE);

Просмотреть файл

@ -533,16 +533,16 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(JNIEnv * ar
#ifdef JNI_STUBS #ifdef JNI_STUBS
typedef jboolean (*Java_org_mozilla_gecko_ANRReporter_requestNativeStack_t)(JNIEnv *, jclass); typedef jboolean (*Java_org_mozilla_gecko_ANRReporter_requestNativeStack_t)(JNIEnv *, jclass, jboolean);
static Java_org_mozilla_gecko_ANRReporter_requestNativeStack_t f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack; static Java_org_mozilla_gecko_ANRReporter_requestNativeStack_t f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack;
extern "C" NS_EXPORT jboolean JNICALL extern "C" NS_EXPORT jboolean JNICALL
Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv * arg0, jclass arg1) { Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv * arg0, jclass arg1, jboolean arg2) {
if (!f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack) { if (!f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"), arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded"); "JNI Function called before it was loaded");
return false; return false;
} }
return f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack(arg0, arg1); return f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack(arg0, arg1, arg2);
} }
#endif #endif

Просмотреть файл

@ -945,7 +945,7 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(JNIEnv* env
} }
NS_EXPORT jboolean JNICALL NS_EXPORT jboolean JNICALL
Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass) Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass, jboolean aUnwind)
{ {
if (profiler_is_active()) { if (profiler_is_active()) {
// Don't proceed if profiler is already running // Don't proceed if profiler is already running
@ -955,11 +955,25 @@ Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass)
// generally unsafe to use the profiler from off the main thread. However, // generally unsafe to use the profiler from off the main thread. However,
// the risk here is limited because for most users, the profiler is not run // the risk here is limited because for most users, the profiler is not run
// elsewhere. See the discussion in Bug 863777, comment 13 // elsewhere. See the discussion in Bug 863777, comment 13
const char *NATIVE_STACK_FEATURES[] = {"leaf", "threads", "privacy"}; const char *NATIVE_STACK_FEATURES[] =
{"leaf", "threads", "privacy"};
const char *NATIVE_STACK_UNWIND_FEATURES[] =
{"leaf", "threads", "privacy", "stackwalk"};
const char **features = NATIVE_STACK_FEATURES;
size_t features_size = sizeof(NATIVE_STACK_FEATURES);
if (aUnwind) {
features = NATIVE_STACK_UNWIND_FEATURES;
features_size = sizeof(NATIVE_STACK_UNWIND_FEATURES);
// We want the new unwinder if the unwind mode has not been set yet
putenv("MOZ_PROFILER_NEW=1");
}
const char *NATIVE_STACK_THREADS[] =
{"GeckoMain", "Compositor"};
// Buffer one sample and let the profiler wait a long time // Buffer one sample and let the profiler wait a long time
profiler_start(100, 10000, NATIVE_STACK_FEATURES, profiler_start(100, 10000, features, features_size / sizeof(char*),
sizeof(NATIVE_STACK_FEATURES) / sizeof(char*), NATIVE_STACK_THREADS, sizeof(NATIVE_STACK_THREADS) / sizeof(char*));
nullptr, 0);
return JNI_TRUE; return JNI_TRUE;
} }