1 /* 2 * Copyright (c) 2021 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 ROSEN_MODULE_FRAME_ANALYZER_EXPORT_FRAME_INFO_H 17 #define ROSEN_MODULE_FRAME_ANALYZER_EXPORT_FRAME_INFO_H 18 19 #include <array> 20 #include <cstdint> 21 #include <map> 22 23 #include "ring_queue.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 /* 28 * Event ids must be continuous, and special 29 * enumerations can be defined after Max. 30 * The ID of the start event must be odd, 31 * and the ID of the end event must be even. 32 */ 33 enum class FrameEventType : int32_t { 34 // UI Event 35 HandleInputStart = 0, 36 HandleInputEnd, 37 AnimateStart, 38 AnimateEnd, 39 BuildStart, 40 BuildEnd, 41 UploadStart, 42 UploadEnd, 43 LayoutStart, 44 LayoutEnd, 45 DrawStart, 46 DrawEnd, 47 48 // RS Event 49 WaitVsyncStart, 50 WaitVsyncEnd, 51 ReleaseStart, 52 ReleaseEnd, 53 FlushStart, 54 FlushEnd, 55 56 // static define 57 Max, 58 59 // ui marks range 60 UIMarksStart = HandleInputStart, 61 UIMarksEnd = DrawEnd + 1, 62 UIMarksLen = UIMarksEnd - UIMarksStart, 63 64 // total range 65 LoopStart = HandleInputStart, 66 LoopEnd = Max, 67 LoopLen = LoopEnd - LoopStart, 68 }; 69 70 /* 71 * Alpha will be determinated by runtime code. 72 * If event doesn't exist, it won't draw. 73 */ 74 static const std::map<FrameEventType, uint32_t> frameEventColorMap = { 75 // FrameEventType::HandleInputStart 76 {FrameEventType::AnimateStart, 0x0000cc00}, // mid green 77 {FrameEventType::BuildStart, 0x0000ffff}, // cyan 78 // FrameEventType::UploadStart 79 {FrameEventType::LayoutStart, 0x0000ff00}, // green 80 {FrameEventType::DrawStart, 0x000000ff}, // blue 81 {FrameEventType::WaitVsyncStart, 0x00006600}, // old green 82 {FrameEventType::ReleaseStart, 0x00ffff00}, // yellow 83 {FrameEventType::FlushStart, 0x00ff0000}, // red 84 }; 85 86 static const std::map<FrameEventType, std::string> frameEventTypeStringMap = { 87 {FrameEventType::HandleInputStart, "HandleInput"}, 88 {FrameEventType::AnimateStart, "Animate"}, 89 {FrameEventType::BuildStart, "Build"}, 90 {FrameEventType::UploadStart, "Upload"}, 91 {FrameEventType::LayoutStart, "Layout"}, 92 {FrameEventType::DrawStart, "Draw"}, 93 {FrameEventType::WaitVsyncStart, "WaitVsync"}, 94 {FrameEventType::ReleaseStart, "Release"}, 95 {FrameEventType::FlushStart, "Flush"}, 96 }; 97 IsStartFrameEventType(int index)98 static inline bool IsStartFrameEventType(int index) 99 { 100 // even is start event, 0x2 for test even 101 return (index % 0x2) == 0; 102 } 103 GetAsyncNameByFrameEventType(int index)104 static inline std::string GetAsyncNameByFrameEventType(int index) 105 { 106 // 0x2 for get event id 107 return std::string("Frame.") + std::to_string(index / 0x2) + "." + 108 frameEventTypeStringMap.at(static_cast<FrameEventType>(index &~ 1)); 109 } 110 GetNameByFrameEventType(FrameEventType type)111 static inline std::string GetNameByFrameEventType(FrameEventType type) 112 { 113 if (IsStartFrameEventType(static_cast<int>(type))) { 114 return frameEventTypeStringMap.at(type) + "Start"; 115 } else { 116 // end type - 1 => start type 117 auto index = static_cast<FrameEventType>(static_cast<int>(type) - 1); 118 return frameEventTypeStringMap.at(index) + "End"; 119 } 120 } 121 122 struct UIMarks { 123 int32_t frameNumber = 0; 124 std::array<int64_t, static_cast<size_t>(FrameEventType::UIMarksLen)> times = {}; 125 }; 126 127 struct FrameInfo { 128 int32_t frameNumber = 0; 129 bool skiped = false; 130 std::array<int64_t, static_cast<size_t>(FrameEventType::LoopLen)> times = {}; 131 }; 132 133 static constexpr int32_t frameQueueMaxSize = 60; 134 static constexpr double frameTotalMs = 160; 135 static constexpr const char *switchRenderingText = "debug.graphic.frame"; 136 static constexpr const char *switchRenderingPaintText = "paint"; 137 static constexpr const char *switchRenderingSaverText = "saver"; 138 static constexpr const char *switchRenderingDisableText = "disable"; 139 static constexpr const char *saveDirectory = "/data/frame_render"; 140 141 using FrameInfoQueue = RingQueue<struct FrameInfo, frameQueueMaxSize>; 142 } // namespace Rosen 143 } // namespace OHOS 144 145 #endif // ROSEN_MODULE_FRAME_ANALYZER_EXPORT_FRAME_INFO_H 146