/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Description: FlowController define */ #ifndef FLOW_CONTROLLER_H #define FLOW_CONTROLLER_H #include "ftrace_data_reader.h" #include "ftrace_namespace.h" #include "ftrace_parser.h" #include "kernel_symbols_parser.h" #include "paged_mem_pool.h" #include "plugin_module_api.h" #include "result_transporter.h" #include "trace_ops.h" #include "trace_plugin_config.pb.h" #include #include #include #include #include using WriterStructPtr = std::unique_ptr::pointer; FTRACE_NS_BEGIN class FlowController { public: FlowController(void); ~FlowController(void); int SetWriter(const WriterStructPtr& writer); int LoadConfig(const uint8_t configData[], uint32_t size); int StartCapture(void); int StopCapture(void); bool ParseBasicData(void); private: DISALLOW_COPY_AND_MOVE(FlowController); bool CreateRawDataReaders(); bool CreatePagedMemoryPool(); bool CreateRawDataBuffers(); bool CreateRawDataCaches(); void SetupTraceBufferSize(uint32_t sizeKb); void SetupTransporterFlushParams(uint32_t intervalMs, uint32_t thresholdKb); void GenerateRawDataFileNames(const std::string& prefix); void SetupTraceReadPeriod(uint32_t periodMs); void CaptureWork(); long ReadEventData(int cpuid); bool ParseEventData(int cpuid, long dataSize); bool AddPlatformEventsToParser(void); void EnableTraceEvents(void); void DisableTraceEvents(void); void DisableAllCategories(void); bool ReportClockTimes(void); bool ParseKernelSymbols(void); bool ParsePerCpuStatus(int stage); bool ParseFtraceEvent(int cpuid, uint8_t page[]); static std::unique_ptr GetTraceOps(); using EventTypeName = std::pair; std::vector supportedEvents_ = {}; std::vector enabledEvents_ = {}; std::unique_ptr memPool_ = nullptr; std::unique_ptr ksymsParser_ = nullptr; std::unique_ptr ftraceParser_ = nullptr; std::unique_ptr tansporter_ = nullptr; std::unique_ptr traceOps_ = nullptr; std::vector> ftraceReaders_ = {}; std::vector> ftraceBuffers_; std::vector> rawDataDumpFile_; std::atomic keepRunning_ = false; std::thread pollThread_ = {}; // for trace plugin config fields std::vector requestEvents_ = {}; // 1 std::vector traceCategories_ = {}; // 2 std::vector traceApps_ = {}; // 3 std::vector rawDataDumpPath_ = {}; // 13 uint32_t tracePeriodMs_ = 0; // 10 uint32_t bufferSizeKb_ = 0; // 6 bool parseKsyms_ = false; // 7 WriterStructPtr resultWriter_ = nullptr; int platformCpuNum_ = 0; bool getClockTimes_ = true; bool ftraceSupported_ = false; bool flushCacheData_ = false; unsigned int hitraceTime_ = 0; std::string traceClock_; }; FTRACE_NS_END #endif // FLOW_CONTROLLER_H