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 #include "hi_sysevent_measure_filter.h"
17 #include "filter_filter.h"
18 #include "log.h"
19 #include "system_event_measure_filter.h"
20 #include "ts_common.h"
21
22 namespace SysTuning {
23 namespace TraceStreamer {
HiSysEventMeasureFilter(TraceDataCache * dataCache,const TraceStreamerFilters * filter)24 HiSysEventMeasureFilter::HiSysEventMeasureFilter(TraceDataCache* dataCache, const TraceStreamerFilters* filter)
25 : FilterBase(dataCache, filter), appKey_(INVALID_UINT64), appName_(INVALID_UINT64)
26 {
27 }
28
~HiSysEventMeasureFilter()29 HiSysEventMeasureFilter::~HiSysEventMeasureFilter() {}
30
AppendNewValue(uint64_t serial,uint64_t timestamp,DataIndex appNameId,DataIndex key,int32_t type,double numericValue,DataIndex strValue)31 DataIndex HiSysEventMeasureFilter::AppendNewValue(uint64_t serial,
32 uint64_t timestamp,
33 DataIndex appNameId,
34 DataIndex key,
35 int32_t type,
36 double numericValue,
37 DataIndex strValue)
38 {
39 uint64_t appKeyId = GetOrCreateFilterIdInternal(appNameId, key);
40 traceDataCache_->GetSyseventMeasureData()->
41 AppendData(serial, timestamp, appNameId, appKeyId, type, numericValue, strValue);
42 return appNameId;
43 }
AppendNewValue(int32_t brightnessState,int32_t btState,int32_t locationState,int32_t wifiState,int32_t streamDefault,int32_t voiceCall,int32_t music,int32_t streamRing,int32_t media,int32_t voiceAssistant,int32_t system,int32_t alarm,int32_t notification,int32_t bluetoolthSco,int32_t enforcedAudible,int32_t streamDtmf,int32_t streamTts,int32_t accessibility,int32_t recording,int32_t streamAll)44 void HiSysEventMeasureFilter::AppendNewValue(int32_t brightnessState,
45 int32_t btState,
46 int32_t locationState,
47 int32_t wifiState,
48 int32_t streamDefault,
49 int32_t voiceCall,
50 int32_t music,
51 int32_t streamRing,
52 int32_t media,
53 int32_t voiceAssistant,
54 int32_t system,
55 int32_t alarm,
56 int32_t notification,
57 int32_t bluetoolthSco,
58 int32_t enforcedAudible,
59 int32_t streamDtmf,
60 int32_t streamTts,
61 int32_t accessibility,
62 int32_t recording,
63 int32_t streamAll)
64 {
65 traceDataCache_->GetDeviceStateData()->AppendNewData(
66 brightnessState, btState, locationState, wifiState, streamDefault, voiceCall, music, streamRing, media,
67 voiceAssistant, system, alarm, notification, bluetoolthSco, enforcedAudible, streamDtmf, streamTts,
68 accessibility, recording, streamAll);
69 return;
70 }
GetOrCreateFilterIdInternal(DataIndex appNameId,DataIndex key)71 DataIndex HiSysEventMeasureFilter::GetOrCreateFilterIdInternal(DataIndex appNameId, DataIndex key)
72 {
73 uint64_t appKeyId = appKey_.Find(appNameId, key);
74 if (appKeyId == INVALID_DATAINDEX) {
75 appKeyId = traceDataCache_->GetAppNamesData()->AppendAppName(1, appNameId, key);
76 appKey_.Insert(appNameId, key, appKeyId);
77 }
78 return appKeyId;
79 }
80
GetOrCreateFilterId(DataIndex eventSource)81 DataIndex HiSysEventMeasureFilter::GetOrCreateFilterId(DataIndex eventSource)
82 {
83 DataIndex eventSourceFilterId = INVALID_DATAINDEX;
84 if (eventSource_.find(eventSource) == eventSource_.end()) {
85 eventSourceFilterId = streamFilters_->sysEventSourceFilter_->AppendNewMeasureFilter(eventSource);
86 eventSource_.insert(std::make_pair(eventSource, eventSourceFilterId));
87 } else {
88 eventSourceFilterId = eventSource_.at(eventSource);
89 }
90 return eventSourceFilterId;
91 }
GetOrCreateFilterId(DataIndex eventSource,DataIndex appName)92 DataIndex HiSysEventMeasureFilter::GetOrCreateFilterId(DataIndex eventSource, DataIndex appName)
93 {
94 DataIndex eventSourceFilterId = INVALID_DATAINDEX;
95 DataIndex appNameId = INVALID_DATAINDEX;
96 if (eventSource_.find(eventSource) == eventSource_.end()) {
97 eventSourceFilterId = streamFilters_->sysEventSourceFilter_->AppendNewMeasureFilter(eventSource);
98 eventSource_.insert(std::make_pair(eventSource, eventSourceFilterId));
99 } else {
100 eventSourceFilterId = eventSource_.at(eventSource);
101 }
102 appNameId = appName_.Find(eventSourceFilterId, appName);
103 if (appNameId == INVALID_DATAINDEX) {
104 appNameId = traceDataCache_->GetAppNamesData()->AppendAppName(0, eventSourceFilterId, appName);
105 appName_.Insert(eventSourceFilterId, appName, appNameId);
106 }
107 return appNameId;
108 }
109 std::tuple<DataIndex, DataIndex>
GetOrCreateFilterId(DataIndex eventSource,DataIndex appName,DataIndex key)110 HiSysEventMeasureFilter::GetOrCreateFilterId(DataIndex eventSource, DataIndex appName, DataIndex key)
111 {
112 DataIndex eventSourceFilterId = INVALID_DATAINDEX;
113 DataIndex appNameId = INVALID_DATAINDEX;
114 if (eventSource_.find(eventSource) == eventSource_.end()) {
115 eventSourceFilterId = streamFilters_->sysEventSourceFilter_->AppendNewMeasureFilter(eventSource);
116 eventSource_.insert(std::make_pair(eventSource, eventSourceFilterId));
117 } else {
118 eventSourceFilterId = eventSource_.at(eventSource);
119 }
120 appNameId = appName_.Find(eventSourceFilterId, appName);
121 if (appNameId == INVALID_DATAINDEX) {
122 appNameId = traceDataCache_->GetAppNamesData()->AppendAppName(0, eventSourceFilterId, appName);
123 appName_.Insert(eventSourceFilterId, appName, appNameId);
124 }
125 uint64_t appKeyId = appKey_.Find(appNameId, key);
126 if (appKeyId == INVALID_DATAINDEX) {
127 appKeyId = traceDataCache_->GetAppNamesData()->AppendAppName(1, appNameId, key);
128 appKey_.Insert(appNameId, key, appKeyId);
129 }
130 return std::make_tuple(appNameId, appKeyId);
131 }
132
Clear()133 void HiSysEventMeasureFilter::Clear()
134 {
135 appKey_.Clear();
136 appName_.Clear();
137 eventSource_.clear();
138 }
139 } // namespace TraceStreamer
140 } // namespace SysTuning
141