/framework/java/jd-gui/android/os/PerformanceCollector.java

https://bitbucket.org/chaos_rom/miui_frameworks · Java · 243 lines · 212 code · 27 blank · 4 comment · 17 complexity · 2b1b93455b8f86381f1484895514da64 MD5 · raw file

  1. package android.os;
  2. import java.util.ArrayList;
  3. import java.util.Iterator;
  4. import java.util.Set;
  5. public class PerformanceCollector
  6. {
  7. public static final String METRIC_KEY_CPU_TIME = "cpu_time";
  8. public static final String METRIC_KEY_EXECUTION_TIME = "execution_time";
  9. public static final String METRIC_KEY_GC_INVOCATION_COUNT = "gc_invocation_count";
  10. public static final String METRIC_KEY_GLOBAL_ALLOC_COUNT = "global_alloc_count";
  11. public static final String METRIC_KEY_GLOBAL_ALLOC_SIZE = "global_alloc_size";
  12. public static final String METRIC_KEY_GLOBAL_FREED_COUNT = "global_freed_count";
  13. public static final String METRIC_KEY_GLOBAL_FREED_SIZE = "global_freed_size";
  14. public static final String METRIC_KEY_ITERATIONS = "iterations";
  15. public static final String METRIC_KEY_JAVA_ALLOCATED = "java_allocated";
  16. public static final String METRIC_KEY_JAVA_FREE = "java_free";
  17. public static final String METRIC_KEY_JAVA_PRIVATE_DIRTY = "java_private_dirty";
  18. public static final String METRIC_KEY_JAVA_PSS = "java_pss";
  19. public static final String METRIC_KEY_JAVA_SHARED_DIRTY = "java_shared_dirty";
  20. public static final String METRIC_KEY_JAVA_SIZE = "java_size";
  21. public static final String METRIC_KEY_LABEL = "label";
  22. public static final String METRIC_KEY_NATIVE_ALLOCATED = "native_allocated";
  23. public static final String METRIC_KEY_NATIVE_FREE = "native_free";
  24. public static final String METRIC_KEY_NATIVE_PRIVATE_DIRTY = "native_private_dirty";
  25. public static final String METRIC_KEY_NATIVE_PSS = "native_pss";
  26. public static final String METRIC_KEY_NATIVE_SHARED_DIRTY = "native_shared_dirty";
  27. public static final String METRIC_KEY_NATIVE_SIZE = "native_size";
  28. public static final String METRIC_KEY_OTHER_PRIVATE_DIRTY = "other_private_dirty";
  29. public static final String METRIC_KEY_OTHER_PSS = "other_pss";
  30. public static final String METRIC_KEY_OTHER_SHARED_DIRTY = "other_shared_dirty";
  31. public static final String METRIC_KEY_PRE_RECEIVED_TRANSACTIONS = "pre_received_transactions";
  32. public static final String METRIC_KEY_PRE_SENT_TRANSACTIONS = "pre_sent_transactions";
  33. public static final String METRIC_KEY_RECEIVED_TRANSACTIONS = "received_transactions";
  34. public static final String METRIC_KEY_SENT_TRANSACTIONS = "sent_transactions";
  35. private long mCpuTime;
  36. private long mExecTime;
  37. private Bundle mPerfMeasurement;
  38. private Bundle mPerfSnapshot;
  39. private PerformanceResultsWriter mPerfWriter;
  40. private long mSnapshotCpuTime;
  41. private long mSnapshotExecTime;
  42. public PerformanceCollector()
  43. {
  44. }
  45. public PerformanceCollector(PerformanceResultsWriter paramPerformanceResultsWriter)
  46. {
  47. setPerformanceResultsWriter(paramPerformanceResultsWriter);
  48. }
  49. private void endPerformanceSnapshot()
  50. {
  51. this.mSnapshotCpuTime = (Process.getElapsedCpuTime() - this.mSnapshotCpuTime);
  52. this.mSnapshotExecTime = (SystemClock.uptimeMillis() - this.mSnapshotExecTime);
  53. stopAllocCounting();
  54. long l1 = Debug.getNativeHeapSize() / 1024L;
  55. long l2 = Debug.getNativeHeapAllocatedSize() / 1024L;
  56. long l3 = Debug.getNativeHeapFreeSize() / 1024L;
  57. Debug.MemoryInfo localMemoryInfo = new Debug.MemoryInfo();
  58. Debug.getMemoryInfo(localMemoryInfo);
  59. Runtime localRuntime = Runtime.getRuntime();
  60. long l4 = localRuntime.totalMemory() / 1024L;
  61. long l5 = localRuntime.freeMemory() / 1024L;
  62. long l6 = l4 - l5;
  63. Bundle localBundle1 = getBinderCounts();
  64. Iterator localIterator1 = localBundle1.keySet().iterator();
  65. while (localIterator1.hasNext())
  66. {
  67. String str2 = (String)localIterator1.next();
  68. this.mPerfSnapshot.putLong(str2, localBundle1.getLong(str2));
  69. }
  70. Bundle localBundle2 = getAllocCounts();
  71. Iterator localIterator2 = localBundle2.keySet().iterator();
  72. while (localIterator2.hasNext())
  73. {
  74. String str1 = (String)localIterator2.next();
  75. this.mPerfSnapshot.putLong(str1, localBundle2.getLong(str1));
  76. }
  77. this.mPerfSnapshot.putLong("execution_time", this.mSnapshotExecTime);
  78. this.mPerfSnapshot.putLong("cpu_time", this.mSnapshotCpuTime);
  79. this.mPerfSnapshot.putLong("native_size", l1);
  80. this.mPerfSnapshot.putLong("native_allocated", l2);
  81. this.mPerfSnapshot.putLong("native_free", l3);
  82. this.mPerfSnapshot.putLong("native_pss", localMemoryInfo.nativePss);
  83. this.mPerfSnapshot.putLong("native_private_dirty", localMemoryInfo.nativePrivateDirty);
  84. this.mPerfSnapshot.putLong("native_shared_dirty", localMemoryInfo.nativeSharedDirty);
  85. this.mPerfSnapshot.putLong("java_size", l4);
  86. this.mPerfSnapshot.putLong("java_allocated", l6);
  87. this.mPerfSnapshot.putLong("java_free", l5);
  88. this.mPerfSnapshot.putLong("java_pss", localMemoryInfo.dalvikPss);
  89. this.mPerfSnapshot.putLong("java_private_dirty", localMemoryInfo.dalvikPrivateDirty);
  90. this.mPerfSnapshot.putLong("java_shared_dirty", localMemoryInfo.dalvikSharedDirty);
  91. this.mPerfSnapshot.putLong("other_pss", localMemoryInfo.otherPss);
  92. this.mPerfSnapshot.putLong("other_private_dirty", localMemoryInfo.otherPrivateDirty);
  93. this.mPerfSnapshot.putLong("other_shared_dirty", localMemoryInfo.otherSharedDirty);
  94. }
  95. private static Bundle getAllocCounts()
  96. {
  97. Bundle localBundle = new Bundle();
  98. localBundle.putLong("global_alloc_count", Debug.getGlobalAllocCount());
  99. localBundle.putLong("global_alloc_size", Debug.getGlobalAllocSize());
  100. localBundle.putLong("global_freed_count", Debug.getGlobalFreedCount());
  101. localBundle.putLong("global_freed_size", Debug.getGlobalFreedSize());
  102. localBundle.putLong("gc_invocation_count", Debug.getGlobalGcInvocationCount());
  103. return localBundle;
  104. }
  105. private static Bundle getBinderCounts()
  106. {
  107. Bundle localBundle = new Bundle();
  108. localBundle.putLong("sent_transactions", Debug.getBinderSentTransactions());
  109. localBundle.putLong("received_transactions", Debug.getBinderReceivedTransactions());
  110. return localBundle;
  111. }
  112. private static void startAllocCounting()
  113. {
  114. Runtime.getRuntime().gc();
  115. Runtime.getRuntime().runFinalization();
  116. Runtime.getRuntime().gc();
  117. Debug.resetAllCounts();
  118. Debug.startAllocCounting();
  119. }
  120. private void startPerformanceSnapshot()
  121. {
  122. this.mPerfSnapshot = new Bundle();
  123. Bundle localBundle = getBinderCounts();
  124. Iterator localIterator = localBundle.keySet().iterator();
  125. while (localIterator.hasNext())
  126. {
  127. String str = (String)localIterator.next();
  128. this.mPerfSnapshot.putLong("pre_" + str, localBundle.getLong(str));
  129. }
  130. startAllocCounting();
  131. this.mSnapshotExecTime = SystemClock.uptimeMillis();
  132. this.mSnapshotCpuTime = Process.getElapsedCpuTime();
  133. }
  134. private static void stopAllocCounting()
  135. {
  136. Runtime.getRuntime().gc();
  137. Runtime.getRuntime().runFinalization();
  138. Runtime.getRuntime().gc();
  139. Debug.stopAllocCounting();
  140. }
  141. public Bundle addIteration(String paramString)
  142. {
  143. this.mCpuTime = (Process.getElapsedCpuTime() - this.mCpuTime);
  144. this.mExecTime = (SystemClock.uptimeMillis() - this.mExecTime);
  145. Bundle localBundle = new Bundle();
  146. localBundle.putString("label", paramString);
  147. localBundle.putLong("execution_time", this.mExecTime);
  148. localBundle.putLong("cpu_time", this.mCpuTime);
  149. this.mPerfMeasurement.getParcelableArrayList("iterations").add(localBundle);
  150. this.mExecTime = SystemClock.uptimeMillis();
  151. this.mCpuTime = Process.getElapsedCpuTime();
  152. return localBundle;
  153. }
  154. public void addMeasurement(String paramString, float paramFloat)
  155. {
  156. if (this.mPerfWriter != null)
  157. this.mPerfWriter.writeMeasurement(paramString, paramFloat);
  158. }
  159. public void addMeasurement(String paramString, long paramLong)
  160. {
  161. if (this.mPerfWriter != null)
  162. this.mPerfWriter.writeMeasurement(paramString, paramLong);
  163. }
  164. public void addMeasurement(String paramString1, String paramString2)
  165. {
  166. if (this.mPerfWriter != null)
  167. this.mPerfWriter.writeMeasurement(paramString1, paramString2);
  168. }
  169. public void beginSnapshot(String paramString)
  170. {
  171. if (this.mPerfWriter != null)
  172. this.mPerfWriter.writeBeginSnapshot(paramString);
  173. startPerformanceSnapshot();
  174. }
  175. public Bundle endSnapshot()
  176. {
  177. endPerformanceSnapshot();
  178. if (this.mPerfWriter != null)
  179. this.mPerfWriter.writeEndSnapshot(this.mPerfSnapshot);
  180. return this.mPerfSnapshot;
  181. }
  182. public void setPerformanceResultsWriter(PerformanceResultsWriter paramPerformanceResultsWriter)
  183. {
  184. this.mPerfWriter = paramPerformanceResultsWriter;
  185. }
  186. public void startTiming(String paramString)
  187. {
  188. if (this.mPerfWriter != null)
  189. this.mPerfWriter.writeStartTiming(paramString);
  190. this.mPerfMeasurement = new Bundle();
  191. this.mPerfMeasurement.putParcelableArrayList("iterations", new ArrayList());
  192. this.mExecTime = SystemClock.uptimeMillis();
  193. this.mCpuTime = Process.getElapsedCpuTime();
  194. }
  195. public Bundle stopTiming(String paramString)
  196. {
  197. addIteration(paramString);
  198. if (this.mPerfWriter != null)
  199. this.mPerfWriter.writeStopTiming(this.mPerfMeasurement);
  200. return this.mPerfMeasurement;
  201. }
  202. public static abstract interface PerformanceResultsWriter
  203. {
  204. public abstract void writeBeginSnapshot(String paramString);
  205. public abstract void writeEndSnapshot(Bundle paramBundle);
  206. public abstract void writeMeasurement(String paramString, float paramFloat);
  207. public abstract void writeMeasurement(String paramString, long paramLong);
  208. public abstract void writeMeasurement(String paramString1, String paramString2);
  209. public abstract void writeStartTiming(String paramString);
  210. public abstract void writeStopTiming(Bundle paramBundle);
  211. }
  212. }
  213. /* Location: /home/lithium/miui/chameleon/2.11.16/framework_dex2jar.jar
  214. * Qualified Name: android.os.PerformanceCollector
  215. * JD-Core Version: 0.6.2
  216. */