• 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 "htrace_hilog_parser.h"
16 #include "clock_filter.h"
17 #include "htrace_event_parser.h"
18 #include "process_filter.h"
19 #include "stat_filter.h"
20 namespace SysTuning {
21 namespace TraceStreamer {
HtraceHiLogParser(TraceDataCache * dataCache,const TraceStreamerFilters * ctx)22 HtraceHiLogParser::HtraceHiLogParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx)
23     : HtracePluginTimeParser(dataCache, ctx) {}
24 
~HtraceHiLogParser()25 HtraceHiLogParser::~HtraceHiLogParser()
26 {
27     TS_LOGI("hilog ts MIN:%llu, MAX:%llu", static_cast<unsigned long long>(GetPluginStartTime()),
28             static_cast<unsigned long long>(GetPluginEndTime()));
29 }
Parse(HilogInfo & tracePacket)30 void HtraceHiLogParser::Parse(HilogInfo& tracePacket)
31 {
32     if (!tracePacket.info_size()) {
33         return;
34     }
35     for (int i = 0; i < tracePacket.info_size(); i++) {
36         auto hilogLine = tracePacket.mutable_info(i);
37         uint64_t curLineSeq = hilogLine->id();
38         streamFilters_->statFilter_->IncreaseStat(TRACE_HILOG, STAT_EVENT_RECEIVED);
39         if (curLineSeq < lastLineSeq_ + 1) {
40             streamFilters_->statFilter_->IncreaseStat(TRACE_HILOG, STAT_EVENT_NOTMATCH);
41         } else if (curLineSeq > lastLineSeq_ + 1) {
42             streamFilters_->statFilter_->IncreaseStat(TRACE_HILOG, STAT_EVENT_DATA_LOST);
43         }
44         lastLineSeq_ = curLineSeq;
45         auto logData = traceDataCache_->GetDataIndex(hilogLine->context().c_str());
46         auto logDetails = hilogLine->detail();
47 
48         streamFilters_->processFilter_->GetOrCreateThreadWithPid(logDetails.tid(), logDetails.pid());
49         auto iter = logLevelString_.find(logDetails.level());
50         if (iter == logLevelString_.end()) {
51             streamFilters_->statFilter_->IncreaseStat(TRACE_HILOG, STAT_EVENT_DATA_INVALID);
52             TS_LOGD("log level do not exit!!!");
53             continue;
54         }
55         auto timeStamp = logDetails.tv_nsec() + logDetails.tv_sec() * SEC_TO_NS;
56         auto newTimeStamp = streamFilters_->clockFilter_->ToPrimaryTraceTime(TS_CLOCK_REALTIME, timeStamp);
57         UpdatePluginTimeRange(TS_CLOCK_REALTIME, timeStamp, newTimeStamp);
58         DataIndex levelData = traceDataCache_->dataDict_.GetStringIndex(iter->second.c_str());
59         DataIndex logTag = traceDataCache_->dataDict_.GetStringIndex(logDetails.tag().c_str());
60         traceDataCache_->GetHilogData()->AppendNewLogInfo(curLineSeq, newTimeStamp, logDetails.pid(), logDetails.tid(),
61                                                           levelData, logTag, logData, timeStamp);
62     }
63 }
Finish()64 void HtraceHiLogParser::Finish()
65 {
66     traceDataCache_->MixTraceTime(GetPluginStartTime(), GetPluginEndTime());
67 }
68 } // namespace TraceStreamer
69 } // namespace SysTuning
70