• 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 #include "clock_filter_ex.h"
16 #include "hi_sysevent_filter/hi_sysevent_measure_filter.h"
17 #include "pbreader_hisysevent_parser.h"
18 #include "process_filter.h"
19 namespace SysTuning {
20 namespace TraceStreamer {
PbreaderHisyseventParser(TraceDataCache * dataCache,const TraceStreamerFilters * ctx)21 PbreaderHisyseventParser::PbreaderHisyseventParser(TraceDataCache *dataCache, const TraceStreamerFilters *ctx)
22     : EventParserBase(dataCache, ctx)
23 {
24 }
~PbreaderHisyseventParser()25 PbreaderHisyseventParser::~PbreaderHisyseventParser()
26 {
27     TS_LOGI("hisysevent ts MIN:%llu, MAX:%llu",
28             static_cast<unsigned long long>(streamFilters_->hiSysEventMeasureFilter_->GetPluginStartTime()),
29             static_cast<unsigned long long>(streamFilters_->hiSysEventMeasureFilter_->GetPluginEndTime()));
30     TS_LOGI("hisysevent real ts MIN:%llu, MAX:%llu",
31             static_cast<unsigned long long>(streamFilters_->hiSysEventMeasureFilter_->MinTs()),
32             static_cast<unsigned long long>(streamFilters_->hiSysEventMeasureFilter_->MaxTs()));
33 }
Finish()34 void PbreaderHisyseventParser::Finish()
35 {
36     auto startTime = streamFilters_->hiSysEventMeasureFilter_->GetPluginStartTime();
37     auto endTime = streamFilters_->hiSysEventMeasureFilter_->GetPluginEndTime();
38     if (startTime != endTime) {
39         traceDataCache_->MixTraceTime(startTime, endTime);
40     }
41 }
42 
Parse(ProtoReader::HisyseventInfo_Reader * tracePacket,uint64_t ts,bool & haveSplitSeg)43 void PbreaderHisyseventParser::Parse(ProtoReader::HisyseventInfo_Reader *tracePacket, uint64_t ts, bool &haveSplitSeg)
44 {
45     // parse hisysevent device state
46     if (tracePacket->has_device_state()) {
47         ProtoReader::DeviceStat_Reader deviceStat(tracePacket->device_state());
48         ProtoReader::AudioVolumeInfo_Reader audioVolumeInfo(deviceStat.volume_state());
49         streamFilters_->hiSysEventMeasureFilter_->AppendNewValue(
50             deviceStat.brightness_state(), deviceStat.bt_state(), deviceStat.location_state(), deviceStat.wifi_state(),
51             audioVolumeInfo.stream_default(), audioVolumeInfo.voice_call(), audioVolumeInfo.music(),
52             audioVolumeInfo.stream_ring(), audioVolumeInfo.media(), audioVolumeInfo.voice_assistant(),
53             audioVolumeInfo.system(), audioVolumeInfo.alarm(), audioVolumeInfo.notification(),
54             audioVolumeInfo.bluetoolth_sco(), audioVolumeInfo.enforced_audible(), audioVolumeInfo.stream_dtmf(),
55             audioVolumeInfo.stream_tts(), audioVolumeInfo.accessibility(), audioVolumeInfo.recording(),
56             audioVolumeInfo.stream_all());
57     }
58     // Parse HisyseventLine info
59 
60     for (auto i = tracePacket->info(); i; ++i) {
61         ProtoReader::HisyseventLine_Reader hisyseventLine(i->ToBytes());
62         json jMessage;
63         if (!jMessage.accept(hisyseventLine.raw_content().ToStdString())) {
64             continue;
65         }
66         jMessage = json::parse(hisyseventLine.raw_content().ToStdString());
67         streamFilters_->hiSysEventMeasureFilter_->FilterAllHiSysEvent(jMessage, hisyseventLine.id(), haveSplitSeg);
68         if (haveSplitSeg) {
69             return;
70         }
71     }
72 }
Parse(ProtoReader::HisyseventConfig_Reader * tracePacket,uint64_t ts)73 void PbreaderHisyseventParser::Parse(ProtoReader::HisyseventConfig_Reader *tracePacket, uint64_t ts)
74 {
75     streamFilters_->hiSysEventMeasureFilter_->AppendNewValue("message", tracePacket->msg().ToStdString());
76     streamFilters_->hiSysEventMeasureFilter_->AppendNewValue("process_name", tracePacket->process_name().ToStdString());
77     return;
78 }
79 } // namespace TraceStreamer
80 } // namespace SysTuning
81