blob: e61b4be1784e496fa0b1d995227e368d531ee13f [file] [log] [blame]
Chris Craik70850ea2014-11-18 10:49:23 -08001/*
2 * Copyright (C) 2014 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#ifndef TRACE_UTILS_H
17#define TRACE_UTILS_H
18
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010019#include <cutils/trace.h>
Chris Craik70850ea2014-11-18 10:49:23 -080020#include <utils/Trace.h>
21
John Reck1bcacfd2017-11-03 10:12:19 -070022#define ATRACE_FORMAT(fmt, ...) \
23 TraceUtils::TraceEnder __traceEnder = \
24 (TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__), TraceUtils::TraceEnder())
Chris Craik70850ea2014-11-18 10:49:23 -080025
John Reck1bcacfd2017-11-03 10:12:19 -070026#define ATRACE_FORMAT_BEGIN(fmt, ...) TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__)
Chris Craik70850ea2014-11-18 10:49:23 -080027
28namespace android {
29namespace uirenderer {
30
31class TraceUtils {
32public:
33 class TraceEnder {
34 public:
35 ~TraceEnder() { ATRACE_END(); }
36 };
37
38 static void atraceFormatBegin(const char* fmt, ...) {
Chris Craik1a0808e2015-05-13 16:33:04 -070039 if (CC_LIKELY(!ATRACE_ENABLED())) return;
Chris Craik70850ea2014-11-18 10:49:23 -080040
41 const int BUFFER_SIZE = 256;
42 va_list ap;
43 char buf[BUFFER_SIZE];
44
45 va_start(ap, fmt);
46 vsnprintf(buf, BUFFER_SIZE, fmt, ap);
47 va_end(ap);
48
49 ATRACE_BEGIN(buf);
50 }
51
John Reck1bcacfd2017-11-03 10:12:19 -070052}; // class TraceUtils
Chris Craik70850ea2014-11-18 10:49:23 -080053
54} /* namespace uirenderer */
55} /* namespace android */
56
57#endif /* TRACE_UTILS_H */