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
14package android.support.v4.os;
15
16import android.os.Build;
17
18/**
19 * Writes trace events to the system trace buffer.  These trace events can be
20 * collected and visualized using the Systrace tool.
21 *
22 * <p>This tracing mechanism is independent of the method tracing mechanism
23 * offered by {@link android.os.Debug#startMethodTracing}.  In particular, it enables
24 * tracing of events that occur across multiple processes.
25 * <p>For information about using the Systrace tool, read <a
26 * href="{@docRoot}tools/debugging/systrace.html">Analyzing Display and Performance
27 * with Systrace</a>.
28 */
29public final class TraceCompat {
30    /**
31     * Writes a trace message to indicate that a given section of code has begun. This call must
32     * be followed by a corresponding call to {@link #endSection()} on the same thread.
33     *
34     * <p class="note"> At this time the vertical bar character '|', newline character '\n', and
35     * null character '\0' are used internally by the tracing mechanism.  If sectionName contains
36     * these characters they will be replaced with a space character in the trace.
37     *
38     * @param sectionName The name of the code section to appear in the trace.  This may be at
39     * most 127 Unicode code units long.
40     */
41
42    public static void beginSection(String sectionName) {
43        if (Build.VERSION.SDK_INT >= 18) {
44            TraceJellybeanMR2.beginSection(sectionName);
45        }
46    }
47
48    /**
49     * Writes a trace message to indicate that a given section of code has ended. This call must
50     * be preceeded by a corresponding call to {@link #beginSection(String)}. Calling this method
51     * will mark the end of the most recently begun section of code, so care must be taken to
52     * ensure that beginSection / endSection pairs are properly nested and called from the same
53     * thread.
54     */
55    public static void endSection() {
56        if (Build.VERSION.SDK_INT >= 18) {
57            TraceJellybeanMR2.endSection();
58        }
59    }
60
61    private TraceCompat() {}
62}
63