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_clock_detail_parser.h"
16 #include "clock_filter.h"
17 #include "htrace_event_parser.h"
18 #include "measure_filter.h"
19 #include "process_filter.h"
20 #include "stat_filter.h"
21 #include "symbols_filter.h"
22 namespace SysTuning {
23 namespace TraceStreamer {
HtraceClockDetailParser(TraceDataCache * dataCache,const TraceStreamerFilters * ctx)24 HtraceClockDetailParser::HtraceClockDetailParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx)
25 : streamFilters_(ctx), traceDataCache_(dataCache)
26 {
27 for (auto i = 0; i < MEM_MAX; i++) {
28 memNameDictMap_.insert(std::make_pair(static_cast<MemInfoType>(i),
29 traceDataCache_->GetDataIndex(config_.memNameMap_.at(static_cast<MemInfoType>(i)))));
30 }
31 }
32
33 HtraceClockDetailParser::~HtraceClockDetailParser() = default;
Parse(TracePluginResult & tracePacket) const34 void HtraceClockDetailParser::Parse(TracePluginResult& tracePacket) const
35 {
36 if (!tracePacket.clocks_detail_size()) {
37 return;
38 }
39 std::vector<SnapShot> snapShot;
40 TS_LOGI("got clock snapshot");
41 for (int i = 0; i < tracePacket.clocks_detail_size(); i++) {
42 auto clockInfo = tracePacket.mutable_clocks_detail(i);
43 TS_LOGI("clockid:%d, ts:%llu", clockInfo->id(),
44 static_cast<unsigned long long>(clockInfo->time().tv_nsec() + clockInfo->time().tv_sec() * SEC_TO_NS));
45 snapShot.push_back(SnapShot{static_cast<ClockId>(clockInfo->id()),
46 clockInfo->time().tv_nsec() + clockInfo->time().tv_sec() * SEC_TO_NS});
47 streamFilters_->clockFilter_->AddClockSnapshot(snapShot);
48 }
49 streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_CLOCK_SYNC, STAT_EVENT_RECEIVED);
50 }
51 } // namespace TraceStreamer
52 } // namespace SysTuning
53