From feec80e875d6ae78dc03ee73585d4c5c446327f8 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Thu, 12 Jun 2014 19:12:37 -0700 Subject: [PATCH] Add timing logs for runners. --- .../glide/load/engine/ResourceRunner.java | 7 ++++- .../load/engine/SourceResourceRunner.java | 26 ++++++++++++++++--- .../load/engine/SourceResourceRunnerTest.java | 3 +++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/bumptech/glide/load/engine/ResourceRunner.java b/library/src/main/java/com/bumptech/glide/load/engine/ResourceRunner.java index b86f7023f..08602b431 100644 --- a/library/src/main/java/com/bumptech/glide/load/engine/ResourceRunner.java +++ b/library/src/main/java/com/bumptech/glide/load/engine/ResourceRunner.java @@ -1,6 +1,7 @@ package com.bumptech.glide.load.engine; import android.os.Handler; +import android.os.SystemClock; import android.util.Log; import com.bumptech.glide.Resource; import com.bumptech.glide.load.Key; @@ -72,7 +73,11 @@ public class ResourceRunner implements Runnable { return; } + long start = SystemClock.currentThreadTimeMillis(); Resource fromCache = loadFromDiskCache(); + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "loaded from disk cache in " + (SystemClock.currentThreadTimeMillis() - start)); + } if (fromCache != null) { Resource transcoded = transcoder.transcode(fromCache); job.onResourceReady(transcoded); @@ -94,7 +99,7 @@ public class ResourceRunner implements Runnable { } if (result == null) { if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Failed to decode image from cache"); + Log.d(TAG, "Failed to decode image from cache or not present in cache"); } diskCache.delete(key); } diff --git a/library/src/main/java/com/bumptech/glide/load/engine/SourceResourceRunner.java b/library/src/main/java/com/bumptech/glide/load/engine/SourceResourceRunner.java index c08fd2156..b9ee3c4bd 100644 --- a/library/src/main/java/com/bumptech/glide/load/engine/SourceResourceRunner.java +++ b/library/src/main/java/com/bumptech/glide/load/engine/SourceResourceRunner.java @@ -1,15 +1,17 @@ package com.bumptech.glide.load.engine; +import android.os.SystemClock; +import android.util.Log; import com.bumptech.glide.Priority; import com.bumptech.glide.Resource; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.ResourceDecoder; import com.bumptech.glide.load.ResourceEncoder; import com.bumptech.glide.load.Transformation; -import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; +import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.engine.cache.DiskCache; import com.bumptech.glide.load.engine.executor.Prioritized; -import com.bumptech.glide.load.data.DataFetcher; +import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; import com.bumptech.glide.request.ResourceCallback; import java.io.OutputStream; @@ -21,6 +23,7 @@ import java.io.OutputStream; * @param The type of the resource that will be transcoded to from the decoded resource. */ public class SourceResourceRunner implements Runnable, DiskCache.Writer, Prioritized { + private static final String TAG = "SourceRunner"; private final Key key; private final int width; private final int height; @@ -63,7 +66,12 @@ public class SourceResourceRunner implements Runnable, DiskCache.Writer } try { + long start = SystemClock.currentThreadTimeMillis(); final Resource decoded = decode(); + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "Decoded from source in " + (SystemClock.currentThreadTimeMillis() - start)); + start = SystemClock.currentThreadTimeMillis(); + } if (decoded != null) { Resource transformed = transformation.transform(decoded, width, height); if (decoded != transformed) { @@ -71,10 +79,17 @@ public class SourceResourceRunner implements Runnable, DiskCache.Writer } result = transformed; } + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "transformed in " + (SystemClock.currentThreadTimeMillis() - start)); + } if (result != null) { diskCache.put(key, this); + start = SystemClock.currentThreadTimeMillis(); Resource transcoded = transcoder.transcode(result); + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.d(TAG, "transcoded in " + (SystemClock.currentThreadTimeMillis() - start)); + } cb.onResourceReady(transcoded); } else { cb.onException(null); @@ -100,7 +115,12 @@ public class SourceResourceRunner implements Runnable, DiskCache.Writer @Override public boolean write(OutputStream os) { - return encoder.encode(result, os); + long start = SystemClock.currentThreadTimeMillis(); + boolean success = encoder.encode(result, os); + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "wrote to disk cache in " + (SystemClock.currentThreadTimeMillis() - start)); + } + return success; } @Override diff --git a/library/src/test/java/com/bumptech/glide/load/engine/SourceResourceRunnerTest.java b/library/src/test/java/com/bumptech/glide/load/engine/SourceResourceRunnerTest.java index 4d2ac4381..8f56bbef8 100644 --- a/library/src/test/java/com/bumptech/glide/load/engine/SourceResourceRunnerTest.java +++ b/library/src/test/java/com/bumptech/glide/load/engine/SourceResourceRunnerTest.java @@ -12,6 +12,8 @@ import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; import com.bumptech.glide.request.ResourceCallback; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -32,6 +34,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@RunWith(RobolectricTestRunner.class) public class SourceResourceRunnerTest { private SourceResourceHarness harness; -- GitLab