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 // every frame rendered 41 inline static const std::string KEY_RENDER_FRAME_NUMBER = "render_frame_number"; 42 inline static const std::string KEY_RENDER_FRAME_LEN = "render_frame_len"; 43 44 // every 8ms 45 inline static const std::string KEY_CPU_TEMP = "cpu_temp"; 46 inline static const std::string KEY_CPU_LOAD = "cpu_load"; 47 inline static const std::string KEY_CPU_FREQ = "cpu_freq"; 48 inline static const std::string KEY_CPU_CURRENT = "cpu_current"; 49 inline static const std::string KEY_GPU_LOAD = "gpu_load"; 50 inline static const std::string KEY_GPU_FREQ = "gpu_freq"; 51 inline static const std::string KEY_CPU_ID = "cpu_id"; 52 53 RSCaptureData(); 54 ~RSCaptureData(); 55 56 void Reset(); 57 58 void SetTime(float time); 59 60 float GetTime() const; 61 62 void Serialize(class Archive& archive); 63 void Serialize(std::vector<char>& out); 64 void Deserialize(const std::vector<char>& in); 65 66 void SetProperty(const std::string& name, const std::string& value); 67 68 template<typename T> SetProperty(const std::string & name,T value)69 void SetProperty(const std::string& name, T value) 70 { 71 SetProperty(name, std::to_string(value)); 72 } 73 74 const std::string& GetProperty(const std::string& name) const; 75 float GetPropertyFloat(const std::string& name) const; 76 double GetPropertyDouble(const std::string& name) const; 77 int8_t GetPropertyInt8(const std::string& name) const; 78 uint8_t GetPropertyUint8(const std::string& name) const; 79 int16_t GetPropertyInt16(const std::string& name) const; 80 uint16_t GetPropertyUint16(const std::string& name) const; 81 int32_t GetPropertyInt32(const std::string& name) const; 82 uint32_t GetPropertyUint32(const std::string& name) const; 83 int64_t GetPropertyInt64(const std::string& name) const; 84 uint64_t GetPropertyUint64(const std::string& name) const; 85 86 private: 87 float time_ = 0.0f; 88 std::map<std::string, std::string> properties_; 89 }; 90 91 } // namespace OHOS::Rosen 92 93 #endif // RS_PROFILER_CAPTUREDATA_H