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_PROCESS_PARSER_H 16 #define HTRACE_PROCESS_PARSER_H 17 #include <cstdint> 18 #include <map> 19 #include <string> 20 #include "htrace_plugin_time_parser.h" 21 #include "process_plugin_result.pb.h" 22 #include "trace_streamer_filters.h" 23 #include "cpu_plugin_result.pb.h" 24 25 26 namespace SysTuning { 27 namespace TraceStreamer { 28 class HtraceProcessParser : public HtracePluginTimeParser { 29 public: 30 HtraceProcessParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx); 31 ~HtraceProcessParser(); 32 void Parse(ProcessData& tracePacket, uint64_t ts); 33 void Finish(); 34 struct TsLiveProcessData { SetLiveProcessTsLiveProcessData35 void SetLiveProcess(uint64_t ts, 36 ProcessInfo& liveProcessInfo, 37 CpuInfo& cpuUsageData, 38 PssInfo& pssInfo, 39 DiskioInfo& diskio) 40 { 41 ts_ = ts; 42 processInfo_ = std::make_unique<ProcessInfo>(liveProcessInfo); 43 cpuUsageData_ = std::make_unique<CpuInfo>(cpuUsageData); 44 pssInfo_ = std::make_unique<PssInfo>(pssInfo); 45 diskio_ = std::make_unique<DiskioInfo>(diskio); 46 } 47 uint64_t ts_; 48 std::unique_ptr<ProcessInfo> processInfo_; 49 std::unique_ptr<CpuInfo> cpuUsageData_; 50 std::unique_ptr<PssInfo> pssInfo_; 51 std::unique_ptr<DiskioInfo> diskio_; 52 }; 53 std::vector<std::unique_ptr<TsLiveProcessData>> liveProcessData_; 54 }; 55 } // namespace TraceStreamer 56 } // namespace SysTuning 57 58 #endif // HTRACE_PROCESS_PARSER_H 59