blob: 90a34a5ed88117103b41887f5bffb873815f9313 [file] [log] [blame]
Ady Abrahambb100af2021-03-18 11:48:43 -07001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// TODO(b/183120308): This file is a copy of f/b/libs/hwui/utils/TraceUtils.h
18// It should be migrated to a common place where both SF and hwui could use it.
19
20#pragma once
21
22#include <cutils/trace.h>
23#include <utils/Trace.h>
24
25#define ATRACE_FORMAT(fmt, ...) \
26 TraceUtils::TraceEnder __traceEnder = \
27 (TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__), TraceUtils::TraceEnder())
28
29#define ATRACE_FORMAT_BEGIN(fmt, ...) TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__)
30
31namespace android {
32
33class TraceUtils {
34public:
35 class TraceEnder {
36 public:
37 ~TraceEnder() { ATRACE_END(); }
38 };
39
40 static void atraceFormatBegin(const char* fmt, ...) {
41 if (CC_LIKELY(!ATRACE_ENABLED())) return;
42
43 const int BUFFER_SIZE = 256;
44 va_list ap;
45 char buf[BUFFER_SIZE];
46
47 va_start(ap, fmt);
48 vsnprintf(buf, BUFFER_SIZE, fmt, ap);
49 va_end(ap);
50
51 ATRACE_BEGIN(buf);
52 }
53
54}; // class TraceUtils
55
56} /* namespace android */