Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | #include <utils/Trace.h> |
| 20 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 21 | #define ATRACE_FORMAT(fmt, ...) \ |
| 22 | TraceUtils::TraceEnder __traceEnder = \ |
| 23 | (TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__), TraceUtils::TraceEnder()) |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 24 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 25 | #define ATRACE_FORMAT_BEGIN(fmt, ...) TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__) |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
| 30 | class TraceUtils { |
| 31 | public: |
| 32 | class TraceEnder { |
| 33 | public: |
| 34 | ~TraceEnder() { ATRACE_END(); } |
| 35 | }; |
| 36 | |
| 37 | static void atraceFormatBegin(const char* fmt, ...) { |
Chris Craik | 1a0808e | 2015-05-13 16:33:04 -0700 | [diff] [blame] | 38 | if (CC_LIKELY(!ATRACE_ENABLED())) return; |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 39 | |
| 40 | const int BUFFER_SIZE = 256; |
| 41 | va_list ap; |
| 42 | char buf[BUFFER_SIZE]; |
| 43 | |
| 44 | va_start(ap, fmt); |
| 45 | vsnprintf(buf, BUFFER_SIZE, fmt, ap); |
| 46 | va_end(ap); |
| 47 | |
| 48 | ATRACE_BEGIN(buf); |
| 49 | } |
| 50 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 51 | }; // class TraceUtils |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 52 | |
| 53 | } /* namespace uirenderer */ |
| 54 | } /* namespace android */ |
| 55 | |
| 56 | #endif /* TRACE_UTILS_H */ |