提交 7fecca97 编写于 作者: E ear 提交者: Sam Judd

Include key in DecodeJob systrace tag.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187541996
上级 7ff3bdee
......@@ -2,7 +2,6 @@ package com.bumptech.glide.load.engine;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.os.TraceCompat;
import android.support.v4.util.Pools;
import android.util.Log;
import com.bumptech.glide.GlideContext;
......@@ -21,6 +20,7 @@ import com.bumptech.glide.load.resource.bitmap.Downsampler;
import com.bumptech.glide.util.LogTime;
import com.bumptech.glide.util.Synthetic;
import com.bumptech.glide.util.pool.FactoryPools.Poolable;
import com.bumptech.glide.util.pool.GlideTrace;
import com.bumptech.glide.util.pool.StateVerifier;
import java.util.ArrayList;
import java.util.List;
......@@ -63,6 +63,7 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
private RunReason runReason;
private long startFetchTime;
private boolean onlyRetrieveFromCache;
private Object model;
private Thread currentThread;
private Key currentSourceKey;
......@@ -125,6 +126,7 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
this.callback = callback;
this.order = order;
this.runReason = RunReason.INITIALIZE;
this.model = model;
return this;
}
......@@ -188,6 +190,7 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
currentFetcher = null;
startFetchTime = 0L;
isCancelled = false;
model = null;
throwables.clear();
pool.release(this);
}
......@@ -218,7 +221,7 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
// This should be much more fine grained, but since Java's thread pool implementation silently
// swallows all otherwise fatal exceptions, this will at least make it obvious to developers
// that something is failing.
TraceCompat.beginSection("DecodeJob#run");
GlideTrace.beginSectionFormat("DecodeJob#run(model=%s)", model);
// Methods in the try statement can invalidate currentFetcher, so set a local variable here to
// ensure that the fetcher is cleaned up either way.
DataFetcher<?> localFetcher = currentFetcher;
......@@ -254,7 +257,7 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
if (localFetcher != null) {
localFetcher.cleanup();
}
TraceCompat.endSection();
GlideTrace.endSection();
}
}
......@@ -371,11 +374,11 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
runReason = RunReason.DECODE_DATA;
callback.reschedule(this);
} else {
TraceCompat.beginSection("DecodeJob.decodeFromRetrievedData");
GlideTrace.beginSection("DecodeJob.decodeFromRetrievedData");
try {
decodeFromRetrievedData();
} finally {
TraceCompat.endSection();
GlideTrace.endSection();
}
}
}
......@@ -654,13 +657,13 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
}
void encode(DiskCacheProvider diskCacheProvider, Options options) {
TraceCompat.beginSection("DecodeJob.encode");
GlideTrace.beginSection("DecodeJob.encode");
try {
diskCacheProvider.getDiskCache().put(key,
new DataCacheWriter<>(encoder, toEncode, options));
} finally {
toEncode.unlock();
TraceCompat.endSection();
GlideTrace.endSection();
}
}
......
......@@ -3,7 +3,6 @@ package com.bumptech.glide.load.resource.bitmap;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.os.TraceCompat;
import android.util.Log;
import com.bumptech.glide.load.EncodeStrategy;
import com.bumptech.glide.load.Option;
......@@ -14,6 +13,7 @@ import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
import com.bumptech.glide.util.LogTime;
import com.bumptech.glide.util.Util;
import com.bumptech.glide.util.pool.GlideTrace;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
......@@ -72,8 +72,8 @@ public class BitmapEncoder implements ResourceEncoder<Bitmap> {
@NonNull Options options) {
final Bitmap bitmap = resource.get();
Bitmap.CompressFormat format = getFormat(bitmap, options);
TraceCompat.beginSection(
"encode: [" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + format);
GlideTrace.
beginSectionFormat("encode: [%dx%d] %s", bitmap.getWidth(), bitmap.getHeight(), format);
try {
long start = LogTime.getLogTime();
int quality = options.get(COMPRESSION_QUALITY);
......@@ -110,7 +110,7 @@ public class BitmapEncoder implements ResourceEncoder<Bitmap> {
}
return success;
} finally {
TraceCompat.endSection();
GlideTrace.endSection();
}
}
......
package com.bumptech.glide.util.pool;
import android.support.v4.os.TraceCompat;
/**
* Systracing utilities for Glide.
*/
public final class GlideTrace {
// Enable this locally to see tracing statements.
private static final boolean TRACING_ENABLED = false;
/** Maximum length of a systrace tag. */
private static final int MAX_LENGTH = 127;
private static String truncateTag(String tag) {
if (tag.length() > MAX_LENGTH) {
return tag.substring(0, MAX_LENGTH - 1);
}
return tag;
}
public static void beginSection(String tag) {
if (TRACING_ENABLED) {
TraceCompat.beginSection(truncateTag(tag));
}
}
public static void beginSectionFormat(String format, Object arg1) {
if (TRACING_ENABLED) {
TraceCompat.beginSection(truncateTag(String.format(format, arg1)));
}
}
public static void beginSectionFormat(String format, Object arg1, Object arg2) {
if (TRACING_ENABLED) {
TraceCompat.beginSection(truncateTag(String.format(format, arg1, arg2)));
}
}
public static void beginSectionFormat(String format, Object arg1, Object arg2, Object arg3) {
if (TRACING_ENABLED) {
TraceCompat.beginSection(truncateTag(String.format(format, arg1, arg2, arg3)));
}
}
public static void endSection() {
if (TRACING_ENABLED) {
TraceCompat.endSection();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册