• 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 #include "clock_filter.h"
16 #include "hidump_plugin_result.pb.h"
17 #include "htrace_event_parser.h"
18 #include "process_filter.h"
19 #include "stat_filter.h"
20 #include "htrace_hidump_parser.h"
21 namespace SysTuning {
22 namespace TraceStreamer {
HtraceHidumpParser(TraceDataCache * dataCache,const TraceStreamerFilters * ctx)23 HtraceHidumpParser::HtraceHidumpParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx)
24     : streamFilters_(ctx), traceDataCache_(dataCache)
25 {
26     if (!traceDataCache_) {
27         TS_LOGE("traceDataCache_ should not be null");
28         return;
29     }
30     if (!streamFilters_) {
31         TS_LOGE("streamFilters_ should not be null");
32         return;
33     }
34 }
35 
~HtraceHidumpParser()36 HtraceHidumpParser::~HtraceHidumpParser()
37 {
38     TS_LOGI("FPS data ts MIN:%llu, MAX:%llu",
39             static_cast<unsigned long long>(traceStartTime_), static_cast<unsigned long long>(traceEndTime_));
40 }
Parse(HidumpInfo & tracePacket)41 void HtraceHidumpParser::Parse(HidumpInfo& tracePacket)
42 {
43     if (!tracePacket.fps_event_size()) {
44         return;
45     }
46     if (!traceDataCache_) {
47         TS_LOGE("traceDataCache_ should not be null");
48         return;
49     }
50     if (!streamFilters_) {
51         TS_LOGE("streamFilters_ should not be null");
52         return;
53     }
54     for (int i = 0; i < tracePacket.fps_event_size(); i++) {
55         streamFilters_->statFilter_->IncreaseStat(TRACE_HIDUMP_FPS, STAT_EVENT_RECEIVED);
56         auto hidumpData = tracePacket.mutable_fps_event(i);
57         auto timeStamp = hidumpData->time().tv_nsec() + hidumpData->time().tv_sec() * SEC_TO_NS;
58         auto newTimeStamp = streamFilters_->clockFilter_->ToPrimaryTraceTime(hidumpData->id(), timeStamp);
59         if (newTimeStamp != timeStamp) { // record the time only when the time is valid
60             traceStartTime_ = std::min(traceStartTime_, newTimeStamp);
61             traceEndTime_ = std::max(traceEndTime_, newTimeStamp);
62         } else {
63             streamFilters_->statFilter_->IncreaseStat(TRACE_HIDUMP_FPS, STAT_EVENT_DATA_INVALID);
64         }
65         auto fps = hidumpData->fps();
66         traceDataCache_->GetHidumpData()->AppendNewHidumpInfo(newTimeStamp, fps);
67     }
68 }
Finish()69 void HtraceHidumpParser::Finish()
70 {
71     traceDataCache_->MixTraceTime(traceStartTime_, traceEndTime_);
72 }
73 } // namespace TraceStreamer
74 } // namespace SysTuning
75