Merge changes I66eac0c5,I07602072 into qt-dev am: e252d155b1
am: 02f4c40623
Change-Id: I33d2191b2e499a0febebd7ea55d9f294bd49f0f9
This commit is contained in:
@@ -713,16 +713,20 @@ static bool dumpTraces(JNIEnv* env, jint pid, jstring fileName, jint timeoutSecs
|
||||
O_CREAT | O_WRONLY | O_NOFOLLOW | O_CLOEXEC | O_APPEND,
|
||||
0666));
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Can't open %s: %s\n", fileNameChars.c_str(), strerror(errno));
|
||||
PLOG(ERROR) << "Can't open " << fileNameChars.c_str();
|
||||
return false;
|
||||
}
|
||||
|
||||
return (dump_backtrace_to_file_timeout(pid, dumpType, timeoutSecs, fd) == 0);
|
||||
int res = dump_backtrace_to_file_timeout(pid, dumpType, timeoutSecs, fd);
|
||||
if (fdatasync(fd.get()) != 0) {
|
||||
PLOG(ERROR) << "Failed flushing trace.";
|
||||
}
|
||||
return res == 0;
|
||||
}
|
||||
|
||||
static jboolean android_os_Debug_dumpJavaBacktraceToFileTimeout(JNIEnv* env, jobject clazz,
|
||||
jint pid, jstring fileName, jint timeoutSecs) {
|
||||
const bool ret = dumpTraces(env, pid, fileName, timeoutSecs, kDebuggerdJavaBacktrace);
|
||||
const bool ret = dumpTraces(env, pid, fileName, timeoutSecs, kDebuggerdJavaBacktrace);
|
||||
return ret ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -547,6 +547,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
private static final int MAX_BUGREPORT_TITLE_SIZE = 50;
|
||||
|
||||
private static final int NATIVE_DUMP_TIMEOUT_MS = 2000; // 2 seconds;
|
||||
private static final int JAVA_DUMP_MINIMUM_SIZE = 100; // 100 bytes.
|
||||
|
||||
OomAdjuster mOomAdjuster;
|
||||
final LowMemDetector mLowMemDetector;
|
||||
@@ -3805,9 +3806,28 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
*/
|
||||
private static long dumpJavaTracesTombstoned(int pid, String fileName, long timeoutMs) {
|
||||
final long timeStart = SystemClock.elapsedRealtime();
|
||||
if (!Debug.dumpJavaBacktraceToFileTimeout(pid, fileName, (int) (timeoutMs / 1000))) {
|
||||
Debug.dumpNativeBacktraceToFileTimeout(pid, fileName,
|
||||
(NATIVE_DUMP_TIMEOUT_MS / 1000));
|
||||
boolean javaSuccess = Debug.dumpJavaBacktraceToFileTimeout(pid, fileName,
|
||||
(int) (timeoutMs / 1000));
|
||||
if (javaSuccess) {
|
||||
// Check that something is in the file, actually. Try-catch should not be necessary,
|
||||
// but better safe than sorry.
|
||||
try {
|
||||
long size = new File(fileName).length();
|
||||
if (size < JAVA_DUMP_MINIMUM_SIZE) {
|
||||
Slog.w(TAG, "Successfully created Java ANR file is empty!");
|
||||
javaSuccess = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Slog.w(TAG, "Unable to get ANR file size", e);
|
||||
javaSuccess = false;
|
||||
}
|
||||
}
|
||||
if (!javaSuccess) {
|
||||
Slog.w(TAG, "Dumping Java threads failed, initiating native stack dump.");
|
||||
if (!Debug.dumpNativeBacktraceToFileTimeout(pid, fileName,
|
||||
(NATIVE_DUMP_TIMEOUT_MS / 1000))) {
|
||||
Slog.w(TAG, "Native stack dump failed!");
|
||||
}
|
||||
}
|
||||
|
||||
return SystemClock.elapsedRealtime() - timeStart;
|
||||
|
||||
Reference in New Issue
Block a user