1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * http://www.apache.org/licenses/LICENSE-2.0 7 * Unless required by applicable law or agreed to in writing, software 8 * distributed under the License is distributed on an "AS IS" BASIS, 9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 * See the License for the specific language governing permissions and 11 * limitations under the License. 12 */ 13 14 package android.support.v4.os; 15 16 import android.os.Build; 17 import android.os.Trace; 18 19 /** 20 * Writes trace events to the system trace buffer. These trace events can be 21 * collected and visualized using the Systrace tool. 22 * 23 * <p>This tracing mechanism is independent of the method tracing mechanism 24 * offered by {@link android.os.Debug#startMethodTracing}. In particular, it enables 25 * tracing of events that occur across multiple processes. 26 * <p>For information about using the Systrace tool, read <a 27 * href="{@docRoot}tools/debugging/systrace.html">Analyzing Display and Performance 28 * with Systrace</a>. 29 */ 30 public final class TraceCompat { 31 /** 32 * Writes a trace message to indicate that a given section of code has begun. This call must 33 * be followed by a corresponding call to {@link #endSection()} on the same thread. 34 * 35 * <p class="note"> At this time the vertical bar character '|', newline character '\n', and 36 * null character '\0' are used internally by the tracing mechanism. If sectionName contains 37 * these characters they will be replaced with a space character in the trace. 38 * 39 * @param sectionName The name of the code section to appear in the trace. This may be at 40 * most 127 Unicode code units long. 41 */ 42 43 public static void beginSection(String sectionName) { 44 if (Build.VERSION.SDK_INT >= 18) { 45 Trace.beginSection(sectionName); 46 } 47 } 48 49 /** 50 * Writes a trace message to indicate that a given section of code has ended. This call must 51 * be preceeded by a corresponding call to {@link #beginSection(String)}. Calling this method 52 * will mark the end of the most recently begun section of code, so care must be taken to 53 * ensure that beginSection / endSection pairs are properly nested and called from the same 54 * thread. 55 */ 56 public static void endSection() { 57 if (Build.VERSION.SDK_INT >= 18) { 58 Trace.endSection(); 59 } 60 } 61 62 private TraceCompat() {} 63 } 64