From 2905f6f492c34db684d53bac6e438c1d81fc0314 Mon Sep 17 00:00:00 2001 From: zachh Date: Tue, 20 Feb 2018 21:50:53 -0800 Subject: Record jank metrics in old and new call logs. Bug: 70989667 Test: unit PiperOrigin-RevId: 186410938 Change-Id: I0671ab0bbbe957b8f034c673e6309204284756d2 --- .../dialer/app/calllog/CallLogFragment.java | 7 ++++ java/com/android/dialer/buildtype/BuildType.java | 20 ++++++---- .../buildtype/release/BuildTypeAccessorImpl.java | 3 +- .../dialer/calllog/ui/NewCallLogFragment.java | 7 ++++ .../dialer/commandline/CommandLineReceiver.java | 3 +- .../android/dialer/logging/LoggingBindings.java | 3 ++ java/com/android/dialer/metrics/Metrics.java | 6 +++ java/com/android/dialer/metrics/StubMetrics.java | 6 +++ .../metrics/jank/RecyclerViewJankLogger.java | 46 ++++++++++++++++++++++ .../dialer/simulator/impl/SimulatorImpl.java | 3 +- .../android/dialer/strictmode/StrictModeUtils.java | 3 +- 11 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 java/com/android/dialer/metrics/jank/RecyclerViewJankLogger.java (limited to 'java') diff --git a/java/com/android/dialer/app/calllog/CallLogFragment.java b/java/com/android/dialer/app/calllog/CallLogFragment.java index 6b6b92297..6b6239da4 100644 --- a/java/com/android/dialer/app/calllog/CallLogFragment.java +++ b/java/com/android/dialer/app/calllog/CallLogFragment.java @@ -63,6 +63,9 @@ import com.android.dialer.database.CallLogQueryHandler.Listener; import com.android.dialer.location.GeoUtil; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.logging.LoggingBindings; +import com.android.dialer.metrics.MetricsComponent; +import com.android.dialer.metrics.jank.RecyclerViewJankLogger; import com.android.dialer.oem.CequintCallerIdManager; import com.android.dialer.performancereport.PerformanceReport; import com.android.dialer.phonenumbercache.ContactInfoHelper; @@ -306,6 +309,10 @@ public class CallLogFragment extends Fragment protected void setupView(View view) { recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); + recyclerView.addOnScrollListener( + new RecyclerViewJankLogger( + MetricsComponent.get(getContext()).metrics(), + LoggingBindings.OLD_CALL_LOG_JANK_EVENT_NAME)); layoutManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(layoutManager); PerformanceReport.logOnScrollStateChange(recyclerView); diff --git a/java/com/android/dialer/buildtype/BuildType.java b/java/com/android/dialer/buildtype/BuildType.java index 6b6bc2906..c5c41d247 100644 --- a/java/com/android/dialer/buildtype/BuildType.java +++ b/java/com/android/dialer/buildtype/BuildType.java @@ -28,15 +28,19 @@ public class BuildType { /** The type of build. */ @Retention(RetentionPolicy.SOURCE) @IntDef({ - BUGFOOD, FISHFOOD, DOGFOOD, RELEASE, TEST, + Type.BUGFOOD, + Type.FISHFOOD, + Type.DOGFOOD, + Type.RELEASE, + Type.TEST, }) - public @interface Type {} - - public static final int BUGFOOD = 1; - public static final int FISHFOOD = 2; - public static final int DOGFOOD = 3; - public static final int RELEASE = 4; - public static final int TEST = 5; + public @interface Type { + int BUGFOOD = 1; + int FISHFOOD = 2; + int DOGFOOD = 3; + int RELEASE = 4; + int TEST = 5; + } private static int cachedBuildType; private static boolean didInitializeBuildType; diff --git a/java/com/android/dialer/buildtype/release/BuildTypeAccessorImpl.java b/java/com/android/dialer/buildtype/release/BuildTypeAccessorImpl.java index 70b9f9e37..4019dd011 100644 --- a/java/com/android/dialer/buildtype/release/BuildTypeAccessorImpl.java +++ b/java/com/android/dialer/buildtype/release/BuildTypeAccessorImpl.java @@ -16,6 +16,7 @@ package com.android.dialer.buildtype; +import com.android.dialer.buildtype.BuildType.Type; import com.android.dialer.proguard.UsedByReflection; /** Gets the build type. */ @@ -25,6 +26,6 @@ public class BuildTypeAccessorImpl implements BuildTypeAccessor { @Override @BuildType.Type public int getBuildType() { - return BuildType.RELEASE; + return Type.RELEASE; } } diff --git a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java index d0f42d335..bbd16fbf1 100644 --- a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java +++ b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java @@ -33,6 +33,9 @@ import com.android.dialer.calllog.RefreshAnnotatedCallLogReceiver; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DefaultFutureCallback; import com.android.dialer.common.concurrent.ThreadUtil; +import com.android.dialer.logging.LoggingBindings; +import com.android.dialer.metrics.MetricsComponent; +import com.android.dialer.metrics.jank.RecyclerViewJankLogger; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.TimeUnit; @@ -170,6 +173,10 @@ public final class NewCallLogFragment extends Fragment implements LoaderCallback View view = inflater.inflate(R.layout.new_call_log_fragment, container, false); recyclerView = view.findViewById(R.id.new_call_log_recycler_view); + recyclerView.addOnScrollListener( + new RecyclerViewJankLogger( + MetricsComponent.get(getContext()).metrics(), + LoggingBindings.NEW_CALL_LOG_JANK_EVENT_NAME)); getLoaderManager().restartLoader(0, null, this); diff --git a/java/com/android/dialer/commandline/CommandLineReceiver.java b/java/com/android/dialer/commandline/CommandLineReceiver.java index e5e78c46a..effca2e92 100644 --- a/java/com/android/dialer/commandline/CommandLineReceiver.java +++ b/java/com/android/dialer/commandline/CommandLineReceiver.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.Intent; import android.text.TextUtils; import com.android.dialer.buildtype.BuildType; +import com.android.dialer.buildtype.BuildType.Type; import com.android.dialer.commandline.Command.IllegalCommandLineArgumentException; import com.android.dialer.common.LogUtil; import com.google.common.util.concurrent.FutureCallback; @@ -44,7 +45,7 @@ public class CommandLineReceiver extends BroadcastReceiver { LogUtil.e("CommandLineReceiver", "missing tag"); return; } - if (!LogUtil.isDebugEnabled() && BuildType.get() != BuildType.BUGFOOD) { + if (!LogUtil.isDebugEnabled() && BuildType.get() != Type.BUGFOOD) { LogUtil.i(outputTag, "DISABLED"); return; } diff --git a/java/com/android/dialer/logging/LoggingBindings.java b/java/com/android/dialer/logging/LoggingBindings.java index ec98ed124..a093c4f6b 100644 --- a/java/com/android/dialer/logging/LoggingBindings.java +++ b/java/com/android/dialer/logging/LoggingBindings.java @@ -29,6 +29,9 @@ public interface LoggingBindings { String ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME = "GoogleDialtactsActivity.onResume"; String INCALL_ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME = "IncallActivity.OnResume"; String INCALL_ACTIVITY_ON_STOP_MEMORY_EVENT_NAME = "IncallActivity.OnStop"; + String OLD_CALL_LOG_JANK_EVENT_NAME = "OldCallLog.Jank"; + String NEW_CALL_LOG_JANK_EVENT_NAME = "NewCallLog.Jank"; + /** * Logs an DialerImpression event that's not associated with a specific call. * diff --git a/java/com/android/dialer/metrics/Metrics.java b/java/com/android/dialer/metrics/Metrics.java index 3922a8cfa..7cdfa220e 100644 --- a/java/com/android/dialer/metrics/Metrics.java +++ b/java/com/android/dialer/metrics/Metrics.java @@ -28,6 +28,12 @@ public interface Metrics { /** Stop a timer. */ void stopTimer(String timerEventName); + /** Start a jank recorder. */ + void startJankRecorder(String eventName); + + /** Stop a jank recorder. */ + void stopJankRecorder(String eventName); + /** Record memory. */ void recordMemory(String memoryEventName); diff --git a/java/com/android/dialer/metrics/StubMetrics.java b/java/com/android/dialer/metrics/StubMetrics.java index 114eb4308..f4d41e2d2 100644 --- a/java/com/android/dialer/metrics/StubMetrics.java +++ b/java/com/android/dialer/metrics/StubMetrics.java @@ -31,6 +31,12 @@ public final class StubMetrics implements Metrics { @Override public void stopTimer(String timerEventName) {} + @Override + public void startJankRecorder(String eventName) {} + + @Override + public void stopJankRecorder(String eventName) {} + @Override public void recordMemory(String memoryEventName) {} } diff --git a/java/com/android/dialer/metrics/jank/RecyclerViewJankLogger.java b/java/com/android/dialer/metrics/jank/RecyclerViewJankLogger.java new file mode 100644 index 000000000..c9f389285 --- /dev/null +++ b/java/com/android/dialer/metrics/jank/RecyclerViewJankLogger.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.metrics.jank; + +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.RecyclerView.OnScrollListener; +import com.android.dialer.metrics.Metrics; + +/** Logs jank for {@link RecyclerView} scrolling events. */ +public final class RecyclerViewJankLogger extends OnScrollListener { + + private final Metrics metrics; + private final String eventName; + + private boolean isScrolling; + + public RecyclerViewJankLogger(Metrics metrics, String eventName) { + this.metrics = metrics; + this.eventName = eventName; + } + + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + if (!isScrolling && newState == RecyclerView.SCROLL_STATE_DRAGGING) { + isScrolling = true; + metrics.startJankRecorder(eventName); + } else if (isScrolling && newState == RecyclerView.SCROLL_STATE_IDLE) { + isScrolling = false; + metrics.stopJankRecorder(eventName); + } + } +} diff --git a/java/com/android/dialer/simulator/impl/SimulatorImpl.java b/java/com/android/dialer/simulator/impl/SimulatorImpl.java index 24f34102e..c8b8af92e 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorImpl.java +++ b/java/com/android/dialer/simulator/impl/SimulatorImpl.java @@ -19,6 +19,7 @@ package com.android.dialer.simulator.impl; import android.support.v7.app.AppCompatActivity; import android.view.ActionProvider; import com.android.dialer.buildtype.BuildType; +import com.android.dialer.buildtype.BuildType.Type; import com.android.dialer.common.LogUtil; import com.android.dialer.simulator.Simulator; import javax.inject.Inject; @@ -33,7 +34,7 @@ final class SimulatorImpl implements Simulator { @Override public boolean shouldShow() { - return BuildType.get() == BuildType.BUGFOOD || LogUtil.isDebugEnabled(); + return BuildType.get() == Type.BUGFOOD || LogUtil.isDebugEnabled(); } @Override diff --git a/java/com/android/dialer/strictmode/StrictModeUtils.java b/java/com/android/dialer/strictmode/StrictModeUtils.java index c07138f81..27f8142d8 100644 --- a/java/com/android/dialer/strictmode/StrictModeUtils.java +++ b/java/com/android/dialer/strictmode/StrictModeUtils.java @@ -25,6 +25,7 @@ import android.preference.PreferenceManager; import android.support.annotation.AnyThread; import android.support.v4.os.UserManagerCompat; import com.android.dialer.buildtype.BuildType; +import com.android.dialer.buildtype.BuildType.Type; import com.android.dialer.function.Supplier; import com.android.dialer.storage.StorageComponent; @@ -86,7 +87,7 @@ public final class StrictModeUtils { } public static boolean isStrictModeAllowed() { - return BuildType.get() == BuildType.BUGFOOD; + return BuildType.get() == Type.BUGFOOD; } private static boolean onMainThread() { -- cgit v1.2.3