• 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 
43 static std::stringstream ss;
Parse(ProtoReader::HisyseventInfo_Reader * tracePacket,uint64_t ts,bool & haveSplitSeg)44 void PbreaderHisyseventParser::Parse(ProtoReader::HisyseventInfo_Reader *tracePacket, uint64_t ts, bool &haveSplitSeg)
45 {
46     // parse hisysevent device state
47     if (tracePacket->has_device_state()) {
48         ProtoReader::DeviceStat_Reader deviceStat(tracePacket->device_state());
49         ProtoReader::AudioVolumeInfo_Reader audioVolumeInfo(deviceStat.volume_state());
50         streamFilters_->hiSysEventMeasureFilter_->AppendNewValue(
51             deviceStat.brightness_state(), deviceStat.bt_state(), deviceStat.location_state(), deviceStat.wifi_state(),
52             audioVolumeInfo.stream_default(), audioVolumeInfo.voice_call(), audioVolumeInfo.music(),
53             audioVolumeInfo.stream_ring(), audioVolumeInfo.media(), audioVolumeInfo.voice_assistant(),
54             audioVolumeInfo.system(), audioVolumeInfo.alarm(), audioVolumeInfo.notification(),
55             audioVolumeInfo.bluetoolth_sco(), audioVolumeInfo.enforced_audible(), audioVolumeInfo.stream_dtmf(),
56             audioVolumeInfo.stream_tts(), audioVolumeInfo.accessibility(), audioVolumeInfo.recording(),
57             audioVolumeInfo.stream_all());
58     }
59     // Parse HisyseventLine info
60 
61     for (auto i = tracePacket->info(); i; ++i) {
62         ProtoReader::HisyseventLine_Reader hisyseventLine(i->ToBytes());
63         json jMessage;
64         if (!jMessage.accept(hisyseventLine.raw_content().ToStdString())) {
65             continue;
66         }
67         jMessage = json::parse(hisyseventLine.raw_content().ToStdString());
68         streamFilters_->hiSysEventMeasureFilter_->FilterAllHiSysEvent(jMessage, hisyseventLine.id(), haveSplitSeg);
69         if (haveSplitSeg) {
70             return;
71         }
72     }
73 }
Parse(ProtoReader::HisyseventConfig_Reader * tracePacket,uint64_t ts)74 void PbreaderHisyseventParser::Parse(ProtoReader::HisyseventConfig_Reader *tracePacket, uint64_t ts)
75 {
76     streamFilters_->hiSysEventMeasureFilter_->AppendNewValue("message", tracePacket->msg().ToStdString());
77     streamFilters_->hiSysEventMeasureFilter_->AppendNewValue("process_name", tracePacket->process_name().ToStdString());
78     return;
79 }
80 } // namespace TraceStreamer
81 } // namespace SysTuning
82