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 #include "skia_trace_memory_dump.h"
17 #include "utils/log.h"
18
19 namespace OHOS {
20 namespace Rosen {
21 namespace Drawing {
SkiaTraceMemoryDump(const char * categoryKey,bool itemizeType)22 SkiaTraceMemoryDump::SkiaTraceMemoryDump(const char* categoryKey, bool itemizeType)
23 : TraceMemoryDumpImpl(categoryKey, itemizeType),
24 skiaMemoryTrace_(std::make_shared<SkiaMemoryTracer>(categoryKey, itemizeType)) {}
25
DumpNumericValue(const char * dumpName,const char * valueName,const char * units,uint64_t value)26 void SkiaTraceMemoryDump::DumpNumericValue(const char* dumpName,
27 const char* valueName, const char* units, uint64_t value)
28 {
29 if (skiaMemoryTrace_ == nullptr) {
30 LOGD("SkiaTraceMemoryDump::DumpNumericValue, skiaMemoryTrace_ is nullptr");
31 return;
32 }
33
34 skiaMemoryTrace_->dumpNumericValue(dumpName, valueName, units, value);
35 }
36
DumpStringValue(const char * dumpName,const char * valueName,const char * value)37 void SkiaTraceMemoryDump::DumpStringValue(const char* dumpName, const char* valueName, const char* value)
38 {
39 if (skiaMemoryTrace_ == nullptr) {
40 LOGD("SkiaTraceMemoryDump::DumpStringValue, skiaMemoryTrace_ is nullptr");
41 return;
42 }
43
44 skiaMemoryTrace_->dumpStringValue(dumpName, valueName, value);
45 }
46
LogOutput(OHOS::Rosen::DfxString & log)47 void SkiaTraceMemoryDump::LogOutput(OHOS::Rosen::DfxString& log)
48 {
49 if (skiaMemoryTrace_ == nullptr) {
50 LOGD("SkiaTraceMemoryDump::LogOutput, skiaMemoryTrace_ is nullptr");
51 return;
52 }
53
54 skiaMemoryTrace_->LogOutput(log);
55 }
56
LogTotals(OHOS::Rosen::DfxString & log)57 void SkiaTraceMemoryDump::LogTotals(OHOS::Rosen::DfxString& log)
58 {
59 if (skiaMemoryTrace_ == nullptr) {
60 LOGD("SkiaTraceMemoryDump::LogTotals, skiaMemoryTrace_ is nullptr");
61 return;
62 }
63
64 skiaMemoryTrace_->LogTotals(log);
65 }
66
GetGpuMemorySizeInMB() const67 float SkiaTraceMemoryDump::GetGpuMemorySizeInMB() const
68 {
69 if (skiaMemoryTrace_ == nullptr) {
70 LOGD("SkiaTraceMemoryDump::GetGpuMemorySizeInMB, skiaMemoryTrace_ is nullptr");
71 return 0.0f;
72 }
73
74 return skiaMemoryTrace_->GetGpuMemorySizeInMB();
75 }
76
GetGLMemorySize() const77 float SkiaTraceMemoryDump::GetGLMemorySize() const
78 {
79 if (skiaMemoryTrace_ == nullptr) {
80 LOGD("SkiaTraceMemoryDump::GetGLMemorySize, skiaMemoryTrace_ is nullptr");
81 return 0.0f;
82 }
83
84 return skiaMemoryTrace_->GetGLMemorySize();
85 }
86
GetTraceMemoryDump() const87 std::shared_ptr<SkiaMemoryTracer> SkiaTraceMemoryDump::GetTraceMemoryDump() const
88 {
89 return skiaMemoryTrace_;
90 }
91 }
92 }
93 }