Pipeline systrace - add markers to EncodedMemoryCacheProducer
@@ -15,6 +15,7 @@ import com.facebook.imagepipeline.cache.CacheKeyFactory;
import com.facebook.imagepipeline.cache.MemoryCache;
import com.facebook.imagepipeline.image.EncodedImage;
import com.facebook.imagepipeline.request.ImageRequest;
+import com.facebook.imagepipeline.systrace.FrescoSystrace;
/**
* Memory cache producer for the encoded memory cache.
@@ -39,9 +40,9 @@ public class EncodedMemoryCacheProducer implements Producer<EncodedImage> {
@Override
public void produceResults(
- final Consumer<EncodedImage> consumer,
- final ProducerContext producerContext) {
-
+ final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
+ try {
+ FrescoSystrace.beginSection("EncodedMemoryCacheProducer#produceResults");
final String requestId = producerContext.getId();
final ProducerListener listener = producerContext.getListener();
listener.onProducerStart(requestId, PRODUCER_NAME);
@@ -69,8 +70,8 @@ public class EncodedMemoryCacheProducer implements Producer<EncodedImage> {
}
}
- if (producerContext.getLowestPermittedRequestLevel().getValue() >=
- ImageRequest.RequestLevel.ENCODED_MEMORY_CACHE.getValue()) {
+ if (producerContext.getLowestPermittedRequestLevel().getValue()
+ >= ImageRequest.RequestLevel.ENCODED_MEMORY_CACHE.getValue()) {
listener.onProducerFinishWithSuccess(
requestId,
PRODUCER_NAME,
@@ -82,7 +83,8 @@ public class EncodedMemoryCacheProducer implements Producer<EncodedImage> {
return;
}
- final boolean isMemoryCacheEnabled = producerContext.getImageRequest().isMemoryCacheEnabled();
+ final boolean isMemoryCacheEnabled =
+ producerContext.getImageRequest().isMemoryCacheEnabled();
Consumer consumerOfInputProducer =
new EncodedMemoryCacheConsumer(consumer, mMemoryCache, cacheKey, isMemoryCacheEnabled);
@@ -96,6 +98,9 @@ public class EncodedMemoryCacheProducer implements Producer<EncodedImage> {
} finally {
CloseableReference.closeSafely(cachedReference);
}
+ } finally {
+ FrescoSystrace.endSection();
+ }
}
private static class EncodedMemoryCacheConsumer
@@ -118,9 +123,12 @@ public class EncodedMemoryCacheProducer implements Producer<EncodedImage> {
@Override
public void onNewResultImpl(EncodedImage newResult, @Status int status) {
+ try {
+ FrescoSystrace.beginSection("EncodedMemoryCacheProducer#onNewResultImpl");
// intermediate, null or uncacheable results are not cached, so we just forward them
- if (isNotLast(status) || newResult == null ||
- statusHasAnyFlag(status, DO_NOT_CACHE_ENCODED | IS_PARTIAL_RESULT)) {
+ if (isNotLast(status)
+ || newResult == null
+ || statusHasAnyFlag(status, DO_NOT_CACHE_ENCODED | IS_PARTIAL_RESULT)) {
getConsumer().onNewResult(newResult, status);
return;
}
@@ -154,6 +162,9 @@ public class EncodedMemoryCacheProducer implements Producer<EncodedImage> {
}
}
getConsumer().onNewResult(newResult, status);
+ } finally {
+ FrescoSystrace.endSection();
+ }
}
}
}
