• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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_PROCESS_MEASURE_FILTER,
32     E_CPU_MEASURE_FILTER,
33     E_CLOCK_RATE_FILTER,
34     E_CLOCK_ENABLE_FILTER,
35     E_CLOCK_DISABLE_FILTER,
36     E_CLK_RATE_FILTER,
37     E_CLK_ENABLE_FILTER,
38     E_CLK_DISABLE_FILTER
39 };
40 
41 class MeasureFilter : private FilterBase {
42 public:
43     MeasureFilter(TraceDataCache *dataCache, const TraceStreamerFilters *filter, FilterType);
44     MeasureFilter(const MeasureFilter &) = delete;
45     MeasureFilter &operator=(const MeasureFilter &) = delete;
46     ~MeasureFilter() override;
47     bool AppendNewMeasureData(uint64_t internalTid, DataIndex nameIndex, uint64_t timeStamp, int64_t value);
48     uint32_t GetOrCreateFilterId(uint64_t internalTid, DataIndex nameIndex);
49 
50 private:
51     void AddCertainFilterId(uint64_t internalTid, DataIndex nameIndex, uint64_t filterId);
52     DoubleMap<uint64_t, DataIndex, uint64_t> tidStreamIdFilterIdMap_;
53     FilterType filterType_;
54 
55     const std::map<FilterType, std::string> filterTypeValue = {
56         {E_PROCESS_MEASURE_FILTER, "process_measure_filter"}, {E_CPU_MEASURE_FILTER, "cpu_measure_filter"},
57         {E_CLOCK_RATE_FILTER, "clock_rate_filter"},           {E_CLOCK_ENABLE_FILTER, "clock_enable_filter"},
58         {E_CLOCK_DISABLE_FILTER, "clock_disable_filter"},     {E_CLK_RATE_FILTER, "clk_rate_filter"},
59         {E_CLK_ENABLE_FILTER, "clk_enable_filter"},           {E_CLK_DISABLE_FILTER, "clk_disable_filter"}};
60     const DataIndex clockSetRateDataIndex_ = traceDataCache_->GetDataIndex("clock_set_rate");
61     const DataIndex clockEnableDataIndex_ = traceDataCache_->GetDataIndex("clock_enable");
62     const DataIndex clockDisableDataIndex_ = traceDataCache_->GetDataIndex("clock_disable");
63     const DataIndex clkSetRateDataIndex_ = traceDataCache_->GetDataIndex("clk_set_rate");
64     const DataIndex clkEnableDataIndex_ = traceDataCache_->GetDataIndex("clk_enable");
65     const DataIndex clkDisableDataIndex_ = traceDataCache_->GetDataIndex("clk_disable");
66 };
67 } // namespace TraceStreamer
68 } // namespace SysTuning
69 #endif // THREAD_MEASURE_FILTER_H
70