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_EVENT_PARSER_H 16 #define HTRACE_EVENT_PARSER_H 17 #include <cstdint> 18 #include <functional> 19 #include <limits> 20 #include <stdexcept> 21 #include <string> 22 #include <unordered_set> 23 #include <vector> 24 25 #include "event_parser_base.h" 26 #include "google/protobuf/message_lite.h" 27 #include "log.h" 28 #include "print_event_parser.h" 29 #include "trace_data/trace_data_cache.h" 30 #include "trace_plugin_result.pb.h" 31 #include "trace_streamer_config.h" 32 #include "trace_streamer_filters.h" 33 #include "ts_common.h" 34 35 namespace SysTuning { 36 namespace TraceStreamer { 37 using namespace google::protobuf; 38 class HtraceEventParser : private EventParserBase { 39 public: 40 HtraceEventParser(TraceDataCache* dataCache, const TraceStreamerFilters* filter); 41 ~HtraceEventParser(); 42 void ParseDataItem(const FtraceCpuDetailMsg* cpuDetail, BuiltinClocks clock); 43 void FilterAllEventsTemp(); 44 void FilterAllEvents(); 45 void Clear() const; 46 private: 47 void DealEvent(const FtraceEvent& event); 48 bool BinderTractionEvent(const MessageLite& event) const; 49 bool BinderTractionReceivedEvent(const MessageLite& event) const; 50 bool BinderTractionAllocBufEvent(const MessageLite& event) const; 51 bool BinderTractionLockEvent(const MessageLite& event) const; 52 bool BinderTractionLockedEvent(const MessageLite& event) const; 53 bool BinderTractionUnLockEvent(const MessageLite& event) const; 54 bool SchedSwitchEvent(const MessageLite& event); 55 bool ProcessExitEvent(const MessageLite& event) const; 56 bool ProcessFreeEvent(const MessageLite& event) const; 57 bool TaskRenameEvent(const MessageLite& event) const; 58 bool TaskNewtaskEvent(const MessageLite& event) const; 59 bool ParsePrintEvent(const MessageLite& event); 60 bool SchedWakeupEvent(const MessageLite& event) const; 61 bool SchedWakeupNewEvent(const MessageLite& event) const; 62 bool SchedWakingEvent(const MessageLite& event) const; 63 bool CpuIdleEvent(const MessageLite& event) const; 64 bool CpuFrequencyEvent(const MessageLite& event) const; 65 bool CpuFrequencyLimitsEvent(const MessageLite& event) const; 66 bool SuspendResumeEvent(const MessageLite& event) const; 67 bool WorkqueueExecuteStartEvent(const MessageLite& event) const; 68 bool WorkqueueExecuteEndEvent(const MessageLite& event) const; 69 bool ClockSetRateEvent(const MessageLite& event) const; 70 bool ClockEnableEvent(const MessageLite& event) const; 71 bool ClockDisableEvent(const MessageLite& event) const; 72 bool ClkSetRateEvent(const MessageLite& event) const; 73 bool ClkEnableEvent(const MessageLite& event) const; 74 bool ClkDisableEvent(const MessageLite& event) const; 75 bool IrqHandlerEntryEvent(const MessageLite& event) const; 76 bool IrqHandlerExitEvent(const MessageLite& event) const; 77 bool SoftIrqEntryEvent(const MessageLite& event) const; 78 bool SoftIrqRaiseEvent(const MessageLite& event) const; 79 bool SoftIrqExitEvent(const MessageLite& event) const; 80 bool SysEnterEvent(const MessageLite& event) const; 81 bool SysExitEvent(const MessageLite& event) const; 82 bool OomScoreAdjUpdate(const MessageLite& event) const; 83 bool SignalGenerateEvent(const MessageLite& event) const; 84 bool SignalDeleverEvent(const MessageLite& event) const; 85 bool InvokeFunc(const SupportedTraceEventType& eventType, const MessageLite& msgBase); 86 class EventInfo { 87 public: EventInfo(const std::string & common,uint64_t eventTimestamp,uint32_t eventCpu,uint32_t eventPid,uint32_t eventTid,const FtraceEvent & cpuDetail)88 EventInfo(const std::string& common, 89 uint64_t eventTimestamp, 90 uint32_t eventCpu, 91 uint32_t eventPid, 92 uint32_t eventTid, 93 const FtraceEvent& cpuDetail) 94 : common_(common), 95 eventTimestamp_(eventTimestamp), 96 eventCpu_(eventCpu), 97 eventPid_(eventPid), 98 eventTid_(eventTid), 99 cpuDetail_(std::move(cpuDetail)) 100 { 101 } 102 std::string common_; 103 uint64_t eventTimestamp_; 104 uint32_t eventCpu_; 105 uint32_t eventPid_; 106 uint32_t eventTid_; 107 FtraceEvent cpuDetail_; 108 }; 109 using FuncCall = std::function<bool(const MessageLite& event)>; 110 uint32_t eventCpu_ = INVALID_UINT32; 111 uint64_t eventTimestamp_ = INVALID_UINT64; 112 std::string comm_ = ""; 113 uint32_t eventPid_ = INVALID_UINT32; 114 uint32_t eventTid_ = INVALID_UINT32; 115 std::map<std::string, FuncCall> eventToFunctionMap_ = {}; 116 std::unordered_set<uint32_t> tids_ = {}; 117 std::unordered_set<uint32_t> pids_ = {}; 118 DataIndex workQueueId_ = 0; 119 PrintEventParser printEventParser_; 120 uint64_t lastOverwrite_ = 0; 121 uint64_t ftraceStartTime_ = std::numeric_limits<uint64_t>::max(); 122 uint64_t ftraceEndTime_ = 0; 123 std::vector<std::unique_ptr<EventInfo>> eventList_ = {}; 124 const DataIndex signalGenerateId_ = traceDataCache_->GetDataIndex("signal_generate"); 125 const DataIndex signalDeliverId_ = traceDataCache_->GetDataIndex("signal_deliver"); 126 const DataIndex schedWakeupName_ = traceDataCache_->GetDataIndex("sched_wakeup"); 127 const DataIndex schedWakingName_ = traceDataCache_->GetDataIndex("sched_waking"); 128 const DataIndex schedWakeupNewName_ = traceDataCache_->GetDataIndex("sched_wakeup_new"); 129 const DataIndex cpuIdleName_ = traceDataCache_->GetDataIndex("cpu_idle"); 130 const DataIndex cpuFrequencyName_ = traceDataCache_->GetDataIndex("cpu_frequency"); 131 const DataIndex cpuFrequencyLimitMaxNameId = traceDataCache_->GetDataIndex("cpu_frequency_limits_max"); 132 const DataIndex cpuFrequencyLimitMinNameId = traceDataCache_->GetDataIndex("cpu_frequency_limits_min"); 133 const DataIndex sysEnterName_ = traceDataCache_->GetDataIndex("sys_enter"); 134 const DataIndex sysExitName_ = traceDataCache_->GetDataIndex("sys_exit"); 135 const DataIndex oomScoreAdjName_ = traceDataCache_->GetDataIndex("oom_score_adj"); 136 TraceStreamerConfig config_{}; 137 }; 138 } // namespace TraceStreamer 139 } // namespace SysTuning 140 141 #endif // HTRACE_EVENT_PARSER_H_ 142