• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SYS_EVENT_MEASURE_FILTER_H
17 #define SYS_EVENT_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 SysEventType { E_SYS_MEMORY_FILTER, E_SYS_VIRTUAL_MEMORY_FILTER, E_SYS_EVENT_SOURCE_FILTER };
31 
32 class SystemEventMeasureFilter : private FilterBase {
33 public:
34     SystemEventMeasureFilter(TraceDataCache* dataCache, const TraceStreamerFilters* filter, SysEventType);
35     SystemEventMeasureFilter(const SystemEventMeasureFilter&) = delete;
36     SystemEventMeasureFilter& operator=(const SystemEventMeasureFilter&) = delete;
37     ~SystemEventMeasureFilter() override;
38     void AppendNewMeasureData(DataIndex nameIndex, uint64_t timestamp, int64_t value);
39     uint32_t AppendNewMeasureFilter(DataIndex nameIndex);
40     void Clear();
41 private:
42     uint32_t GetOrCreateFilterId(DataIndex nameIndex);
43     void AddCertainFilterId(DataIndex nameIndex, uint64_t filterId);
44     std::map<DataIndex, uint64_t> tidStreamIdFilterIdMap_ = {};
45     SysEventType filterType_;
46 
47     const std::map<SysEventType, std::string> filterTypeValue = {
48         {E_SYS_MEMORY_FILTER, "sys_memory_filter"},
49         {E_SYS_VIRTUAL_MEMORY_FILTER, "sys_virtual_memory_filter"},
50         {E_SYS_EVENT_SOURCE_FILTER, "sys_event_source_filter"}};
51     const DataIndex sysMemoryFilterId_ = traceDataCache_->GetDataIndex("sys_memory_filter");
52     const DataIndex sysVMemoryFilterId_ = traceDataCache_->GetDataIndex("sys_virtual_memory_filter");
53     const DataIndex sysEventSourceFilterId_ = traceDataCache_->GetDataIndex("sys_event_source_filter");
54 };
55 } // namespace TraceStreamer
56 } // namespace SysTuning
57 #endif // SYS_EVENT_MEASURE_FILTER_H
58