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_plugin_time_parser.h"
16 namespace SysTuning {
17 namespace TraceStreamer {
HtracePluginTimeParser(TraceDataCache * dataCache,const TraceStreamerFilters * ctx)18 HtracePluginTimeParser::HtracePluginTimeParser(TraceDataCache* dataCache, const TraceStreamerFilters* ctx)
19 : EventParserBase(dataCache, ctx)
20 {
21 if (!streamFilters_) {
22 TS_LOGF("streamFilters_ should not be null");
23 return;
24 }
25 if (!traceDataCache_) {
26 TS_LOGF("traceDataCache_ should not be null");
27 return;
28 }
29 }
UpdatePluginTimeRange(ClockId clockId,uint64_t asyncTimestamp,uint64_t syncTimestamp)30 void HtracePluginTimeParser::UpdatePluginTimeRange(ClockId clockId, uint64_t asyncTimestamp, uint64_t syncTimestamp)
31 {
32 minTs_ = std::min(minTs_, asyncTimestamp);
33 maxTs_ = std::max(maxTs_, asyncTimestamp);
34 if (clockId == streamFilters_->clockFilter_->GetPrimaryClock()) {
35 syncHtracePluginStartTime_ = std::min(syncHtracePluginStartTime_, syncTimestamp);
36 syncHtracePluginEndTime_ = std::max(syncHtracePluginEndTime_, syncTimestamp);
37 return;
38 }
39 if (syncTimestamp != asyncTimestamp) {
40 syncHtracePluginStartTime_ = std::min(syncHtracePluginStartTime_, syncTimestamp);
41 syncHtracePluginEndTime_ = std::max(syncHtracePluginEndTime_, syncTimestamp);
42 } else {
43 asyncHtracePluginStartTime_ = std::min(asyncHtracePluginStartTime_, syncTimestamp);
44 asyncHtracePluginEndTime_ = std::max(asyncHtracePluginEndTime_, syncTimestamp);
45 }
46 }
GetPluginStartTime()47 uint64_t HtracePluginTimeParser::GetPluginStartTime()
48 {
49 if (syncHtracePluginStartTime_ != std::numeric_limits<uint64_t>::max()) {
50 return syncHtracePluginStartTime_;
51 } else if (asyncHtracePluginStartTime_ != std::numeric_limits<uint64_t>::max()) {
52 return asyncHtracePluginStartTime_;
53 }
54 return std::numeric_limits<uint64_t>::max();
55 }
56
GetPluginEndTime()57 uint64_t HtracePluginTimeParser::GetPluginEndTime()
58 {
59 if (syncHtracePluginEndTime_ != 0) {
60 return syncHtracePluginEndTime_;
61 } else if (asyncHtracePluginEndTime_ != 0) {
62 return asyncHtracePluginEndTime_;
63 }
64 return 0;
65 }
66 } // namespace TraceStreamer
67 } // namespace SysTuning
68