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 RS_PROFILER_CAPTUREDATA_H 17 #define RS_PROFILER_CAPTUREDATA_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS::Rosen { 24 25 class RSCaptureData final { 26 public: 27 // every rs update 28 inline static const std::string KEY_RS_FRAME_NUMBER = "rs_frame_number"; 29 inline static const std::string KEY_RS_SYNC_TIME = "rs_sync_time"; 30 inline static const std::string KEY_RS_FRAME_LEN = "rs_frame_len"; 31 inline static const std::string KEY_RS_CMD_COUNT = "rs_cmd_count"; 32 inline static const std::string KEY_RS_CMD_EXECUTE_COUNT = "rs_cmd_execute_count"; 33 inline static const std::string KEY_RS_PARCEL_CMD_LIST = "rs_parcel_cmd_list"; 34 inline static const std::string KEY_RS_PIXEL_IMAGE_ADDED = "rs_pixelimage_added"; 35 inline static const std::string KEY_RS_DIRTY_REGION = "rs_dirty_region"; 36 inline static const std::string KEY_RS_DIRTY_REGION_LIST = "rs_dirty_region_list"; 37 inline static const std::string KEY_RS_CPU_ID = "rs_cpu_id"; 38 inline static const std::string KEY_RS_VSYNC_ID = "rs_vsync_id"; 39 40 // events 41 inline static const std::string KEY_EVENT_TYPE = "evt_type"; // event type 42 43 inline static const std::string VAL_EVENT_TYPE_VSYNC = "val_vsync"; 44 inline static const std::string VAL_EVENT_TYPE_MSGERR = "val_msgerr"; 45 inline static const std::string VAL_EVENT_TYPE_MSGWARN = "val_msgwarn"; 46 inline static const std::string VAL_EVENT_TYPE_PIXELMAP = "val_pixelmap"; 47 inline static const std::string VAL_EVENT_TYPE_INFO = "val_info"; 48 inline static const std::string VAL_EVENT_TYPE_PARCEL_UNMARSHALLING_START = "val_pustart"; 49 inline static const std::string VAL_EVENT_TYPE_PARCEL_UNMARSHALLING_END = "val_puend"; 50 inline static const std::string VAL_EVENT_TYPE_DEBUG = "val_debug"; 51 inline static const std::string VAL_EVENT_TYPE_PIXELMAP_YUV = "val_pixelmap_uv"; 52 53 inline static const std::string KEY_EVENT_MSG = "evt_msg"; // event param 54 55 // every frame rendered 56 inline static const std::string KEY_RENDER_FRAME_NUMBER = "render_frame_number"; 57 inline static const std::string KEY_RENDER_FRAME_LEN = "render_frame_len"; 58 59 // every 8ms 60 inline static const std::string KEY_CPU_TEMP = "cpu_temp"; 61 inline static const std::string KEY_CPU_LOAD = "cpu_load"; 62 inline static const std::string KEY_CPU_FREQ = "cpu_freq"; 63 inline static const std::string KEY_CPU_CURRENT = "cpu_current"; 64 inline static const std::string KEY_GPU_LOAD = "gpu_load"; 65 inline static const std::string KEY_GPU_FREQ = "gpu_freq"; 66 inline static const std::string KEY_CPU_ID = "cpu_id"; 67 68 RSCaptureData(); 69 ~RSCaptureData(); 70 71 void Reset(); 72 73 void SetTime(float time); 74 75 float GetTime() const; 76 77 void Serialize(class Archive& archive); 78 void Serialize(std::vector<char>& out); 79 void Deserialize(const std::vector<char>& in); 80 81 void SetProperty(const std::string& name, const std::string& value); 82 83 template<typename T> SetProperty(const std::string & name,T value)84 void SetProperty(const std::string& name, T value) 85 { 86 SetProperty(name, std::to_string(value)); 87 } 88 89 const std::string& GetProperty(const std::string& name) const; 90 float GetPropertyFloat(const std::string& name) const; 91 double GetPropertyDouble(const std::string& name) const; 92 int8_t GetPropertyInt8(const std::string& name) const; 93 uint8_t GetPropertyUint8(const std::string& name) const; 94 int16_t GetPropertyInt16(const std::string& name) const; 95 uint16_t GetPropertyUint16(const std::string& name) const; 96 int32_t GetPropertyInt32(const std::string& name) const; 97 uint32_t GetPropertyUint32(const std::string& name) const; 98 int64_t GetPropertyInt64(const std::string& name) const; 99 uint64_t GetPropertyUint64(const std::string& name) const; 100 101 private: 102 float time_ = 0.0f; 103 std::map<std::string, std::string> properties_; 104 }; 105 106 } // namespace OHOS::Rosen 107 108 #endif // RS_PROFILER_CAPTUREDATA_H