1 /*
2  * Copyright (c) 2023 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 TRACE_MEMORY_DUMP_H
17 #define TRACE_MEMORY_DUMP_H
18 
19 #include "impl_interface/trace_memory_dump_impl.h"
20 #include "memory/rs_dfx_string.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
25 class TraceMemoryDump {
26 public:
27     TraceMemoryDump(const char* categoryKey, bool itemizeType);
~TraceMemoryDump()28     ~TraceMemoryDump() {}
29 
30     /**
31      * @brief Appends a new memory dump (i.e. a row) to the trace memory infrastructure.
32      * If dumpName does not exist yet, a new one is created. Otherwise, a new column is appended to
33      * the previously created dump.
34      *
35      * @param dumpName an absolute, slash-separated, name for the item being dumped
36      * e.g., "Drawing/CacheX/EntryY".
37      * @param valueName a string indicating the name of the column.
38      * e.g., "size", "active_size", "number_of_objects".
39      * This string is supposed to be long lived and is NOT copied.
40      * @param units a string indicating the units for the value. e.g., "bytes", "objects".
41      * This string is supposed to be long lived and is NOT copied.
42      * @param value the actual value being dumped.
43      */
44     void DumpNumericValue(const char* dumpName, const char* valueName, const char* units, uint64_t value);
45 
46     void DumpStringValue(const char* dumpName, const char* valueName, const char* value);
47 
48     void LogOutput(OHOS::Rosen::DfxString& log);
49 
50     void LogTotals(OHOS::Rosen::DfxString& log);
51 
52     float GetGpuMemorySizeInMB() const;
53 
54     float GetGLMemorySize() const;
55 
56     template<typename T>
GetImpl()57     T* GetImpl() const
58     {
59         return impl_->DowncastingTo<T>();
60     }
61 private:
62     std::shared_ptr<TraceMemoryDumpImpl> impl_;
63 };
64 }
65 }
66 }
67 #endif // TRACE_MEMORY_DUMP_H