Skip to content

Commit

Permalink
Remove dead code for loggingViewAsyncDrawee
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D59057271

fbshipit-source-id: d2d842158737a471c573ba6a415c918bc29607eb
  • Loading branch information
steelrooter authored and facebook-github-bot committed Jun 26, 2024
1 parent a8c2f66 commit efd8d39
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@ protected synchronized void initializePerformanceMonitoring(
ImageRequest,
CloseableReference<CloseableImage>,
ImageInfo>
builder,
Supplier<Boolean> asyncLogging) {
builder) {
if (mImagePerfMonitor != null) {
mImagePerfMonitor.reset();
}
if (imagePerfDataListener != null) {
if (mImagePerfMonitor == null) {
mImagePerfMonitor = new ImagePerfMonitor(AwakeTimeSinceBootClock.get(), this, asyncLogging);
mImagePerfMonitor = new ImagePerfMonitor(AwakeTimeSinceBootClock.get(), this);
}
mImagePerfMonitor.addImagePerfDataListener(imagePerfDataListener);
mImagePerfMonitor.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.facebook.cache.common.CacheKey;
import com.facebook.common.internal.ImmutableList;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.Suppliers;
import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.DataSource;
import com.facebook.drawee.backends.pipeline.info.ImageOriginListener;
Expand Down Expand Up @@ -133,8 +132,7 @@ protected PipelineDraweeController obtainController() {
getCacheKey(),
getCallerContext(),
mCustomDrawableFactories);
controller.initializePerformanceMonitoring(
mImagePerfDataListener, this, Suppliers.BOOLEAN_FALSE);
controller.initializePerformanceMonitoring(mImagePerfDataListener, this);
return controller;
} finally {
if (FrescoSystrace.isTracing()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.facebook.drawee.backends.pipeline.info;

import android.graphics.Rect;
import com.facebook.common.internal.Supplier;
import com.facebook.common.time.MonotonicClock;
import com.facebook.drawee.backends.pipeline.PipelineDraweeController;
import com.facebook.drawee.backends.pipeline.info.internal.ImagePerfControllerListener2;
Expand All @@ -26,13 +25,12 @@
import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.Nullable;

@Nullsafe(Nullsafe.Mode.STRICT)
@Nullsafe(Nullsafe.Mode.LOCAL)
public class ImagePerfMonitor implements ImagePerfNotifier {

private final PipelineDraweeController mPipelineDraweeController;
private final MonotonicClock mMonotonicClock;
private final ImagePerfState mImagePerfState;
private final Supplier<Boolean> mAsyncLogging;

private @Nullable ImagePerfRequestListener mImagePerfRequestListener;
private @Nullable ImagePerfControllerListener2 mImagePerfControllerListener2;
Expand All @@ -43,13 +41,10 @@ public class ImagePerfMonitor implements ImagePerfNotifier {
private boolean mEnabled;

public ImagePerfMonitor(
MonotonicClock monotonicClock,
PipelineDraweeController pipelineDraweeController,
Supplier<Boolean> asyncLogging) {
MonotonicClock monotonicClock, PipelineDraweeController pipelineDraweeController) {
mMonotonicClock = monotonicClock;
mPipelineDraweeController = pipelineDraweeController;
mImagePerfState = new ImagePerfState();
mAsyncLogging = asyncLogging;
}

public void setEnabled(boolean enabled) {
Expand Down Expand Up @@ -135,7 +130,7 @@ public void addViewportData() {
private void setupListeners() {
if (mImagePerfControllerListener2 == null) {
mImagePerfControllerListener2 =
new ImagePerfControllerListener2(mMonotonicClock, mImagePerfState, this, mAsyncLogging);
new ImagePerfControllerListener2(mMonotonicClock, mImagePerfState, this);
}
if (mImagePerfRequestListener == null) {
mImagePerfRequestListener = new ImagePerfRequestListener(mMonotonicClock, mImagePerfState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@

package com.facebook.drawee.backends.pipeline.info.internal;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.Supplier;
import com.facebook.common.time.MonotonicClock;
import com.facebook.drawee.drawable.VisibilityCallback;
import com.facebook.fresco.ui.common.BaseControllerListener2;
Expand All @@ -38,96 +31,35 @@ public class ImagePerfControllerListener2 extends BaseControllerListener2<ImageI
Closeable,
VisibilityCallback {

private static final int WHAT_STATUS = 1;
private static final int WHAT_VISIBILITY = 2;

private static @Nullable LogHandler sHandler;

private final MonotonicClock mClock;
private final ImagePerfState mImagePerfState;
private final ImagePerfNotifier mImagePerfNotifier;
private final Supplier<Boolean> mAsyncLogging;

private @Nullable ImagePerfNotifier mLocalImagePerfNotifier = null;

private final boolean mReportVisibleOnSubmitAndRelease;

static class LogHandler extends Handler implements ImagePerfNotifierHolder {

private final ImagePerfNotifier mNotifier;
private @Nullable ImagePerfNotifier mLocalNotifier;

public LogHandler(
@NonNull Looper looper,
@NonNull ImagePerfNotifier notifier,
@Nullable ImagePerfNotifier localNotifier) {
super(looper);
mNotifier = notifier;
mLocalNotifier = localNotifier;
}

@Override
public void setImagePerfNotifier(@Nullable ImagePerfNotifier imagePerfNotifier) {
mLocalNotifier = imagePerfNotifier;
}

@Override
public void handleMessage(@NonNull Message msg) {
ImagePerfState state = (ImagePerfState) Preconditions.checkNotNull(msg.obj);
ImagePerfNotifier localNotifier = mLocalNotifier;

switch (msg.what) {
case WHAT_STATUS:
ImageLoadStatus imageLoadStatusFromVal = ImageLoadStatus.Companion.fromInt(msg.arg1);
if (imageLoadStatusFromVal == null) {
throw new IllegalArgumentException("Invalid ImageLoadStatus value: " + msg.arg1);
}
mNotifier.notifyStatusUpdated(state, imageLoadStatusFromVal);
if (localNotifier != null) {
localNotifier.notifyStatusUpdated(state, imageLoadStatusFromVal);
}
break;
case WHAT_VISIBILITY:
VisibilityState visibilityStateFromVal = VisibilityState.Companion.fromInt(msg.arg1);
if (visibilityStateFromVal == null) {
throw new IllegalArgumentException("Invalid VisibilityState value: " + msg.arg1);
}
mNotifier.notifyListenersOfVisibilityStateUpdate(state, visibilityStateFromVal);
if (localNotifier != null) {
localNotifier.notifyListenersOfVisibilityStateUpdate(state, visibilityStateFromVal);
}
break;
}
}
}

public ImagePerfControllerListener2(
MonotonicClock clock,
ImagePerfState imagePerfState,
ImagePerfNotifier globalImagePerfNotifier,
Supplier<Boolean> asyncLogging) {
this(clock, imagePerfState, globalImagePerfNotifier, asyncLogging, true);
ImagePerfNotifier globalImagePerfNotifier) {
this(clock, imagePerfState, globalImagePerfNotifier, true);
}

public ImagePerfControllerListener2(
MonotonicClock clock,
ImagePerfState imagePerfState,
ImagePerfNotifier globalImagePerfNotifier,
Supplier<Boolean> asyncLogging,
boolean reportVisibleOnSubmitAndRelease) {
mClock = clock;
mImagePerfState = imagePerfState;
mImagePerfNotifier = globalImagePerfNotifier;
mAsyncLogging = asyncLogging;
mReportVisibleOnSubmitAndRelease = reportVisibleOnSubmitAndRelease;
}

@Override
public void setImagePerfNotifier(@Nullable ImagePerfNotifier imagePerfNotifier) {
mLocalImagePerfNotifier = imagePerfNotifier;
if (sHandler != null) {
sHandler.setImagePerfNotifier(imagePerfNotifier);
}
}

@Override
Expand Down Expand Up @@ -250,58 +182,23 @@ private void reportViewInvisible(ImagePerfState state, long time) {
private void updateStatus(ImagePerfState state, ImageLoadStatus imageLoadStatus) {
state.setImageLoadStatus(imageLoadStatus);

if (shouldDispatchAsync()) {
Message msg = Preconditions.checkNotNull(sHandler).obtainMessage();
msg.what = WHAT_STATUS;
msg.arg1 = imageLoadStatus.getValue();
msg.obj = state;
sHandler.sendMessage(msg);
} else {
mImagePerfNotifier.notifyStatusUpdated(state, imageLoadStatus);
ImagePerfNotifier localImagePerfNotifier = mLocalImagePerfNotifier;
if (localImagePerfNotifier != null) {
localImagePerfNotifier.notifyStatusUpdated(state, imageLoadStatus);
}
mImagePerfNotifier.notifyStatusUpdated(state, imageLoadStatus);
ImagePerfNotifier localImagePerfNotifier = mLocalImagePerfNotifier;
if (localImagePerfNotifier != null) {
localImagePerfNotifier.notifyStatusUpdated(state, imageLoadStatus);
}
}

private void updateVisibility(ImagePerfState state, VisibilityState visibilityState) {
if (shouldDispatchAsync()) {
Message msg = Preconditions.checkNotNull(sHandler).obtainMessage();
msg.what = WHAT_VISIBILITY;
msg.arg1 = visibilityState.getValue();
msg.obj = state;
sHandler.sendMessage(msg);
} else {
// sync
mImagePerfNotifier.notifyListenersOfVisibilityStateUpdate(state, visibilityState);
ImagePerfNotifier localImagePerfNotifier = mLocalImagePerfNotifier;
if (localImagePerfNotifier != null) {
localImagePerfNotifier.notifyListenersOfVisibilityStateUpdate(state, visibilityState);
}
}
}

private synchronized void initHandler() {
if (sHandler != null) {
return;
}
HandlerThread handlerThread = new HandlerThread("ImagePerfControllerListener2Thread");
handlerThread.start();
Looper looper = Preconditions.checkNotNull(handlerThread.getLooper());
sHandler = new LogHandler(looper, mImagePerfNotifier, mLocalImagePerfNotifier);
}

private boolean shouldDispatchAsync() {
boolean enabled = mAsyncLogging.get();
if (enabled && sHandler == null) {
initHandler();
mImagePerfNotifier.notifyListenersOfVisibilityStateUpdate(state, visibilityState);
ImagePerfNotifier localImagePerfNotifier = mLocalImagePerfNotifier;
if (localImagePerfNotifier != null) {
localImagePerfNotifier.notifyListenersOfVisibilityStateUpdate(state, visibilityState);
}
return enabled;
}

@Override
public void onEmptyEvent(@androidx.annotation.Nullable Object callerContext) {
public void onEmptyEvent(@Nullable Object callerContext) {
ImagePerfState state = mImagePerfState;
state.setImageLoadStatus(ImageLoadStatus.EMPTY_EVENT);
mImagePerfNotifier.notifyStatusUpdated(state, ImageLoadStatus.EMPTY_EVENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import com.facebook.common.internal.Suppliers;
import com.facebook.common.time.MonotonicClock;
import com.facebook.drawee.backends.pipeline.PipelineDraweeController;
import com.facebook.drawee.backends.pipeline.info.internal.ImagePerfControllerListener2;
Expand Down Expand Up @@ -46,7 +45,7 @@ public void setUp() {
mController = mock(PipelineDraweeController.class);
when(mController.getId()).thenReturn(CONTROLLER_ID);

mImagePerfMonitor = new ImagePerfMonitor(mMonotonicClock, mController, Suppliers.BOOLEAN_FALSE);
mImagePerfMonitor = new ImagePerfMonitor(mMonotonicClock, mController);
}

@Test
Expand Down

0 comments on commit efd8d39

Please sign in to comment.