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 16 #ifndef THREAD_MEASURE_FILTER_H 17 #define THREAD_MEASURE_FILTER_H 18 19 #include <map> 20 #include <string_view> 21 #include <tuple> 22 23 #include "double_map.h" 24 #include "filter_base.h" 25 #include "trace_data_cache.h" 26 #include "trace_streamer_filters.h" 27 28 namespace SysTuning { 29 namespace TraceStreamer { 30 enum FilterType { 31 E_THREADMEASURE_FILTER, 32 E_THREAD_FILTER, 33 E_PROCESS_MEASURE_FILTER, 34 E_PROCESS_FILTER_FILTER, 35 E_CPU_MEASURE_FILTER, 36 E_CLOCK_RATE_FILTER, 37 E_CLOCK_ENABLE_FILTER, 38 E_CLOCK_DISABLE_FILTER, 39 E_CLK_RATE_FILTER, 40 E_CLK_ENABLE_FILTER, 41 E_CLK_DISABLE_FILTER 42 }; 43 44 class MeasureFilter : private FilterBase { 45 public: 46 MeasureFilter(TraceDataCache* dataCache, const TraceStreamerFilters* filter, FilterType); 47 MeasureFilter(const MeasureFilter&) = delete; 48 MeasureFilter& operator=(const MeasureFilter&) = delete; 49 ~MeasureFilter() override; 50 bool AppendNewMeasureData(uint64_t internalTid, DataIndex nameIndex, uint64_t timestamp, int64_t value); 51 uint32_t GetOrCreateFilterId(uint64_t internalTid, DataIndex nameIndex); 52 void Clear(); 53 private: 54 void AddCertainFilterId(uint64_t internalTid, DataIndex nameIndex, uint64_t filterId); 55 DoubleMap<uint64_t, DataIndex, uint64_t> tidStreamIdFilterIdMap_; 56 FilterType filterType_; 57 58 const std::map<FilterType, std::string> filterTypeValue = { 59 { E_THREADMEASURE_FILTER, "thread_measure_filter" }, 60 { E_THREAD_FILTER, "thread_measure" }, 61 { E_PROCESS_MEASURE_FILTER, "process_measure_filter" }, 62 { E_PROCESS_FILTER_FILTER, "process_filter" }, 63 { E_CPU_MEASURE_FILTER, "cpu_measure_filter" }, 64 { E_CLOCK_RATE_FILTER, "clock_rate_filter" }, 65 { E_CLOCK_ENABLE_FILTER, "clock_enable_filter" }, 66 { E_CLOCK_DISABLE_FILTER, "clock_disable_filter" }, 67 { E_CLK_RATE_FILTER, "clk_rate_filter" }, 68 { E_CLK_ENABLE_FILTER, "clk_enable_filter" }, 69 { E_CLK_DISABLE_FILTER, "clk_disable_filter" } 70 }; 71 const DataIndex clockSetRateDataIndex_ = traceDataCache_->GetDataIndex("clock_set_rate"); 72 const DataIndex clockEnableDataIndex_ = traceDataCache_->GetDataIndex("clock_enable"); 73 const DataIndex clockDisableDataIndex_ = traceDataCache_->GetDataIndex("clock_disable"); 74 const DataIndex clkSetRateDataIndex_ = traceDataCache_->GetDataIndex("clk_set_rate"); 75 const DataIndex clkEnableDataIndex_ = traceDataCache_->GetDataIndex("clk_enable"); 76 const DataIndex clkDisableDataIndex_ = traceDataCache_->GetDataIndex("clk_disable"); 77 }; 78 } // namespace TraceStreamer 79 } // namespace SysTuning 80 #endif // THREAD_MEASURE_FILTER_H 81