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 CPU_DETAIL_PARSER_H 16 #define CPU_DETAIL_PARSER_H 17 #include "print_event_parser.h" 18 #include "trace_data_cache.h" 19 #include "trace_plugin_result.pb.h" 20 #include "trace_streamer_filters.h" 21 22 namespace SysTuning { 23 namespace TraceStreamer { 24 struct RawTraceEventInfo { 25 uint8_t cpuId = INVALID_UINT8; 26 uint32_t eventId = INVALID_UINT32; 27 std::unique_ptr<FtraceEvent> msgPtr; 28 }; 29 class CpuDetailParser { 30 public: 31 CpuDetailParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx); 32 ~CpuDetailParser() = default; 33 void EventAppend(std::unique_ptr<RawTraceEventInfo> event); 34 bool FilterAllEvents(FtraceCpuDetailMsg& cpuDetail, bool isFinished = false); 35 void Clear(); 36 37 private: 38 void DealEvent(const RawTraceEventInfo& event); 39 bool SchedSwitchEvent(const RawTraceEventInfo& event); 40 bool SchedBlockReasonEvent(const RawTraceEventInfo& event); 41 bool SchedWakeupEvent(const RawTraceEventInfo& event) const; 42 bool SchedWakingEvent(const RawTraceEventInfo& event) const; 43 bool SchedWakeupNewEvent(const RawTraceEventInfo& event) const; 44 bool ProcessExitEvent(const RawTraceEventInfo& event) const; 45 bool ProcessFreeEvent(const RawTraceEventInfo& event) const; 46 bool BinderTractionEvent(const RawTraceEventInfo& event) const; 47 bool BinderTractionReceivedEvent(const RawTraceEventInfo& event) const; 48 bool BinderTractionAllocBufEvent(const RawTraceEventInfo& event) const; 49 bool BinderTractionLockEvent(const RawTraceEventInfo& event) const; 50 bool BinderTractionLockedEvent(const RawTraceEventInfo& event) const; 51 bool BinderTractionUnLockEvent(const RawTraceEventInfo& event) const; 52 bool TaskRenameEvent(const RawTraceEventInfo& event) const; 53 bool TaskNewtaskEvent(const RawTraceEventInfo& event) const; 54 bool ParseTracingMarkWriteOrPrintEvent(const RawTraceEventInfo& event); 55 bool CpuIdleEvent(const RawTraceEventInfo& event) const; 56 bool CpuFrequencyEvent(const RawTraceEventInfo& event) const; 57 bool CpuFrequencyLimitsEvent(const RawTraceEventInfo& event) const; 58 bool SuspendResumeEvent(const RawTraceEventInfo& event) const; 59 bool WorkqueueExecuteStartEvent(const RawTraceEventInfo& event) const; 60 bool WorkqueueExecuteEndEvent(const RawTraceEventInfo& event) const; 61 bool IrqHandlerEntryEvent(const RawTraceEventInfo& event) const; 62 bool IrqHandlerExitEvent(const RawTraceEventInfo& event) const; 63 bool IpiHandlerEntryEvent(const RawTraceEventInfo& event) const; 64 bool IpiHandlerExitEvent(const RawTraceEventInfo& event) const; 65 bool SoftIrqEntryEvent(const RawTraceEventInfo& event) const; 66 bool SoftIrqRaiseEvent(const RawTraceEventInfo& event) const; 67 bool SoftIrqExitEvent(const RawTraceEventInfo& event) const; 68 bool SetRateEvent(const RawTraceEventInfo& event) const; 69 bool ClockEnableEvent(const RawTraceEventInfo& event) const; 70 bool ClockDisableEvent(const RawTraceEventInfo& event) const; 71 bool RegulatorSetVoltageEvent(const RawTraceEventInfo& event) const; 72 bool RegulatorSetVoltageCompleteEvent(const RawTraceEventInfo& event) const; 73 bool RegulatorDisableEvent(const RawTraceEventInfo& event) const; 74 bool RegulatorDisableCompleteEvent(const RawTraceEventInfo& event) const; 75 76 void InterruptEventInitialization(); 77 void ClockEventInitialization(); 78 void CpuEventInitialization(); 79 void LockEventInitialization(); 80 void BinderEventInitialization(); 81 void StackEventsInitialization(); 82 void VoltageEventInitialization(); 83 84 private: 85 using FuncCall = std::function<bool(const RawTraceEventInfo& event)>; 86 const TraceStreamerFilters* streamFilters_; 87 TraceDataCache* traceDataCache_; 88 PrintEventParser printEventParser_; 89 90 uint32_t eventPid_ = INVALID_UINT32; 91 uint32_t eventTid_ = INVALID_UINT32; 92 uint64_t lastOverwrite_ = 0; 93 94 std::deque<std::unique_ptr<RawTraceEventInfo>> rawTraceEventList_ = {}; 95 std::map<std::string, FuncCall> eventToFunctionMap_ = {}; 96 97 TraceStreamerConfig config_{}; 98 const BuiltinClocks clock_ = TS_CLOCK_BOOTTIME; 99 const DataIndex schedWakeupIndex_ = traceDataCache_->GetDataIndex("sched_wakeup"); 100 const DataIndex schedWakingIndex_ = traceDataCache_->GetDataIndex("sched_waking"); 101 const DataIndex schedWakeupNewIndex_ = traceDataCache_->GetDataIndex("sched_wakeup_new"); 102 const DataIndex cpuIdleIndex_ = traceDataCache_->GetDataIndex("cpu_idle"); 103 const DataIndex cpuFrequencyIndex_ = traceDataCache_->GetDataIndex("cpu_frequency"); 104 const DataIndex cpuFrequencyLimitMaxIndex_ = traceDataCache_->GetDataIndex("cpu_frequency_limits_max"); 105 const DataIndex cpuFrequencyLimitMinIndex_ = traceDataCache_->GetDataIndex("cpu_frequency_limits_min"); 106 const DataIndex workQueueIndex_ = traceDataCache_->GetDataIndex("workqueue"); 107 }; 108 } // namespace TraceStreamer 109 } // namespace SysTuning 110 111 #endif // CPU_DETAIL_PARSER_H_ 112