1 /* 2 * Copyright (c) 2023 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 "time_statistician.h" 16 #include "distributed_hardware_log.h" 17 #include "dcamera_utils_tools.h" 18 19 namespace OHOS { 20 namespace DistributedHardware { CalProcessTime(const std::shared_ptr<IFeedableData> & data)21void TimeStatistician::CalProcessTime(const std::shared_ptr<IFeedableData>& data) 22 { 23 int64_t feedTime = GetNowTimeStampUs(); 24 int64_t timeStamp = data->GetTimeStamp(); 25 CalAverFeedInterval(feedTime); 26 CalAverTimeStampInterval(timeStamp); 27 } 28 CalAverFeedInterval(const int64_t feedTime)29void TimeStatistician::CalAverFeedInterval(const int64_t feedTime) 30 { 31 feedTime_ = feedTime; 32 feedInterval_ = feedTime_ - lastFeedTime_; 33 if (lastFeedTime_ == 0) { 34 lastFeedTime_ = feedTime_; 35 return; 36 } 37 feedIndex_++; 38 feedIntervalSum_ += feedInterval_; 39 averFeedInterval_ = feedIntervalSum_ / static_cast<int64_t>(feedIndex_); 40 lastFeedTime_ = feedTime_; 41 } 42 CalAverTimeStampInterval(const int64_t timeStamp)43void TimeStatistician::CalAverTimeStampInterval(const int64_t timeStamp) 44 { 45 timeStamp_ = timeStamp; 46 timeStampInterval_ = timeStamp_ - lastTimeStamp_; 47 if (lastTimeStamp_ == 0) { 48 lastTimeStamp_ = timeStamp_; 49 return; 50 } 51 timeStampIndex_++; 52 timeStampIntervalSum_ += timeStampInterval_; 53 averTimeStampInterval_ = timeStampIntervalSum_ / static_cast<int64_t>(timeStampIndex_); 54 lastTimeStamp_ = timeStamp_; 55 } 56 GetAverFeedInterval()57int64_t TimeStatistician::GetAverFeedInterval() 58 { 59 return averFeedInterval_; 60 } 61 GetAverTimeStampInterval()62int64_t TimeStatistician::GetAverTimeStampInterval() 63 { 64 return averTimeStampInterval_; 65 } 66 GetFeedInterval()67int64_t TimeStatistician::GetFeedInterval() 68 { 69 return feedInterval_; 70 } 71 GetTimeStampInterval()72int64_t TimeStatistician::GetTimeStampInterval() 73 { 74 return timeStampInterval_; 75 } 76 } // namespace DistributedHardware 77 } // namespace OHOS