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 HTRACE_NATIVE_HOOK_PARSER_H 16 #define HTRACE_NATIVE_HOOK_PARSER_H 17 #include <cstdint> 18 #include <map> 19 #include <set> 20 #include <string> 21 #include "common_types.h" 22 #include "event_parser_base.h" 23 #include "htrace_plugin_time_parser.h" 24 #include "native_hook_filter.h" 25 #include "offline_symbolization_filter.h" 26 #include "trace_streamer_config.h" 27 #include "trace_streamer_filters.h" 28 namespace SysTuning { 29 namespace TraceStreamer { 30 class PbreaderNativeHookParser : public EventParserBase, public HtracePluginTimeParser { 31 public: 32 PbreaderNativeHookParser(TraceDataCache *dataCache, const TraceStreamerFilters *ctx); 33 ~PbreaderNativeHookParser(); 34 void ParseConfigInfo(PbreaderDataSegment &dataSeg); 35 void Parse(PbreaderDataSegment &dataSeg, bool &haveSplitSeg); 36 void FinishSplitNativeHook(); 37 void FinishParseNativeHookData(); 38 void Finish(); NativeHookReloadElfSymbolTable(const std::unique_ptr<SymbolsFile> & symbolsFile)39 void NativeHookReloadElfSymbolTable(const std::unique_ptr<SymbolsFile> &symbolsFile) 40 { 41 nativeHookFilter_->NativeHookReloadElfSymbolTable(symbolsFile); 42 } UpdataOfflineSymbolizationMode(bool isOfflineSymbolizationMode)43 void UpdataOfflineSymbolizationMode(bool isOfflineSymbolizationMode) 44 { 45 // Ut testing the offline symbolic use of native_hook,do not delete!!! 46 nativeHookFilter_->UpdataOfflineSymbolizationMode(isOfflineSymbolizationMode); 47 } 48 49 private: 50 void ParseNativeHookAuxiliaryEvent(std::unique_ptr<NativeHookMetaData> &nativeHookMetaData); 51 void ParseFileEvent(const ProtoReader::BytesView &bytesView); 52 void ParseSymbolEvent(const ProtoReader::BytesView &bytesView); 53 void ParseThreadEvent(const ProtoReader::BytesView &bytesView); 54 void ParseFrameMap(std::unique_ptr<NativeHookMetaData> &nativeHookMetaData); 55 bool ParseStackMap(const ProtoReader::BytesView &bytesView); 56 void SplitHookData(std::unique_ptr<NativeHookMetaData> &nativeHookMetaData, bool &haveSplitSeg); 57 58 private: 59 std::vector<std::shared_ptr<const std::string>> segs_ = {}; 60 std::unique_ptr<NativeHookFilter> nativeHookFilter_; 61 uint64_t hookBootTime_ = 0; 62 bool isCommData_ = false; 63 uint64_t statisticsInterval_ = 0; 64 }; 65 } // namespace TraceStreamer 66 } // namespace SysTuning 67 68 #endif // HTRACE_NATIVE_HOOK_PARSER_H 69