• 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 "htrace_plugin_time_parser.h"
16 #include "clock_filter.h"
17 namespace SysTuning {
18 namespace TraceStreamer {
HtracePluginTimeParser()19 HtracePluginTimeParser::HtracePluginTimeParser() {}
UpdatePluginTimeRange(ClockId clockId,uint64_t asyncTimestamp,uint64_t syncTimestamp)20 void HtracePluginTimeParser::UpdatePluginTimeRange(ClockId clockId, uint64_t asyncTimestamp, uint64_t syncTimestamp)
21 {
22     minTs_ = std::min(minTs_, asyncTimestamp);
23     maxTs_ = std::max(maxTs_, asyncTimestamp);
24     if (clockId == g_primaryClockId) {
25         syncHtracePluginStartTime_ = std::min(syncHtracePluginStartTime_, syncTimestamp);
26         syncHtracePluginEndTime_ = std::max(syncHtracePluginEndTime_, syncTimestamp);
27         return;
28     }
29     if (syncTimestamp != asyncTimestamp) {
30         syncHtracePluginStartTime_ = std::min(syncHtracePluginStartTime_, syncTimestamp);
31         syncHtracePluginEndTime_ = std::max(syncHtracePluginEndTime_, syncTimestamp);
32     } else {
33         asyncHtracePluginStartTime_ = std::min(asyncHtracePluginStartTime_, syncTimestamp);
34         asyncHtracePluginEndTime_ = std::max(asyncHtracePluginEndTime_, syncTimestamp);
35     }
36 }
GetPluginStartTime() const37 uint64_t HtracePluginTimeParser::GetPluginStartTime() const
38 {
39     if (syncHtracePluginStartTime_ != std::numeric_limits<uint64_t>::max()) {
40         return syncHtracePluginStartTime_;
41     } else if (asyncHtracePluginStartTime_ != std::numeric_limits<uint64_t>::max()) {
42         return asyncHtracePluginStartTime_;
43     }
44     return std::numeric_limits<uint64_t>::max();
45 }
46 
GetPluginEndTime() const47 uint64_t HtracePluginTimeParser::GetPluginEndTime() const
48 {
49     if (syncHtracePluginEndTime_ != 0) {
50         return syncHtracePluginEndTime_;
51     } else if (asyncHtracePluginEndTime_ != 0) {
52         return asyncHtracePluginEndTime_;
53     }
54     return 0;
55 }
56 } // namespace TraceStreamer
57 } // namespace SysTuning
58