1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 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 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __DFX_TRACE_H__ 16 #define __DFX_TRACE_H__ 17 18 #include <cstdlib> 19 #include <cstdio> 20 #include <cstdint> 21 #ifdef DFX_ENABLE_TRACE 22 #include "hitrace_meter.h" 23 constexpr int TRACE_BUF_LEN = 128; 24 void DfxStartTrace(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 25 void FormatTraceName(char *name, size_t size, const char *fmt, ...) __attribute__((format(printf, 3, 4))); 26 27 #define DFX_TRACE_SCOPED(fmt, ...) \ 28 char traceName[TRACE_BUF_LEN] = {0}; \ 29 FormatTraceName(traceName, TRACE_BUF_LEN, fmt, ##__VA_ARGS__); \ 30 HitraceScoped trace(HITRACE_TAG_APP, traceName) 31 32 #define DFX_TRACE_START(fmt, ...) DfxStartTrace(fmt, ##__VA_ARGS__) 33 #define DFX_TRACE_FINISH(...) FinishTrace(HITRACE_TAG_APP) 34 #else 35 #define DFX_TRACE_SCOPED(fmt, ...) 36 #define DFX_TRACE_START(fmt, ...) 37 #define DFX_TRACE_FINISH(...) 38 #endif 39 40 #endif