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