1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 "native_memory_profiler_sa_config.h"
17 #include "define_macro.h"
18 #include "logging.h"
19
20 namespace OHOS::Developtools::NativeDaemon {
Marshalling(Parcel & parcel) const21 bool NativeMemoryProfilerSaConfig::Marshalling(Parcel& parcel) const
22 {
23 WRITEINT32(parcel, pid_);
24 WRITESTRING(parcel, filePath_);
25 WRITEUINT32(parcel, duration_);
26 WRITEINT32(parcel, filterSize_);
27 WRITEUINT32(parcel, shareMemorySize_);
28 WRITESTRING(parcel, processName_);
29 WRITEUINT8(parcel, maxStackDepth_);
30 WRITEBOOL(parcel, mallocDisable_);
31 WRITEBOOL(parcel, mmapDisable_);
32 WRITEBOOL(parcel, freeStackData_);
33 WRITEBOOL(parcel, munmapStackData_);
34 WRITEUINT32(parcel, mallocFreeMatchingInterval_);
35 WRITEUINT32(parcel, mallocFreeMatchingCnt_);
36 WRITEBOOL(parcel, stringCompressed_);
37 WRITEBOOL(parcel, fpUnwind_);
38 WRITEBOOL(parcel, blocked_);
39 WRITEBOOL(parcel, recordAccurately_);
40 WRITEBOOL(parcel, startupMode_);
41 WRITEBOOL(parcel, memtraceEnable_);
42 WRITEBOOL(parcel, offlineSymbolization_);
43 WRITEBOOL(parcel, callframeCompress_);
44 WRITEUINT32(parcel, statisticsInterval_);
45 WRITEINT32(parcel, clockId_);
46 WRITEUINT32(parcel, sampleInterval_);
47 WRITEBOOL(parcel, responseLibraryMode_);
48 WRITEBOOL(parcel, printNmd_);
49 WRITEBOOL(parcel, printNmdOnly_);
50 WRITEUINT32(parcel, nmdPid_);
51 WRITEUINT32(parcel, nmdType_);
52 WRITEINT32(parcel, jsStackReport_);
53 WRITEUINT8(parcel, maxJsStackDepth_);
54 WRITESTRING(parcel, filterNapiName_);
55 WRITEUINT32(parcel, largestSize_);
56 WRITEUINT32(parcel, secondLargestSize_);
57 WRITEUINT32(parcel, maxGrowthSize_);
58 return true;
59 }
60
Unmarshalling(Parcel & parcel,std::shared_ptr<NativeMemoryProfilerSaConfig> config)61 bool NativeMemoryProfilerSaConfig::Unmarshalling(Parcel& parcel, std::shared_ptr<NativeMemoryProfilerSaConfig> config)
62 {
63 if (config == nullptr) {
64 return false;
65 }
66 READINT32(parcel, config->pid_);
67 READSTRING(parcel, config->filePath_);
68 READUINT32(parcel, config->duration_);
69 READINT32(parcel, config->filterSize_);
70 READUINT32(parcel, config->shareMemorySize_);
71 READSTRING(parcel, config->processName_);
72 READUINT8(parcel, config->maxStackDepth_);
73 READBOOL(parcel, config->mallocDisable_);
74 READBOOL(parcel, config->mmapDisable_);
75 READBOOL(parcel, config->freeStackData_);
76 READBOOL(parcel, config->munmapStackData_);
77 READUINT32(parcel, config->mallocFreeMatchingInterval_);
78 READUINT32(parcel, config->mallocFreeMatchingCnt_);
79 READBOOL(parcel, config->stringCompressed_);
80 READBOOL(parcel, config->fpUnwind_);
81 READBOOL(parcel, config->blocked_);
82 READBOOL(parcel, config->recordAccurately_);
83 READBOOL(parcel, config->startupMode_);
84 READBOOL(parcel, config->memtraceEnable_);
85 READBOOL(parcel, config->offlineSymbolization_);
86 READBOOL(parcel, config->callframeCompress_);
87 READUINT32(parcel, config->statisticsInterval_);
88 READINT32(parcel, config->clockId_);
89 READUINT32(parcel, config->sampleInterval_);
90 READBOOL(parcel, config->responseLibraryMode_);
91 READBOOL(parcel, config->printNmd_);
92 READBOOL(parcel, config->printNmdOnly_);
93 READUINT32(parcel, config->nmdPid_);
94 READUINT32(parcel, config->nmdType_);
95 READINT32(parcel, config->jsStackReport_);
96 READUINT8(parcel, config->maxJsStackDepth_);
97 READSTRING(parcel, config->filterNapiName_);
98 READUINT32(parcel, config->largestSize_);
99 READUINT32(parcel, config->secondLargestSize_);
100 READUINT32(parcel, config->maxGrowthSize_);
101 PrintConfig(config);
102 return true;
103 }
104
PrintConfig(std::shared_ptr<NativeMemoryProfilerSaConfig> & config)105 void NativeMemoryProfilerSaConfig::PrintConfig(std::shared_ptr<NativeMemoryProfilerSaConfig>& config)
106 {
107 PROFILER_LOG_DEBUG(LOG_CORE,
108 "pid: %d, filePath: %s, duration: %d, filterSize: %d, shareMemorySize: %d, processName: %s",
109 config->pid_, config->filePath_.c_str(), config->duration_, config->filterSize_, config->shareMemorySize_,
110 config->processName_.c_str());
111 PROFILER_LOG_DEBUG(LOG_CORE, "maxStackDepth: %d, mallocDisable: %d, mmapDisable: %d, freeStackData: %d," \
112 "munmapStackData: %d",
113 config->maxStackDepth_, config->mallocDisable_, config->mmapDisable_, config->freeStackData_,
114 config->munmapStackData_);
115 PROFILER_LOG_DEBUG(LOG_CORE, "mallocFreeMatchingInterval: %d, mallocFreeMatchingCnt: %d, stringCompressed: %d," \
116 "fpUnwind: %d, blocked: %d, recordAccurately: %d",
117 config->mallocFreeMatchingInterval_, config->mallocFreeMatchingCnt_, config->stringCompressed_,
118 config->fpUnwind_, config->blocked_, config->recordAccurately_);
119 PROFILER_LOG_DEBUG(LOG_CORE,
120 "startupMode: %d, memtraceEnable: %d, offlineSymbolization: %d, callframeCompress: %d," \
121 "statisticsInterval: %d, clockId: %d",
122 config->startupMode_, config->memtraceEnable_, config->offlineSymbolization_, config->callframeCompress_,
123 config->statisticsInterval_, config->clockId_);
124 PROFILER_LOG_DEBUG(LOG_CORE,
125 "jsStackReport: %d, maxJsStackDepth_: %d, filterNapiName_: %s",
126 config->jsStackReport_, config->maxJsStackDepth_, config->filterNapiName_.c_str());
127 }
128 } // namespace OHOS::Developtools::NativeDaemon