Commit e85629a5 authored by Tim Volodine's avatar Tim Volodine Committed by Commit Bot

[Android WebView] Update AwTracingController with new API and logic

This patch updates the AwTracingController to reflect the newly
updated Android API. Also moves and extends some logic from the
glue layer to chromium.

Note: some obsolete bits will be removed in a follow-up patch
in order to no break compile. This will happen once chromium
rolls downstream and the glue layer is properly updated.

BUG=781249

Change-Id: I35d3938560e24c172ae598d11ad2dc0540a9e665
Reviewed-on: https://chromium-review.googlesource.com/922205Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Tim Volodine <timvolodine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537423}
parent 1f3669c3
...@@ -5,10 +5,19 @@ ...@@ -5,10 +5,19 @@
package org.chromium.android_webview; package org.chromium.android_webview;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
/** /**
* Manages tracing functionality in WebView. * Manages tracing functionality in WebView.
*/ */
...@@ -16,14 +25,52 @@ import org.chromium.base.annotations.JNINamespace; ...@@ -16,14 +25,52 @@ import org.chromium.base.annotations.JNINamespace;
public class AwTracingController { public class AwTracingController {
private static final String TAG = "cr.AwTracingController"; private static final String TAG = "cr.AwTracingController";
public static final int CATEGORIES_ALL = 0;
public static final int CATEGORIES_ANDROID_WEBVIEW = 1;
public static final int CATEGORIES_WEB_DEVELOPER = 2;
public static final int CATEGORIES_INPUT_LATENCY = 3;
public static final int CATEGORIES_RENDERING = 4;
public static final int CATEGORIES_JAVASCRIPT_AND_RENDERING = 5;
public static final int CATEGORIES_FRAME_VIEWER = 6;
private static final List<String> CATEGORIES_ALL_LIST = new ArrayList<>(Arrays.asList("*"));
private static final List<String> CATEGORIES_ANDROID_WEBVIEW_LIST =
new ArrayList<>(Arrays.asList("blink", "android_webview", "Java", "toplevel"));
private static final List<String> CATEGORIES_WEB_DEVELOPER_LIST = new ArrayList<>(
Arrays.asList("blink", "cc", "netlog", "renderer.scheduler", "toplevel", "v8"));
private static final List<String> CATEGORIES_INPUT_LATENCY_LIST = new ArrayList<>(
Arrays.asList("benchmark", "input", "evdev", "renderer.scheduler", "toplevel"));
private static final List<String> CATEGORIES_RENDERING_LIST =
new ArrayList<>(Arrays.asList("blink", "cc", "gpu", "toplevel"));
private static final List<String> CATEGORIES_JAVASCRIPT_AND_RENDERING_LIST = new ArrayList<>(
Arrays.asList("blink", "cc", "gpu", "renderer.scheduler", "v8", "toplevel"));
private static final List<String> CATEGORIES_FRAME_VIEWER_LIST = new ArrayList<>(
Arrays.asList("blink", "cc", "gpu", "renderer.scheduler", "v8", "toplevel",
"disabled-by-default-cc.debug", "disabled-by-default-cc.debug.picture",
"disabled-by-default-cc.debug.display_items"));
private static final List<List<String>> PREDEFINED_CATEGORIES_LIST =
new ArrayList<List<String>>(Arrays.asList(CATEGORIES_ALL_LIST, // CATEGORIES_ALL
CATEGORIES_ANDROID_WEBVIEW_LIST, // CATEGORIES_ANDROID_WEBVIEW
CATEGORIES_WEB_DEVELOPER_LIST, // CATEGORIES_WEB_DEVELOPER
CATEGORIES_INPUT_LATENCY_LIST, // CATEGORIES_INPUT_LATENCY
CATEGORIES_RENDERING_LIST, // CATEGORIES_RENDERING
CATEGORIES_JAVASCRIPT_AND_RENDERING_LIST, // CATEGORIES_JAVASCRIPT_AND_RENDERING
CATEGORIES_FRAME_VIEWER_LIST // CATEGORIES_FRAME_VIEWER
));
// TODO(timvolodine): remove once glue layer is updated, crbug.com/812289.
private AwTracingOutputStream mOutputStream; private AwTracingOutputStream mOutputStream;
// TODO: consider caching a mIsTracing value for efficiency. private OutputStream mOutputStreamNew;
// TODO(timvolodine): consider caching a mIsTracing value for efficiency.
// boolean mIsTracing; // boolean mIsTracing;
/** /**
* Interface for the callbacks to return tracing data. * Interface for the callbacks to return tracing data.
*/ */
// TODO(timvolodine): remove once glue layer is updated, crbug.com/812289.
public interface AwTracingOutputStream { public interface AwTracingOutputStream {
public void write(byte[] chunk); public void write(byte[] chunk);
public void complete(); public void complete();
...@@ -33,6 +80,18 @@ public class AwTracingController { ...@@ -33,6 +80,18 @@ public class AwTracingController {
mNativeAwTracingController = nativeInit(); mNativeAwTracingController = nativeInit();
} }
// Start tracing
public void start(Collection<Integer> predefinedCategories,
Collection<String> customIncludedCategories, int mode) {
if (isTracing()) {
throw new IllegalArgumentException("Cannot start tracing: tracing is already enabled");
}
String categoryFilter =
constructCategoryFilterString(predefinedCategories, customIncludedCategories);
nativeStart(mNativeAwTracingController, categoryFilter, mode);
}
// TODO(timvolodine): remove once glue layer is updated, crbug.com/812289.
// Start tracing. // Start tracing.
public boolean start(String categoryFilter, int mode) { public boolean start(String categoryFilter, int mode) {
if (isTracing()) { if (isTracing()) {
...@@ -43,6 +102,7 @@ public class AwTracingController { ...@@ -43,6 +102,7 @@ public class AwTracingController {
return result; return result;
} }
// TODO(timvolodine): remove once glue layer is updated, crbug.com/812289.
// Stop tracing and flush tracing data. // Stop tracing and flush tracing data.
public boolean stopAndFlush(@Nullable AwTracingOutputStream outputStream) { public boolean stopAndFlush(@Nullable AwTracingOutputStream outputStream) {
if (!isTracing()) return false; if (!isTracing()) return false;
...@@ -51,22 +111,65 @@ public class AwTracingController { ...@@ -51,22 +111,65 @@ public class AwTracingController {
return true; return true;
} }
// Stop tracing and flush tracing data.
public boolean stopAndFlush(@Nullable OutputStream outputStream) {
if (!isTracing()) return false;
mOutputStreamNew = outputStream;
nativeStopAndFlush(mNativeAwTracingController);
return true;
}
public boolean isTracing() { public boolean isTracing() {
return nativeIsTracing(mNativeAwTracingController); return nativeIsTracing(mNativeAwTracingController);
} }
private String constructCategoryFilterString(
Collection<Integer> predefinedCategories, Collection<String> customIncludedCategories) {
// Make sure to remove any doubles in category patterns.
HashSet<String> categoriesSet = new HashSet<String>();
for (int predefinedCategoriesIndex : predefinedCategories) {
categoriesSet.addAll(PREDEFINED_CATEGORIES_LIST.get(predefinedCategoriesIndex));
}
for (String categoryPattern : customIncludedCategories) {
if (isValidPattern(categoryPattern)) {
categoriesSet.add(categoryPattern);
} else {
throw new IllegalArgumentException(
"category patterns starting with '-' or containing ',' are not allowed");
}
}
if (categoriesSet.isEmpty()) {
// when no categories are specified -- exclude everything
categoriesSet.add("-*");
}
return TextUtils.join(",", categoriesSet);
}
private boolean isValidPattern(String pattern) {
// do not allow 'excluded' patterns or comma separated strings
return !pattern.startsWith("-") && !pattern.contains(",");
}
@CalledByNative @CalledByNative
private void onTraceDataChunkReceived(byte[] data) { private void onTraceDataChunkReceived(byte[] data) throws IOException {
// TODO(timvolodine): remove once glue layer is updated, crbug.com/812289.
if (mOutputStream != null) { if (mOutputStream != null) {
mOutputStream.write(data); mOutputStream.write(data);
} }
if (mOutputStreamNew != null) {
mOutputStreamNew.write(data);
}
} }
@CalledByNative @CalledByNative
private void onTraceDataComplete() { private void onTraceDataComplete() throws IOException {
// TODO(timvolodine): remove once glue layer is updated, crbug.com/812289.
if (mOutputStream != null) { if (mOutputStream != null) {
mOutputStream.complete(); mOutputStream.complete();
} }
if (mOutputStreamNew != null) {
mOutputStreamNew.close();
}
} }
private long mNativeAwTracingController; private long mNativeAwTracingController;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment