1 /* 2 * Copyright (c) 2022-2022 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 16 #ifndef HISTREAMER_HITRACE_UTILS_H 17 #define HISTREAMER_HITRACE_UTILS_H 18 19 #if defined(OHOS_LITE) || defined(_WIN32) 20 #define SYNC_TRACER() 21 #define SYNC_TRACE_START(title) 22 #define SYNC_TRACE_END() 23 #define ASYNC_TRACER() 24 #define ASYNC_TRACE_START(title, taskId) 25 #define ASYNC_TRACE_END(title, taskId) 26 #define COUNT_TRACE(title, count) 27 #else 28 #include "hitrace_meter.h" 29 #define DEFAULT_HITRACE_LIMIT (-1) 30 #define DEFAULT_HITRACE_TAG HITRACE_TAG_ZMEDIA 31 #define DEFAULT_HITRACE_TASK_ID 1 32 #define DEFAULT_HITRACE_PREFIX "HiStreamer::" 33 #define BUILD_TRACE_TITLE() ((DEFAULT_HITRACE_PREFIX) + (std::string(__FUNCTION__))) 34 #define WRAP_TITLE_PREFIX(title) ((DEFAULT_HITRACE_PREFIX) + (std::string(__FUNCTION__)) + " : " + (title)) 35 #define SYNC_TRACER() SyncTracker __syncTracker(BUILD_TRACE_TITLE()) 36 #define SYNC_TRACE_START(title) StartTrace(DEFAULT_HITRACE_TAG, WRAP_TITLE_PREFIX(title), DEFAULT_HITRACE_LIMIT) 37 #define SYNC_TRACE_END() FinishTrace(DEFAULT_HITRACE_TAG) 38 #define ASYNC_TRACER() AsyncTracker __asyncTracker(BUILD_TRACE_TITLE(), DEFAULT_HITRACE_TASK_ID) 39 #define ASYNC_TRACE_START(title, taskId) \ 40 StartAsyncTrace(DEFAULT_HITRACE_TAG, WRAP_TITLE_PREFIX(title), taskId, DEFAULT_HITRACE_LIMIT) 41 #define ASYNC_TRACE_END(title, taskId) FinishAsyncTrace(WRAP_TITLE_PREFIX(title), taskId, DEFAULT_HITRACE_TAG) 42 #define COUNT_TRACE(title, count) CountTrace(DEFAULT_HITRACE_TAG, WRAP_TITLE_PREFIX(title), count) 43 44 namespace OHOS { 45 namespace Media { 46 class SyncTracker { 47 public: 48 explicit SyncTracker(const std::string &title); 49 ~SyncTracker(); 50 }; 51 52 class AsyncTracker { 53 public: 54 AsyncTracker(const std::string &title, int32_t taskId); 55 ~AsyncTracker(); 56 private: 57 const std::string title_; 58 int32_t taskId_; 59 }; 60 } 61 } 62 #endif 63 #endif // HISTREAMER_HITRACE_UTILS_H 64