Roman Stratiienko | 6a7ac12 | 2021-04-02 17:19:54 +0300 | [diff] [blame] | 1 | // clang-format off |
| 2 | /* |
| 3 | * Copyright (C) 2012 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_TRACE_H |
| 19 | #define ANDROID_TRACE_H |
| 20 | |
| 21 | #if defined(_WIN32) |
| 22 | |
| 23 | #define ATRACE_NAME(...) |
| 24 | #define ATRACE_CALL() |
| 25 | |
| 26 | #else // !_WIN32 |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | |
| 30 | #include <cutils/trace.h> |
| 31 | |
| 32 | // See <cutils/trace.h> for more ATRACE_* macros. |
| 33 | |
| 34 | // ATRACE_NAME traces from its location until the end of its enclosing scope. |
| 35 | #define _PASTE(x, y) x ## y |
| 36 | #define PASTE(x, y) _PASTE(x,y) |
| 37 | #define ATRACE_NAME(name) ::android::ScopedTrace PASTE(___tracer, __LINE__)(ATRACE_TAG, name) |
| 38 | |
| 39 | // ATRACE_CALL is an ATRACE_NAME that uses the current function name. |
| 40 | #define ATRACE_CALL() ATRACE_NAME(__FUNCTION__) |
| 41 | |
| 42 | namespace android { |
| 43 | |
| 44 | class ScopedTrace { |
| 45 | public: |
| 46 | inline ScopedTrace(uint64_t tag, const char* name) : mTag(tag) { |
| 47 | atrace_begin(mTag, name); |
| 48 | } |
| 49 | |
| 50 | inline ~ScopedTrace() { |
| 51 | atrace_end(mTag); |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | uint64_t mTag; |
| 56 | }; |
| 57 | |
| 58 | } // namespace android |
| 59 | |
| 60 | #endif // _WIN32 |
| 61 | |
| 62 | #endif // ANDROID_TRACE_H |