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 "common_types.h" 21 #include "event_parser_base.h" 22 #include "htrace_plugin_time_parser.h" 23 #include "trace_streamer_filters.h" 24 25 namespace SysTuning { 26 namespace TraceStreamer { 27 class HtraceProcessParser : public EventParserBase, public HtracePluginTimeParser { 28 public: 29 HtraceProcessParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx); 30 ~HtraceProcessParser(); 31 void Parse(ProtoReader::BytesView tracePacket, uint64_t ts); 32 void Finish(); 33 struct DiskioInfo { DiskioInfoDiskioInfo34 DiskioInfo(uint64_t rchar, 35 uint64_t wchar, 36 uint64_t syscr, 37 uint64_t syscw, 38 uint64_t rbytes, 39 uint64_t wbytes, 40 uint64_t cancelled_wbytes) 41 : rchar(rchar), 42 wchar(wchar), 43 syscr(syscr), 44 syscw(syscw), 45 rbytes(rbytes), 46 wbytes(wbytes), 47 cancelled_wbytes(cancelled_wbytes) 48 { 49 } 50 uint64_t rchar; 51 uint64_t wchar; 52 uint64_t syscr; 53 uint64_t syscw; 54 uint64_t rbytes; 55 uint64_t wbytes; 56 uint64_t cancelled_wbytes; 57 }; 58 struct PssInfo { PssInfoPssInfo59 explicit PssInfo(int32_t pssInfo) : pssInfo(pssInfo) {} 60 int32_t pssInfo; 61 }; 62 struct CpuInfo { CpuInfoCpuInfo63 CpuInfo(double cpuUsage, int32_t threadSum, uint64_t cpuTimeMs) 64 : cpuUsage(cpuUsage), threadSum(threadSum), cpuTimeMs(cpuTimeMs) 65 { 66 } 67 double cpuUsage; 68 int32_t threadSum; 69 uint64_t cpuTimeMs; 70 }; 71 struct ProcessInfo { ProcessInfoProcessInfo72 ProcessInfo(int32_t pid, const std::string& name, int32_t ppid, int32_t uid) 73 : pid(pid), name(name), ppid(ppid), uid(uid) 74 { 75 } 76 int32_t pid; 77 std::string name; 78 int32_t ppid; 79 int32_t uid; 80 }; 81 struct TsLiveProcessData { SetLiveProcessTsLiveProcessData82 void SetLiveProcess(uint64_t ts, 83 std::unique_ptr<ProcessInfo> liveProcessInfo, 84 std::unique_ptr<CpuInfo> cpuUsageData, 85 std::unique_ptr<PssInfo> pssInfo, 86 std::unique_ptr<DiskioInfo> diskio) 87 { 88 ts_ = ts; 89 processInfo_ = std::move(liveProcessInfo); 90 cpuUsageData_ = std::move(cpuUsageData); 91 pssInfo_ = std::move(pssInfo); 92 diskio_ = std::move(diskio); 93 } 94 uint64_t ts_; 95 std::unique_ptr<ProcessInfo> processInfo_; 96 std::unique_ptr<CpuInfo> cpuUsageData_; 97 std::unique_ptr<PssInfo> pssInfo_; 98 std::unique_ptr<DiskioInfo> diskio_; 99 }; 100 std::vector<std::unique_ptr<TsLiveProcessData>> liveProcessData_; 101 }; 102 } // namespace TraceStreamer 103 } // namespace SysTuning 104 105 #endif // HTRACE_PROCESS_PARSER_H 106