1 /* 2 * Copyright (c) 2024 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 16 #include "gfx/fps_info/rs_surface_fps.h" 17 #include "rs_trace.h" 18 19 namespace OHOS::Rosen { RecordPresentTime(uint64_t timestamp,uint32_t seqNum)20bool RSSurfaceFps::RecordPresentTime(uint64_t timestamp, uint32_t seqNum) 21 { 22 std::unique_lock<std::mutex> lock(mutex_); 23 if (seqNum == presentTimeRecords_[(count_ - 1 + FRAME_RECORDS_NUM) % FRAME_RECORDS_NUM].seqNum) { 24 return false; 25 } 26 RS_TRACE_NAME_FMT("RSSurfaceFps::RecordPresentTime timestamp:%llu", timestamp); 27 presentTimeRecords_[count_].presentTime = timestamp; 28 presentTimeRecords_[count_].seqNum = seqNum; 29 count_ = (count_ + 1) % FRAME_RECORDS_NUM; 30 return true; 31 } 32 Dump(std::string & result)33void RSSurfaceFps::Dump(std::string& result) 34 { 35 std::unique_lock<std::mutex> lock(mutex_); 36 const uint32_t offset = count_; 37 for (uint32_t i = 0; i < FRAME_RECORDS_NUM; i++) { 38 uint32_t order = (offset + FRAME_RECORDS_NUM - i - 1) % FRAME_RECORDS_NUM; 39 result += std::to_string(presentTimeRecords_[order].presentTime) + "\n"; 40 } 41 } 42 ClearDump()43void RSSurfaceFps::ClearDump() 44 { 45 std::unique_lock<std::mutex> lock(mutex_); 46 FPSStat defaultFPSStat = {0, 0}; 47 presentTimeRecords_.fill(defaultFPSStat); 48 } 49 }