1 /* 2 * Copyright (c) 2021 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 #ifndef HTRACE_MEM_PARSER_H 16 #define HTRACE_MEM_PARSER_H 17 18 #include <cstdint> 19 #include <limits> 20 #include <map> 21 #include <stdexcept> 22 #include <string> 23 #include "htrace_plugin_time_parser.h" 24 #include "memory_plugin_result.pb.h" 25 #include "trace_data/trace_data_cache.h" 26 #include "trace_streamer_config.h" 27 #include "trace_streamer_filters.h" 28 namespace SysTuning { 29 namespace TraceStreamer { 30 class HtraceMemParser : public HtracePluginTimeParser { 31 public: 32 HtraceMemParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx); 33 ~HtraceMemParser(); 34 void Parse(const MemoryData& tracePacket, uint64_t, BuiltinClocks clock); 35 void Finish(); 36 private: 37 void ParseProcessInfo(const MemoryData& tracePacket, uint64_t timeStamp) const; 38 void ParseMemInfo(const MemoryData& tracePacket, uint64_t timeStamp) const; 39 void ParseMemInfoEasy(const MemoryData& tracePacket, uint64_t timeStamp) const; 40 void ParseVMemInfo(const MemoryData& tracePacket, uint64_t timeStamp) const; 41 void ParseVMemInfoEasy(const MemoryData& tracePacket, uint64_t timeStamp) const; 42 void ParseSmapsInfoEasy(const ProcessMemoryInfo& memInfo, uint64_t timeStamp) const; 43 std::map<MemInfoType, DataIndex> memNameDictMap_ = {}; 44 std::map<SysMeminfoType, DataIndex> sysMemNameDictMap_ = {}; 45 std::map<SysVMeminfoType, DataIndex> sysVMemNameDictMap_ = {}; 46 uint64_t zram_ = 0; 47 const DataIndex zramIndex_ = traceDataCache_->GetDataIndex("sys.mem.zram"); 48 TraceStreamerConfig config_{}; 49 }; 50 } // namespace TraceStreamer 51 } // namespace SysTuning 52 53 #endif // HTRACE_MEM_PARSER_H 54