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 WRITEBOOL(parcel, hookstandalone_);
51 WRITEBOOL(parcel, saveFile_);
52 WRITESTRING(parcel, fileName_);
53 WRITEUINT32(parcel, nmdPid_);
54 WRITEUINT32(parcel, nmdType_);
55 WRITEINT32(parcel, jsStackReport_);
56 WRITEUINT8(parcel, maxJsStackDepth_);
57 WRITESTRING(parcel, filterNapiName_);
58 WRITESTRING(parcel, targetSoName_);
59 WRITEUINT32(parcel, largestSize_);
60 WRITEUINT32(parcel, secondLargestSize_);
61 WRITEUINT32(parcel, maxGrowthSize_);
62 return true;
63 }
64
Unmarshalling(Parcel & parcel,std::shared_ptr<NativeMemoryProfilerSaConfig> config)65 bool NativeMemoryProfilerSaConfig::Unmarshalling(Parcel& parcel, std::shared_ptr<NativeMemoryProfilerSaConfig> config)
66 {
67 if (config == nullptr) {
68 return false;
69 }
70 READINT32(parcel, config->pid_);
71 READSTRING(parcel, config->filePath_);
72 READUINT32(parcel, config->duration_);
73 READINT32(parcel, config->filterSize_);
74 READUINT32(parcel, config->shareMemorySize_);
75 READSTRING(parcel, config->processName_);
76 READUINT8(parcel, config->maxStackDepth_);
77 READBOOL(parcel, config->mallocDisable_);
78 READBOOL(parcel, config->mmapDisable_);
79 READBOOL(parcel, config->freeStackData_);
80 READBOOL(parcel, config->munmapStackData_);
81 READUINT32(parcel, config->mallocFreeMatchingInterval_);
82 READUINT32(parcel, config->mallocFreeMatchingCnt_);
83 READBOOL(parcel, config->stringCompressed_);
84 READBOOL(parcel, config->fpUnwind_);
85 READBOOL(parcel, config->blocked_);
86 READBOOL(parcel, config->recordAccurately_);
87 READBOOL(parcel, config->startupMode_);
88 READBOOL(parcel, config->memtraceEnable_);
89 READBOOL(parcel, config->offlineSymbolization_);
90 READBOOL(parcel, config->callframeCompress_);
91 READUINT32(parcel, config->statisticsInterval_);
92 READINT32(parcel, config->clockId_);
93 READUINT32(parcel, config->sampleInterval_);
94 READBOOL(parcel, config->responseLibraryMode_);
95 READBOOL(parcel, config->printNmd_);
96 READBOOL(parcel, config->printNmdOnly_);
97 READBOOL(parcel, config->hookstandalone_);
98 READBOOL(parcel, config->saveFile_);
99 READSTRING(parcel, config->fileName_);
100 READUINT32(parcel, config->nmdPid_);
101 READUINT32(parcel, config->nmdType_);
102 READINT32(parcel, config->jsStackReport_);
103 READUINT8(parcel, config->maxJsStackDepth_);
104 READSTRING(parcel, config->filterNapiName_);
105 READSTRING(parcel, config->targetSoName_);
106 READUINT32(parcel, config->largestSize_);
107 READUINT32(parcel, config->secondLargestSize_);
108 READUINT32(parcel, config->maxGrowthSize_);
109 PrintConfig(config);
110 return true;
111 }
112
PrintConfig(std::shared_ptr<NativeMemoryProfilerSaConfig> & config)113 void NativeMemoryProfilerSaConfig::PrintConfig(std::shared_ptr<NativeMemoryProfilerSaConfig>& config)
114 {
115 PROFILER_LOG_DEBUG(LOG_CORE,
116 "pid: %d, filePath: %s, duration: %d, filterSize: %d, shareMemorySize: %d, processName: %s",
117 config->pid_, config->filePath_.c_str(), config->duration_, config->filterSize_, config->shareMemorySize_,
118 config->processName_.c_str());
119 PROFILER_LOG_DEBUG(LOG_CORE, "maxStackDepth: %d, mallocDisable: %d, mmapDisable: %d, freeStackData: %d," \
120 "munmapStackData: %d",
121 config->maxStackDepth_, config->mallocDisable_, config->mmapDisable_, config->freeStackData_,
122 config->munmapStackData_);
123 PROFILER_LOG_DEBUG(LOG_CORE, "mallocFreeMatchingInterval: %d, mallocFreeMatchingCnt: %d, stringCompressed: %d," \
124 "fpUnwind: %d, blocked: %d, recordAccurately: %d",
125 config->mallocFreeMatchingInterval_, config->mallocFreeMatchingCnt_, config->stringCompressed_,
126 config->fpUnwind_, config->blocked_, config->recordAccurately_);
127 PROFILER_LOG_DEBUG(LOG_CORE,
128 "startupMode: %d, memtraceEnable: %d, offlineSymbolization: %d, callframeCompress: %d," \
129 "statisticsInterval: %d, clockId: %d, targetSoName: %s",
130 config->startupMode_, config->memtraceEnable_, config->offlineSymbolization_, config->callframeCompress_,
131 config->statisticsInterval_, config->clockId_, config->targetSoName_.c_str());
132 PROFILER_LOG_DEBUG(LOG_CORE,
133 "jsStackReport: %d, maxJsStackDepth_: %d, filterNapiName_: %s",
134 config->jsStackReport_, config->maxJsStackDepth_, config->filterNapiName_.c_str());
135 }
136 } // namespace OHOS::Developtools::NativeDaemon