提交 feec80e8 编写于 作者: S Sam Judd

Add timing logs for runners.

上级 8e936252
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<Z, R> implements Runnable {
return;
}
long start = SystemClock.currentThreadTimeMillis();
Resource<Z> fromCache = loadFromDiskCache();
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "loaded from disk cache in " + (SystemClock.currentThreadTimeMillis() - start));
}
if (fromCache != null) {
Resource<R> transcoded = transcoder.transcode(fromCache);
job.onResourceReady(transcoded);
......@@ -94,7 +99,7 @@ public class ResourceRunner<Z, R> 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);
}
......
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 <R> The type of the resource that will be transcoded to from the decoded resource.
*/
public class SourceResourceRunner<T, Z, R> 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<T, Z, R> implements Runnable, DiskCache.Writer
}
try {
long start = SystemClock.currentThreadTimeMillis();
final Resource<Z> 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<Z> transformed = transformation.transform(decoded, width, height);
if (decoded != transformed) {
......@@ -71,10 +79,17 @@ public class SourceResourceRunner<T, Z, R> 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<R> 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<T, Z, R> 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
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册