1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 PTREADER_HILOG_PARSER_H 16 #define PTREADER_HILOG_PARSER_H 17 18 #include "common_types.h" 19 #include "event_parser_base.h" 20 #include "parser_base.h" 21 #include "string_help.h" 22 #include "string_to_numerical.h" 23 #include "trace_data_cache.h" 24 25 namespace SysTuning { 26 namespace TraceStreamer { 27 constexpr uint64_t MS_TO_NS = 1e6; 28 constexpr uint64_t US_TO_NS = 1e3; 29 constexpr uint32_t TM_YEAR_FROM = 1900; 30 constexpr uint32_t MS_FORMAT_LEN = 3; 31 constexpr uint32_t US_FORMAT_LEN = 6; 32 class PtreaderHilogParser : public EventParserBase { 33 public: 34 PtreaderHilogParser(TraceDataCache *dataCache, const TraceStreamerFilters *filters); 35 ~PtreaderHilogParser(); 36 void ParseHilogDataItem(const std::string &buffer, const uint64_t lineSeq, bool &haveSplitSeg); 37 void FilterAllHilogData(); 38 39 private: 40 bool HilogTimeStrToTimestamp(std::string &timeStr, uint64_t &timeStamp) const; 41 void FilterHilogData(std::unique_ptr<HilogLine> bufLine); 42 void BeginFilterHilogData(HilogLine *hilogData); 43 44 const std::regex hilogMatcher_ = std::regex(R"( *(\w+ )?([\-\d: ]+\.\d+) +(\d+) +(\d+) +([FEWID]) +(.+?): +(.+))"); 45 enum HILOG_MATCH_SEQ { 46 HILOG_MATCH_SEQ_ZONE = 1, 47 HILOG_MATCH_SEQ_TIME = 2, 48 HILOG_MATCH_SEQ_PID = 3, 49 HILOG_MATCH_SEQ_TID = 4, 50 HILOG_MATCH_SEQ_LEVEL = 5, 51 HILOG_MATCH_SEQ_TAG = 6, 52 HILOG_MATCH_SEQ_CONTENT = 7, 53 }; 54 std::vector<std::unique_ptr<HilogLine>> hilogList_ = {}; 55 }; 56 } // namespace TraceStreamer 57 } // namespace SysTuning 58 59 #endif // PTREADER_HILOG_PARSER_H 60