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 #ifndef VSYNC_RES_EVENT_LISTENER_H 17 #define VSYNC_RES_EVENT_LISTENER_H 18 19 #include <cstdint> 20 #include <mutex> 21 22 #include "ffrt.h" 23 #include "res_sched_event_listener.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 class ResschedEventListener : public ResourceSchedule::ResSchedEventListener { 28 public: 29 static sptr<ResschedEventListener> GetInstance() noexcept; 30 void OnReceiveEvent(uint32_t eventType, uint32_t eventValue, 31 std::unordered_map<std::string, std::string> extInfo) override; 32 bool GetIsNeedReport() const; 33 bool GetIsFirstReport() const; 34 void SetIsFirstReport(bool value); 35 void ReportFrameToRSS(); 36 37 void ReportFrameCountAsync(uint32_t rowPid); 38 uint32_t GetCurrentPid(); 39 private: 40 static std::once_flag createFlag_; 41 static sptr<ResschedEventListener> instance_; 42 std::atomic<bool> isNeedReport_ = {false}; 43 std::atomic<bool> isFirstReport_ = {false}; 44 uint64_t lastReportTime_ = 0; 45 std::atomic<uint32_t> currentPid_; 46 uint32_t currentType_; 47 std::chrono::steady_clock::time_point beginTimeStamp_; 48 std::chrono::steady_clock::time_point endTimeStamp_; 49 uint64_t frameCountNum_; 50 bool isFrameRateFirstReport_ = false; 51 static std::mutex ffrtGetQueueMutex_; 52 static std::mutex ffrtGetHighFrequenceQueueMutex_; 53 static std::shared_ptr<ffrt::queue> ffrtQueue_; 54 static std::shared_ptr<ffrt::queue> ffrtHighPriorityQueue_; 55 56 void HandleDrawFrameEventReport(uint32_t eventValue); 57 void HandleFrameRateStatisticsReport(uint32_t eventValue, std::unordered_map<std::string, std::string> extInfo); 58 void HandleFrameRateStatisticsBeginAsync(uint32_t pid, uint32_t type); 59 void HandleFrameRateStatisticsEndAsync(uint32_t pid, uint32_t type); 60 void HandleFrameRateStatisticsBreakAsync(uint32_t pid, uint32_t type); 61 void ReportFrameRateToRSS(const std::unordered_map<std::string, std::string>& mapPayload); 62 static bool GetFfrtQueue(); 63 static bool GetFfrtHighPriorityQueue(); 64 }; 65 } // namespace Rosen 66 } // namespace OHOS 67 #endif