1 /* 2 * Copyright (c) 2025 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 HIVIEWDFX_HIVIEW_TRACE_UTIL_H 17 #define HIVIEWDFX_HIVIEW_TRACE_UTIL_H 18 19 #include <cinttypes> 20 #include <string> 21 #include <vector> 22 23 #include "hitrace_dump.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 using namespace Hitrace; 28 29 namespace CallerName { 30 const std::string XPERF = "Xperf"; 31 const std::string XPOWER = "Xpower"; 32 const std::string RELIABILITY = "Reliability"; 33 const std::string HIVIEW = "Hiview"; 34 const std::string OTHER = "Other"; 35 const std::string SCREEN = "Screen"; 36 }; 37 38 namespace ClientName { 39 const std::string COMMAND = "Command"; 40 const std::string COMMON_DEV = "Other"; 41 const std::string APP = "APP"; 42 const std::string BETACLUB = "BetaClub"; 43 }; 44 45 namespace BusinessName { 46 const std::string BEHAVIOR = "behavior"; 47 const std::string TELEMETRY = "Telemetry"; 48 } 49 50 enum class TraceScenario : uint8_t { 51 TRACE_COMMAND, 52 TRACE_COMMON, 53 TRACE_DYNAMIC, 54 TRACE_TELEMETRY, 55 }; 56 57 enum class TraceStateCode : uint8_t { 58 SUCCESS, 59 DENY, // Change state deny 60 FAIL // Invoke dump or drop interface in wrong state 61 }; 62 63 enum class TraceFlowCode : uint8_t { 64 TRACE_ALLOW, 65 TRACE_DUMP_DENY, 66 TRACE_UPLOAD_DENY, 67 TRACE_HAS_CAPTURED_TRACE 68 }; 69 70 struct TraceRet { 71 TraceRet() = default; 72 TraceRetTraceRet73 explicit TraceRet(TraceStateCode stateError) : stateError_(stateError) {} 74 TraceRetTraceRet75 explicit TraceRet(TraceErrorCode codeError) : codeError_(codeError) {} 76 TraceRetTraceRet77 explicit TraceRet(TraceFlowCode codeError) : flowError_(codeError) {} 78 GetStateErrorTraceRet79 TraceStateCode GetStateError() 80 { 81 return stateError_; 82 } 83 GetCodeErrorTraceRet84 TraceErrorCode GetCodeError() 85 { 86 return codeError_; 87 } 88 GetFlowErrorTraceRet89 TraceFlowCode GetFlowError() 90 { 91 return flowError_; 92 } 93 IsSuccessTraceRet94 bool IsSuccess() 95 { 96 return stateError_ == TraceStateCode::SUCCESS && codeError_ == TraceErrorCode::SUCCESS 97 && flowError_ == TraceFlowCode::TRACE_ALLOW; 98 } 99 100 TraceStateCode stateError_ = TraceStateCode::SUCCESS; 101 TraceErrorCode codeError_ = TraceErrorCode::SUCCESS; 102 TraceFlowCode flowError_ = TraceFlowCode::TRACE_ALLOW; 103 }; 104 } 105 } 106 #endif // HIVIEWDFX_HIVIEW_TRACE_UTIL_H 107