Merge "Automatically trace messages on shared loopers." into nyc-dev
am: 94cac07
* commit '94cac0730a23525559ded53bfaaee5a529b80aab':
Automatically trace messages on shared loopers.
Change-Id: Ifbc34c8d15b23ca55782ecee0973e36f33441c72
This commit is contained in:
@@ -231,6 +231,18 @@ public class Handler {
|
|||||||
mAsynchronous = async;
|
mAsynchronous = async;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@hide} */
|
||||||
|
public String getTraceName(Message message) {
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getClass().getName()).append(": ");
|
||||||
|
if (message.callback != null) {
|
||||||
|
sb.append(message.callback.getClass().getName());
|
||||||
|
} else {
|
||||||
|
sb.append("#").append(message.what);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string representing the name of the specified message.
|
* Returns a string representing the name of the specified message.
|
||||||
* The default implementation will either return the class name of the
|
* The default implementation will either return the class name of the
|
||||||
@@ -739,8 +751,8 @@ public class Handler {
|
|||||||
message.callback.run();
|
message.callback.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
final MessageQueue mQueue;
|
|
||||||
final Looper mLooper;
|
final Looper mLooper;
|
||||||
|
final MessageQueue mQueue;
|
||||||
final Callback mCallback;
|
final Callback mCallback;
|
||||||
final boolean mAsynchronous;
|
final boolean mAsynchronous;
|
||||||
IMessenger mMessenger;
|
IMessenger mMessenger;
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public final class Looper {
|
|||||||
final Thread mThread;
|
final Thread mThread;
|
||||||
|
|
||||||
private Printer mLogging;
|
private Printer mLogging;
|
||||||
|
private long mTraceTag;
|
||||||
|
|
||||||
/** Initialize the current thread as a looper.
|
/** Initialize the current thread as a looper.
|
||||||
* This gives you a chance to create handlers that then reference
|
* This gives you a chance to create handlers that then reference
|
||||||
@@ -139,13 +140,23 @@ public final class Looper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This must be in a local variable, in case a UI event sets the logger
|
// This must be in a local variable, in case a UI event sets the logger
|
||||||
Printer logging = me.mLogging;
|
final Printer logging = me.mLogging;
|
||||||
if (logging != null) {
|
if (logging != null) {
|
||||||
logging.println(">>>>> Dispatching to " + msg.target + " " +
|
logging.println(">>>>> Dispatching to " + msg.target + " " +
|
||||||
msg.callback + ": " + msg.what);
|
msg.callback + ": " + msg.what);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.target.dispatchMessage(msg);
|
final long traceTag = me.mTraceTag;
|
||||||
|
if (traceTag != 0) {
|
||||||
|
Trace.traceBegin(traceTag, msg.target.getTraceName(msg));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
msg.target.dispatchMessage(msg);
|
||||||
|
} finally {
|
||||||
|
if (traceTag != 0) {
|
||||||
|
Trace.traceEnd(traceTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (logging != null) {
|
if (logging != null) {
|
||||||
logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);
|
logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);
|
||||||
@@ -208,6 +219,11 @@ public final class Looper {
|
|||||||
mLogging = printer;
|
mLogging = printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@hide} */
|
||||||
|
public void setTraceTag(long traceTag) {
|
||||||
|
mTraceTag = traceTag;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quits the looper.
|
* Quits the looper.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.internal.os;
|
|||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
|
import android.os.Trace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared singleton background thread for each process.
|
* Shared singleton background thread for each process.
|
||||||
@@ -34,6 +35,7 @@ public final class BackgroundThread extends HandlerThread {
|
|||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new BackgroundThread();
|
sInstance = new BackgroundThread();
|
||||||
sInstance.start();
|
sInstance.start();
|
||||||
|
sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
sHandler = new Handler(sInstance.getLooper());
|
sHandler = new Handler(sInstance.getLooper());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Trace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared singleton foreground thread for the system. This is a thread for
|
* Shared singleton foreground thread for the system. This is a thread for
|
||||||
@@ -36,6 +37,7 @@ public final class DisplayThread extends ServiceThread {
|
|||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new DisplayThread();
|
sInstance = new DisplayThread();
|
||||||
sInstance.start();
|
sInstance.start();
|
||||||
|
sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
sHandler = new Handler(sInstance.getLooper());
|
sHandler = new Handler(sInstance.getLooper());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Trace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared singleton foreground thread for the system. This is a thread for regular
|
* Shared singleton foreground thread for the system. This is a thread for regular
|
||||||
@@ -38,6 +39,7 @@ public final class FgThread extends ServiceThread {
|
|||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new FgThread();
|
sInstance = new FgThread();
|
||||||
sInstance.start();
|
sInstance.start();
|
||||||
|
sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
sHandler = new Handler(sInstance.getLooper());
|
sHandler = new Handler(sInstance.getLooper());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Trace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared singleton I/O thread for the system. This is a thread for non-background
|
* Shared singleton I/O thread for the system. This is a thread for non-background
|
||||||
@@ -35,6 +36,7 @@ public final class IoThread extends ServiceThread {
|
|||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new IoThread();
|
sInstance = new IoThread();
|
||||||
sInstance.start();
|
sInstance.start();
|
||||||
|
sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
sHandler = new Handler(sInstance.getLooper());
|
sHandler = new Handler(sInstance.getLooper());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Trace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared singleton thread for showing UI. This is a foreground thread, and in
|
* Shared singleton thread for showing UI. This is a foreground thread, and in
|
||||||
@@ -35,6 +36,7 @@ public final class UiThread extends ServiceThread {
|
|||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new UiThread();
|
sInstance = new UiThread();
|
||||||
sInstance.start();
|
sInstance.start();
|
||||||
|
sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
sHandler = new Handler(sInstance.getLooper());
|
sHandler = new Handler(sInstance.getLooper());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user