OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.Process; | 7 import android.os.Process; |
8 import android.os.StrictMode; | 8 import android.os.StrictMode; |
9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
10 | 10 |
11 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
| 12 import org.chromium.base.annotations.MainDex; |
12 import org.chromium.base.annotations.SuppressFBWarnings; | 13 import org.chromium.base.annotations.SuppressFBWarnings; |
13 | 14 |
14 import java.io.File; | 15 import java.io.File; |
15 import java.util.ArrayList; | 16 import java.util.ArrayList; |
16 import java.util.HashMap; | 17 import java.util.HashMap; |
17 import java.util.List; | 18 import java.util.List; |
18 import java.util.Map; | 19 import java.util.Map; |
19 | 20 |
20 /** Support for early tracing, before the native library is loaded. | 21 /** Support for early tracing, before the native library is loaded. |
21 * | 22 * |
22 * This is limited, as: | 23 * This is limited, as: |
23 * - Arguments are not supported | 24 * - Arguments are not supported |
24 * - Thread time is not reported | 25 * - Thread time is not reported |
25 * - Two events with the same name cannot be in progress at the same time. | 26 * - Two events with the same name cannot be in progress at the same time. |
26 * | 27 * |
27 * Events recorded here are buffered in Java until the native library is availab
le. Then it waits | 28 * Events recorded here are buffered in Java until the native library is availab
le. Then it waits |
28 * for the completion of pending events, and sends the events to the native side
. | 29 * for the completion of pending events, and sends the events to the native side
. |
29 * | 30 * |
30 * Locking: This class is threadsafe. It is enabled when general tracing is, and
then disabled when | 31 * Locking: This class is threadsafe. It is enabled when general tracing is, and
then disabled when |
31 * tracing is enabled from the native side. Event completions are still
processed as long | 32 * tracing is enabled from the native side. Event completions are still
processed as long |
32 * as some are pending, then early tracing is permanently disabled afte
r dumping the | 33 * as some are pending, then early tracing is permanently disabled afte
r dumping the |
33 * events. This means that if any early event is still pending when tr
acing is disabled, | 34 * events. This means that if any early event is still pending when tr
acing is disabled, |
34 * all early events are dropped. | 35 * all early events are dropped. |
35 */ | 36 */ |
36 @JNINamespace("base::android") | 37 @JNINamespace("base::android") |
| 38 @MainDex |
37 public class EarlyTraceEvent { | 39 public class EarlyTraceEvent { |
38 // Must be kept in sync with the native kAndroidTraceConfigFile. | 40 // Must be kept in sync with the native kAndroidTraceConfigFile. |
39 private static final String TRACE_CONFIG_FILENAME = "/data/local/chrome-trac
e-config.json"; | 41 private static final String TRACE_CONFIG_FILENAME = "/data/local/chrome-trac
e-config.json"; |
40 | 42 |
41 /** Single trace event. */ | 43 /** Single trace event. */ |
42 @VisibleForTesting | 44 @VisibleForTesting |
43 static final class Event { | 45 static final class Event { |
44 final String mName; | 46 final String mName; |
45 final int mThreadId; | 47 final int mThreadId; |
46 final long mBeginTimeMs; | 48 final long mBeginTimeMs; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 long offsetMs = (nativeNowUs - javaNowUs) / 1000; | 171 long offsetMs = (nativeNowUs - javaNowUs) / 1000; |
170 for (Event event : events) { | 172 for (Event event : events) { |
171 nativeRecordEarlyEvent(event.mName, event.mBeginTimeMs + offsetMs, | 173 nativeRecordEarlyEvent(event.mName, event.mBeginTimeMs + offsetMs, |
172 event.mEndTimeMs + offsetMs, event.mThreadId); | 174 event.mEndTimeMs + offsetMs, event.mThreadId); |
173 } | 175 } |
174 } | 176 } |
175 | 177 |
176 private static native void nativeRecordEarlyEvent( | 178 private static native void nativeRecordEarlyEvent( |
177 String name, long beginTimeMs, long endTimeMs, int threadId); | 179 String name, long beginTimeMs, long endTimeMs, int threadId); |
178 } | 180 } |
OLD | NEW |