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 |
| 15 import org.chromium.base.annotations.SuppressFBWarnings; |
| 16 |
17 import java.io.File; | 17 import java.io.File; |
18 import java.io.FileNotFoundException; | 18 import java.io.FileNotFoundException; |
19 import java.io.FileOutputStream; | 19 import java.io.FileOutputStream; |
20 import java.io.PrintStream; | 20 import java.io.PrintStream; |
21 import java.util.LinkedList; | 21 import java.util.LinkedList; |
22 import java.util.List; | 22 import java.util.List; |
23 | 23 |
24 /** | 24 /** |
25 * PerfTraceEvent can be used like TraceEvent, but is intended for | 25 * PerfTraceEvent can be used like TraceEvent, but is intended for |
26 * performance measurement. By limiting the types of tracing we hope | 26 * performance measurement. By limiting the types of tracing we hope |
27 * to minimize impact on measurement. | 27 * to minimize impact on measurement. |
28 * | 28 * |
29 * All PerfTraceEvent events funnel into TraceEvent. When not doing | 29 * All PerfTraceEvent events funnel into TraceEvent. When not doing |
30 * performance measurements, they act the same. However, | 30 * performance measurements, they act the same. However, |
31 * PerfTraceEvents can be enabled even when TraceEvent is not. | 31 * PerfTraceEvents can be enabled even when TraceEvent is not. |
32 * | 32 * |
33 * Unlike TraceEvent, PerfTraceEvent data is sent to the system log, | 33 * Unlike TraceEvent, PerfTraceEvent data is sent to the system log, |
34 * not to a trace file. | 34 * not to a trace file. |
35 * | 35 * |
36 * Performance events need to have very specific names so we find | 36 * Performance events need to have very specific names so we find |
37 * the right ones. For example, we specify the name exactly in | 37 * the right ones. For example, we specify the name exactly in |
38 * the @TracePerf annotation. Thus, unlike TraceEvent, we do not | 38 * the @TracePerf annotation. Thus, unlike TraceEvent, we do not |
39 * support an implicit trace name based on the callstack. | 39 * support an implicit trace name based on the callstack. |
40 */ | 40 */ |
41 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD") | 41 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD") |
42 public class PerfTraceEvent { | 42 public class PerfTraceEvent { |
43 private static final int MAX_NAME_LENGTH = 40; | 43 private static final int MAX_NAME_LENGTH = 40; |
44 private static final String MEMORY_TRACE_NAME_SUFFIX = "_BZR_PSS"; | 44 private static final String MEMORY_TRACE_NAME_SUFFIX = "_BZR_PSS"; |
45 private static File sOutputFile = null; | 45 private static File sOutputFile; |
46 | 46 |
47 /** The event types understood by the perf trace scripts. */ | 47 /** The event types understood by the perf trace scripts. */ |
48 private enum EventType { | 48 private enum EventType { |
49 START("S"), | 49 START("S"), |
50 FINISH("F"), | 50 FINISH("F"), |
51 INSTANT("I"); | 51 INSTANT("I"); |
52 | 52 |
53 // The string understood by the trace scripts. | 53 // The string understood by the trace scripts. |
54 private final String mTypeStr; | 54 private final String mTypeStr; |
55 | 55 |
56 EventType(String typeStr) { | 56 EventType(String typeStr) { |
57 mTypeStr = typeStr; | 57 mTypeStr = typeStr; |
58 } | 58 } |
59 | 59 |
60 @Override | 60 @Override |
61 public String toString() { | 61 public String toString() { |
62 return mTypeStr; | 62 return mTypeStr; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 private static boolean sEnabled = false; | 66 private static boolean sEnabled; |
67 private static boolean sTrackTiming = true; | 67 private static boolean sTrackTiming = true; |
68 private static boolean sTrackMemory = false; | 68 private static boolean sTrackMemory; |
69 | 69 |
70 // A list of performance trace event strings. | 70 // A list of performance trace event strings. |
71 // Events are stored as a JSON dict much like TraceEvent. | 71 // Events are stored as a JSON dict much like TraceEvent. |
72 // E.g. timestamp is in microseconds. | 72 // E.g. timestamp is in microseconds. |
73 private static JSONArray sPerfTraceStrings; | 73 private static JSONArray sPerfTraceStrings; |
74 | 74 |
75 // A filter for performance tracing. Only events that match a | 75 // A filter for performance tracing. Only events that match a |
76 // string in the list are saved. Presence of a filter does not | 76 // string in the list are saved. Presence of a filter does not |
77 // necessarily mean perf tracing is enabled. | 77 // necessarily mean perf tracing is enabled. |
78 private static List<String> sFilter; | 78 private static List<String> sFilter; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } catch (Exception ex) { | 370 } catch (Exception ex) { |
371 Log.e("PerfTraceEvent", "Unable to close perf trace outp
ut file."); | 371 Log.e("PerfTraceEvent", "Unable to close perf trace outp
ut file."); |
372 } | 372 } |
373 } | 373 } |
374 } catch (FileNotFoundException ex) { | 374 } catch (FileNotFoundException ex) { |
375 Log.e("PerfTraceEvent", "Unable to dump perf trace data to outpu
t file."); | 375 Log.e("PerfTraceEvent", "Unable to dump perf trace data to outpu
t file."); |
376 } | 376 } |
377 } | 377 } |
378 } | 378 } |
379 } | 379 } |
OLD | NEW |