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