Skip to content

Commit 7fecca9

Browse files
kanelbullesjudd
authored andcommitted
Include key in DecodeJob systrace tag.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187541996
1 parent 7ff3bde commit 7fecca9

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.os.Build;
44
import android.support.annotation.NonNull;
5-
import android.support.v4.os.TraceCompat;
65
import android.support.v4.util.Pools;
76
import android.util.Log;
87
import com.bumptech.glide.GlideContext;
@@ -21,6 +20,7 @@
2120
import com.bumptech.glide.util.LogTime;
2221
import com.bumptech.glide.util.Synthetic;
2322
import com.bumptech.glide.util.pool.FactoryPools.Poolable;
23+
import com.bumptech.glide.util.pool.GlideTrace;
2424
import com.bumptech.glide.util.pool.StateVerifier;
2525
import java.util.ArrayList;
2626
import java.util.List;
@@ -63,6 +63,7 @@ class DecodeJob<R> implements DataFetcherGenerator.FetcherReadyCallback,
6363
private RunReason runReason;
6464
private long startFetchTime;
6565
private boolean onlyRetrieveFromCache;
66+
private Object model;
6667

6768
private Thread currentThread;
6869
private Key currentSourceKey;
@@ -125,6 +126,7 @@ DecodeJob<R> init(
125126
this.callback = callback;
126127
this.order = order;
127128
this.runReason = RunReason.INITIALIZE;
129+
this.model = model;
128130
return this;
129131
}
130132

@@ -188,6 +190,7 @@ private void releaseInternal() {
188190
currentFetcher = null;
189191
startFetchTime = 0L;
190192
isCancelled = false;
193+
model = null;
191194
throwables.clear();
192195
pool.release(this);
193196
}
@@ -218,7 +221,7 @@ public void run() {
218221
// This should be much more fine grained, but since Java's thread pool implementation silently
219222
// swallows all otherwise fatal exceptions, this will at least make it obvious to developers
220223
// that something is failing.
221-
TraceCompat.beginSection("DecodeJob#run");
224+
GlideTrace.beginSectionFormat("DecodeJob#run(model=%s)", model);
222225
// Methods in the try statement can invalidate currentFetcher, so set a local variable here to
223226
// ensure that the fetcher is cleaned up either way.
224227
DataFetcher<?> localFetcher = currentFetcher;
@@ -254,7 +257,7 @@ public void run() {
254257
if (localFetcher != null) {
255258
localFetcher.cleanup();
256259
}
257-
TraceCompat.endSection();
260+
GlideTrace.endSection();
258261
}
259262
}
260263

@@ -371,11 +374,11 @@ public void onDataFetcherReady(Key sourceKey, Object data, DataFetcher<?> fetche
371374
runReason = RunReason.DECODE_DATA;
372375
callback.reschedule(this);
373376
} else {
374-
TraceCompat.beginSection("DecodeJob.decodeFromRetrievedData");
377+
GlideTrace.beginSection("DecodeJob.decodeFromRetrievedData");
375378
try {
376379
decodeFromRetrievedData();
377380
} finally {
378-
TraceCompat.endSection();
381+
GlideTrace.endSection();
379382
}
380383
}
381384
}
@@ -654,13 +657,13 @@ <X> void init(Key key, ResourceEncoder<X> encoder, LockedResource<X> toEncode) {
654657
}
655658

656659
void encode(DiskCacheProvider diskCacheProvider, Options options) {
657-
TraceCompat.beginSection("DecodeJob.encode");
660+
GlideTrace.beginSection("DecodeJob.encode");
658661
try {
659662
diskCacheProvider.getDiskCache().put(key,
660663
new DataCacheWriter<>(encoder, toEncode, options));
661664
} finally {
662665
toEncode.unlock();
663-
TraceCompat.endSection();
666+
GlideTrace.endSection();
664667
}
665668
}
666669

library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapEncoder.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.graphics.Bitmap;
44
import android.support.annotation.NonNull;
55
import android.support.annotation.Nullable;
6-
import android.support.v4.os.TraceCompat;
76
import android.util.Log;
87
import com.bumptech.glide.load.EncodeStrategy;
98
import com.bumptech.glide.load.Option;
@@ -14,6 +13,7 @@
1413
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
1514
import com.bumptech.glide.util.LogTime;
1615
import com.bumptech.glide.util.Util;
16+
import com.bumptech.glide.util.pool.GlideTrace;
1717
import java.io.File;
1818
import java.io.FileOutputStream;
1919
import java.io.IOException;
@@ -72,8 +72,8 @@ public boolean encode(@NonNull Resource<Bitmap> resource, @NonNull File file,
7272
@NonNull Options options) {
7373
final Bitmap bitmap = resource.get();
7474
Bitmap.CompressFormat format = getFormat(bitmap, options);
75-
TraceCompat.beginSection(
76-
"encode: [" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + format);
75+
GlideTrace.
76+
beginSectionFormat("encode: [%dx%d] %s", bitmap.getWidth(), bitmap.getHeight(), format);
7777
try {
7878
long start = LogTime.getLogTime();
7979
int quality = options.get(COMPRESSION_QUALITY);
@@ -110,7 +110,7 @@ public boolean encode(@NonNull Resource<Bitmap> resource, @NonNull File file,
110110
}
111111
return success;
112112
} finally {
113-
TraceCompat.endSection();
113+
GlideTrace.endSection();
114114
}
115115
}
116116

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.bumptech.glide.util.pool;
2+
3+
import android.support.v4.os.TraceCompat;
4+
5+
/**
6+
* Systracing utilities for Glide.
7+
*/
8+
public final class GlideTrace {
9+
10+
// Enable this locally to see tracing statements.
11+
private static final boolean TRACING_ENABLED = false;
12+
13+
/** Maximum length of a systrace tag. */
14+
private static final int MAX_LENGTH = 127;
15+
16+
private static String truncateTag(String tag) {
17+
if (tag.length() > MAX_LENGTH) {
18+
return tag.substring(0, MAX_LENGTH - 1);
19+
}
20+
return tag;
21+
}
22+
23+
public static void beginSection(String tag) {
24+
if (TRACING_ENABLED) {
25+
TraceCompat.beginSection(truncateTag(tag));
26+
}
27+
}
28+
29+
public static void beginSectionFormat(String format, Object arg1) {
30+
if (TRACING_ENABLED) {
31+
TraceCompat.beginSection(truncateTag(String.format(format, arg1)));
32+
}
33+
}
34+
35+
public static void beginSectionFormat(String format, Object arg1, Object arg2) {
36+
if (TRACING_ENABLED) {
37+
TraceCompat.beginSection(truncateTag(String.format(format, arg1, arg2)));
38+
}
39+
}
40+
41+
public static void beginSectionFormat(String format, Object arg1, Object arg2, Object arg3) {
42+
if (TRACING_ENABLED) {
43+
TraceCompat.beginSection(truncateTag(String.format(format, arg1, arg2, arg3)));
44+
}
45+
}
46+
47+
public static void endSection() {
48+
if (TRACING_ENABLED) {
49+
TraceCompat.endSection();
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)