1 /* 2 * Copyright (C) 2022-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 16 #ifndef HITRACE_METER_TEST_UTILS_H 17 #define HITRACE_METER_TEST_UTILS_H 18 19 #include <fstream> 20 #include <hilog/log.h> 21 22 #ifdef HITRACE_METER_SDK_C 23 #include "trace.h" 24 #else 25 #include "hitrace_meter.h" 26 #include "hitrace/hitraceid.h" 27 #endif 28 29 namespace OHOS { 30 namespace HiviewDFX { 31 namespace HitraceTest { 32 constexpr int RECORD_SIZE_MAX = 1024; 33 34 struct TraceInfo { 35 char type; 36 #ifdef HITRACE_METER_SDK_C 37 HiTrace_Output_Level level; 38 #else 39 HiTraceOutputLevel level; 40 #endif 41 uint64_t tag; 42 int64_t value; 43 const char* name; 44 const char* customCategory; 45 const char* customArgs; 46 HiTraceId* hiTraceId = nullptr; 47 }; 48 49 bool Init(const char (&pid)[6]); 50 bool CleanTrace(); 51 bool CleanFtrace(); 52 bool SetFtrace(const std::string& filename, bool enabled); 53 bool SetFtrace(const std::string& filename, uint64_t value); 54 std::vector<std::string> ReadTrace(std::string filename = ""); 55 bool FindResult(std::string record, const std::vector<std::string>& list); 56 bool GetTraceResult(TraceInfo& traceInfo, const std::vector<std::string>& list, 57 char (&record)[RECORD_SIZE_MAX + 1]); 58 } 59 } 60 } 61 #endif 62