Commit 945bef09 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Only report GURL metrics/traces on the UI thread.

If GURL is used from a background thread during startup, we don't care
about the time it takes to load GURL as it's not blocking startup.

See https://crbug.com/1065377, the initial stack trace reports are all
coming from background threads.

Bug: 783819
Change-Id: Ifa9b998dbeda974f644aa70686761b366460fd2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124297Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754037}
parent 957f13ce
...@@ -10,6 +10,7 @@ import android.text.TextUtils; ...@@ -10,6 +10,7 @@ import android.text.TextUtils;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
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 org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
...@@ -98,17 +99,21 @@ public class GURL { ...@@ -98,17 +99,21 @@ public class GURL {
*/ */
public static void ensureNativeInitializedForGURL() { public static void ensureNativeInitializedForGURL() {
if (LibraryLoader.getInstance().isInitialized()) return; if (LibraryLoader.getInstance().isInitialized()) return;
if (sReportCallback != null && new Random().nextInt(100) < DEBUG_REPORT_PERCENTAGE) {
final Throwable throwable = new Throwable("This is not a crash, please ignore.");
// This isn't an assert, because by design this is possible, but this path is getting
// hit much more than expected and getting stack traces from the wild will help debug.
PostTask.postTask(
TaskTraits.BEST_EFFORT_MAY_BLOCK, () -> { sReportCallback.run(throwable); });
}
long time = SystemClock.elapsedRealtime(); long time = SystemClock.elapsedRealtime();
LibraryLoader.getInstance().ensureMainDexInitialized(); LibraryLoader.getInstance().ensureMainDexInitialized();
RecordHistogram.recordTimesHistogram("Startup.Android.GURLEnsureMainDexInitialized", // Record metrics only for the UI thread where the delay in loading the library is relevant.
SystemClock.elapsedRealtime() - time); if (ThreadUtils.runningOnUiThread()) {
RecordHistogram.recordTimesHistogram("Startup.Android.GURLEnsureMainDexInitialized",
SystemClock.elapsedRealtime() - time);
if (sReportCallback != null && new Random().nextInt(100) < DEBUG_REPORT_PERCENTAGE) {
final Throwable throwable = new Throwable("This is not a crash, please ignore.");
// This isn't an assert, because by design this is possible, but we would prefer
// this path does not get hit more than necessary and getting stack traces from the
// wild will help find issues.
PostTask.postTask(TaskTraits.BEST_EFFORT_MAY_BLOCK,
() -> { sReportCallback.run(throwable); });
}
}
} }
@CalledByNative @CalledByNative
......
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