Merge "Add new metric to DocumentsUI to record launch time." into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
77dc205bcb
@@ -58,6 +58,7 @@ import com.android.documentsui.model.RootInfo;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@@ -79,6 +80,7 @@ public abstract class BaseActivity extends Activity
|
||||
private int mLayoutId;
|
||||
|
||||
private boolean mNavDrawerHasFocus;
|
||||
private long mStartTime;
|
||||
|
||||
public abstract void onDocumentPicked(DocumentInfo doc, Model model);
|
||||
public abstract void onDocumentsPicked(List<DocumentInfo> docs);
|
||||
@@ -96,16 +98,14 @@ public abstract class BaseActivity extends Activity
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
// Record the time when onCreate is invoked for metric.
|
||||
mStartTime = new Date().getTime();
|
||||
|
||||
super.onCreate(icicle);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
|
||||
// If startup benchmark is requested by a whitelisted testing package, then close the
|
||||
// activity once idle, and notify the testing activity.
|
||||
if (intent.getBooleanExtra(EXTRA_BENCHMARK, false) &&
|
||||
BENCHMARK_TESTING_PACKAGE.equals(getCallingPackage())) {
|
||||
closeOnIdleForTesting();
|
||||
}
|
||||
addListenerForLaunchCompletion();
|
||||
|
||||
setContentView(mLayoutId);
|
||||
|
||||
@@ -604,12 +604,10 @@ public abstract class BaseActivity extends Activity
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void addEventListener(EventListener listener) {
|
||||
mEventListeners.add(listener);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void removeEventListener(EventListener listener) {
|
||||
mEventListeners.remove(listener);
|
||||
}
|
||||
@@ -673,6 +671,44 @@ public abstract class BaseActivity extends Activity
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the activity when it's idle.
|
||||
*/
|
||||
private void addListenerForLaunchCompletion() {
|
||||
addEventListener(new EventListener() {
|
||||
@Override
|
||||
public void onDirectoryNavigated(Uri uri) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryLoaded(Uri uri) {
|
||||
removeEventListener(this);
|
||||
getMainLooper().getQueue().addIdleHandler(new IdleHandler() {
|
||||
@Override
|
||||
public boolean queueIdle() {
|
||||
// If startup benchmark is requested by a whitelisted testing package, then
|
||||
// close the activity once idle, and notify the testing activity.
|
||||
if (getIntent().getBooleanExtra(EXTRA_BENCHMARK, false) &&
|
||||
BENCHMARK_TESTING_PACKAGE.equals(getCallingPackage())) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
||||
Metrics.logStartupMs(
|
||||
BaseActivity.this, (int) (new Date().getTime() - mStartTime));
|
||||
|
||||
// Remove the idle handler.
|
||||
return false;
|
||||
}
|
||||
});
|
||||
new Handler().post(new Runnable() {
|
||||
@Override public void run() {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final class PickRootTask extends PairedTask<BaseActivity, Void, DocumentInfo> {
|
||||
private RootInfo mRoot;
|
||||
|
||||
@@ -694,33 +730,6 @@ public abstract class BaseActivity extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the activity when it's idle. Used only for tests.
|
||||
*/
|
||||
private void closeOnIdleForTesting() {
|
||||
addEventListener(new EventListener() {
|
||||
@Override
|
||||
public void onDirectoryNavigated(Uri uri) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryLoaded(Uri uri) {
|
||||
getMainLooper().getQueue().addIdleHandler(new IdleHandler() {
|
||||
@Override
|
||||
public boolean queueIdle() {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
new Handler().post(new Runnable() {
|
||||
@Override public void run() {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final class HandleRootsChangedTask
|
||||
extends PairedTask<BaseActivity, RootInfo, RootInfo> {
|
||||
DocumentInfo mDownloadsDocument;
|
||||
|
||||
@@ -64,6 +64,7 @@ public final class Metrics {
|
||||
private static final String COUNT_FILEOP_SYSTEM = "docsui_fileop_system";
|
||||
private static final String COUNT_FILEOP_EXTERNAL = "docsui_fileop_external";
|
||||
private static final String COUNT_FILEOP_CANCELED = "docsui_fileop_canceled";
|
||||
private static final String COUNT_STARTUP_MS = "docsui_startup_ms";
|
||||
|
||||
// Indices for bucketing roots in the roots histogram. "Other" is the catch-all index for any
|
||||
// root that is not explicitly recognized by the Metrics code (see {@link
|
||||
@@ -347,7 +348,7 @@ public final class Metrics {
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the cancellation of a file operation. Call this when a Job is canceled.
|
||||
* Logs the cancellation of a file operation. Call this when a Job is canceled.
|
||||
* @param context
|
||||
* @param operationType
|
||||
*/
|
||||
@@ -355,6 +356,15 @@ public final class Metrics {
|
||||
logHistogram(context, COUNT_FILEOP_CANCELED, toMetricsOpType(operationType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs startup time in milliseconds.
|
||||
* @param context
|
||||
* @param startupMs Startup time in milliseconds.
|
||||
*/
|
||||
public static void logStartupMs(Context context, int startupMs) {
|
||||
logHistogram(context, COUNT_STARTUP_MS, startupMs);
|
||||
}
|
||||
|
||||
private static void logInterProviderFileOps(
|
||||
Context context,
|
||||
String histogram,
|
||||
|
||||
Reference in New Issue
Block a user