| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.base; | 5 package org.chromium.base; |
| 6 | 6 |
| 7 import android.os.Debug; | 7 import android.os.Debug; |
| 8 import android.os.Debug.MemoryInfo; | 8 import android.os.Debug.MemoryInfo; |
| 9 import android.util.Log; | 9 import android.util.Log; |
| 10 | 10 |
| 11 import org.chromium.base.annotations.SuppressFBWarnings; | |
| 12 | |
| 13 import org.json.JSONArray; | 11 import org.json.JSONArray; |
| 14 import org.json.JSONException; | 12 import org.json.JSONException; |
| 15 import org.json.JSONObject; | 13 import org.json.JSONObject; |
| 16 | 14 |
| 17 import java.io.File; | 15 import java.io.File; |
| 18 import java.io.FileNotFoundException; | 16 import java.io.FileNotFoundException; |
| 19 import java.io.FileOutputStream; | 17 import java.io.FileOutputStream; |
| 20 import java.io.PrintStream; | 18 import java.io.PrintStream; |
| 21 import java.util.LinkedList; | 19 import java.util.LinkedList; |
| 22 import java.util.List; | 20 import java.util.List; |
| 23 | 21 |
| 24 /** | 22 /** |
| 25 * PerfTraceEvent can be used like TraceEvent, but is intended for | 23 * PerfTraceEvent can be used like TraceEvent, but is intended for |
| 26 * performance measurement. By limiting the types of tracing we hope | 24 * performance measurement. By limiting the types of tracing we hope |
| 27 * to minimize impact on measurement. | 25 * to minimize impact on measurement. |
| 28 * | 26 * |
| 29 * All PerfTraceEvent events funnel into TraceEvent. When not doing | 27 * All PerfTraceEvent events funnel into TraceEvent. When not doing |
| 30 * performance measurements, they act the same. However, | 28 * performance measurements, they act the same. However, |
| 31 * PerfTraceEvents can be enabled even when TraceEvent is not. | 29 * PerfTraceEvents can be enabled even when TraceEvent is not. |
| 32 * | 30 * |
| 33 * Unlike TraceEvent, PerfTraceEvent data is sent to the system log, | 31 * Unlike TraceEvent, PerfTraceEvent data is sent to the system log, |
| 34 * not to a trace file. | 32 * not to a trace file. |
| 35 * | 33 * |
| 36 * Performance events need to have very specific names so we find | 34 * Performance events need to have very specific names so we find |
| 37 * the right ones. For example, we specify the name exactly in | 35 * the right ones. For example, we specify the name exactly in |
| 38 * the @TracePerf annotation. Thus, unlike TraceEvent, we do not | 36 * the @TracePerf annotation. Thus, unlike TraceEvent, we do not |
| 39 * support an implicit trace name based on the callstack. | 37 * support an implicit trace name based on the callstack. |
| 40 */ | 38 */ |
| 41 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD") | |
| 42 public class PerfTraceEvent { | 39 public class PerfTraceEvent { |
| 43 private static final int MAX_NAME_LENGTH = 40; | 40 private static final int MAX_NAME_LENGTH = 40; |
| 44 private static final String MEMORY_TRACE_NAME_SUFFIX = "_BZR_PSS"; | 41 private static final String MEMORY_TRACE_NAME_SUFFIX = "_BZR_PSS"; |
| 45 private static File sOutputFile = null; | 42 private static File sOutputFile = null; |
| 46 | 43 |
| 47 /** The event types understood by the perf trace scripts. */ | 44 /** The event types understood by the perf trace scripts. */ |
| 48 private enum EventType { | 45 private enum EventType { |
| 49 START("S"), | 46 START("S"), |
| 50 FINISH("F"), | 47 FINISH("F"), |
| 51 INSTANT("I"); | 48 INSTANT("I"); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } catch (Exception ex) { | 367 } catch (Exception ex) { |
| 371 Log.e("PerfTraceEvent", "Unable to close perf trace outp
ut file."); | 368 Log.e("PerfTraceEvent", "Unable to close perf trace outp
ut file."); |
| 372 } | 369 } |
| 373 } | 370 } |
| 374 } catch (FileNotFoundException ex) { | 371 } catch (FileNotFoundException ex) { |
| 375 Log.e("PerfTraceEvent", "Unable to dump perf trace data to outpu
t file."); | 372 Log.e("PerfTraceEvent", "Unable to dump perf trace data to outpu
t file."); |
| 376 } | 373 } |
| 377 } | 374 } |
| 378 } | 375 } |
| 379 } | 376 } |
| OLD | NEW |