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 16 #ifndef TRACE_JSON_PARSER_H 17 #define TRACE_JSON_PARSER_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "hitrace_define.h" 24 #include "nocopyable.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 namespace Hitrace { 29 enum TraceType { 30 USER = 0, 31 KERNEL 32 }; 33 34 struct TraceTag { 35 std::string description; 36 uint64_t tag; 37 TraceType type; 38 std::vector<std::string> enablePath; 39 std::vector<std::string> formatPath; 40 }; 41 42 class TraceJsonParser { 43 public: 44 static TraceJsonParser& Instance(); 45 GetAllTagInfos()46 const std::map<std::string, TraceTag>& GetAllTagInfos() const { return traceTagInfos_; } GetTagGroups()47 const std::map<std::string, std::vector<std::string>>& GetTagGroups() const { return tagGroups_; } GetBaseFmtPath()48 const std::vector<std::string>& GetBaseFmtPath() const { return baseTraceFormats_; } 49 50 const AgeingParam& GetAgeingParam(TraceDumpType type) const; 51 GetSnapshotDefaultBufferSizeKb()52 int GetSnapshotDefaultBufferSizeKb() const { return snapshotBufSzKb_; } 53 private: 54 std::map<std::string, TraceTag> traceTagInfos_ = {}; 55 std::map<std::string, std::vector<std::string>> tagGroups_ = {}; 56 std::vector<std::string> baseTraceFormats_ = {}; 57 58 int snapshotBufSzKb_ = 0; 59 60 AgeingParam snapShotAgeingParam_ = {}; 61 AgeingParam recordAgeingParam_ = {}; 62 63 TraceJsonParser(const std::string& hitraceUtilsJson, const std::string& productConfigJson); 64 65 void InitSnapshotDefaultBufferSize(); 66 void InitAgeingParam(); 67 68 void ParseHitraceUtilsJson(const std::string& hitraceUtilsJson); 69 void ParseProductConfigJson(const std::string& productConfigJson); 70 71 void PrintParseResult(); 72 73 ~TraceJsonParser() = default; 74 DISALLOW_COPY_AND_MOVE(TraceJsonParser); 75 }; 76 } // namespace Hitrace 77 } // namespace HiviewDFX 78 } // namespace OHOS 79 #endif // TRACE_JSON_PARSER_H