1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_FRAME_INFO_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_FRAME_INFO_H 18 19 #include <string> 20 #include <vector> 21 22 namespace OHOS::Ace { 23 24 struct TaskInfo { 25 std::string tag_; 26 int32_t id_ = -1; 27 uint64_t time_ = 0; 28 ToStringTaskInfo29 const std::string ToString() const 30 { 31 std::string info; 32 info.append(tag_); 33 info.append("("); 34 info.append(std::to_string(id_)); 35 info.append("), \ttime cost: "); 36 info.append(std::to_string(time_)); 37 return info; 38 } 39 }; 40 41 struct FrameInfo { 42 enum class TaskType { LAYOUT, RENDER }; 43 44 uint64_t frameRecvTime_ = 0; 45 uint64_t frameTimeStamp_ = 0; 46 std::vector<TaskInfo> layoutInfos_; 47 std::vector<TaskInfo> renderInfos_; 48 AddTaskInfoFrameInfo49 void AddTaskInfo(const std::string& tag, const int32_t id, uint64_t time, TaskType type) 50 { 51 switch (type) { 52 case TaskType::LAYOUT: 53 layoutInfos_.push_back({ tag, id, time}); 54 break; 55 case TaskType::RENDER: 56 renderInfos_.push_back({ tag, id, time}); 57 break; 58 } 59 } 60 GetTimeInfoFrameInfo61 const std::string GetTimeInfo() const 62 { 63 std::string info; 64 info.append("VsyncTimeStamp: "); 65 info.append(std::to_string(frameTimeStamp_)); 66 info.append("\t"); 67 info.append("recvTime: "); 68 info.append(std::to_string(frameRecvTime_)); 69 return info; 70 } 71 }; 72 } // namespace OHOS::Ace 73 74 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_FRAME_INFO_H 75