| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import android.util.Log; |
| 20 |
import android.util.Size; |
| 21 |
import com.android.internal.util.FastPrintWriter; |
| 22 |
|
| 23 |
import java.io.FileOutputStream; |
| 24 |
import java.io.PrintWriter; |
| 25 |
import java.util.HashMap; |
| 26 |
import java.util.Map; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class TransactionTracker { |
| 34 |
private Map<String, Long> mTraces; |
| 35 |
|
| 36 |
private void resetTraces() { |
| 37 |
synchronized (this) { |
| 38 |
mTraces = new HashMap<String, Long>(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
TransactionTracker() { |
| 43 |
resetTraces(); |
| 44 |
} |
| 45 |
|
| 46 |
public void addTrace(Throwable tr) { |
| 47 |
String trace = Log.getStackTraceString(tr); |
| 48 |
synchronized (this) { |
| 49 |
if (mTraces.containsKey(trace)) { |
| 50 |
mTraces.put(trace, mTraces.get(trace) + 1); |
| 51 |
} else { |
| 52 |
mTraces.put(trace, Long.valueOf(1)); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
public void writeTracesToFile(ParcelFileDescriptor fd) { |
| 58 |
if (mTraces.isEmpty()) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd.getFileDescriptor())); |
| 63 |
synchronized (this) { |
| 64 |
for (String trace : mTraces.keySet()) { |
| 65 |
pw.println("Count: " + mTraces.get(trace)); |
| 66 |
pw.println("Trace: " + trace); |
| 67 |
pw.println(); |
| 68 |
} |
| 69 |
} |
| 70 |
pw.flush(); |
| 71 |
} |
| 72 |
|
| 73 |
public void clearTraces(){ |
| 74 |
resetTraces(); |
| 75 |
} |
| 76 |
} |