1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2021. 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 #ifndef HOOK_STANDALONE_H
17 #define HOOK_STANDALONE_H
18 
19 #include <string>
20 #include <sstream>
21 #include <set>
22 
23 struct HookData {
24     std::set<std::string> pids = {};
25     uint32_t smbSize {0};
26     uint64_t duration {0};
27     uint32_t filterSize {0};
28     uint32_t maxStackDepth {100};
29     uint32_t maxJsStackdepth = {0};
30     uint32_t statisticsInterval {0};
31     uint32_t sampleInterval {0};
32     int32_t jsStackReport {0};
33     uint32_t mallocFreeMatchingInterval {0};
34     std::string fileName {"/data/local/tmp/data.txt"};
35     std::string processName;
36     std::string performanceFilename {"/data/local/tmp/performance.txt"};
37     std::string filterNapiName = {""};
38     bool mallocDisable {false};
39     bool mmapDisable {false};
40     bool freemsgstack {false};
41     bool munmapmsgstack {false};
42     bool fpUnwind {false};
43     bool offlineSymbolization {false};
44     bool callframeCompress {false};
45     bool stringCompressed {false};
46     bool rawString {false};
47     bool startupMode {false};
48     bool responseLibraryMode {false};
ToStringHookData49     std::string ToString() const
50     {
51         std::stringstream ss;
52         ss << "smbSize:" << smbSize << ", duration:" << duration
53         << ", filterSize:" << filterSize << ", maxStackDepth:" << maxStackDepth
54         << ", statisticsInterval:" << statisticsInterval << ", fileName:" << fileName
55         << ", performanceFilename:" << performanceFilename << ", mallocDisable:" << mallocDisable
56         << ", mmapDisable:" << mmapDisable << ", freemsgstack:" << freemsgstack
57         << ", munmapmsgstack:" << munmapmsgstack << ", fpUnwind:" << fpUnwind
58         << ", offlineSymbolization:" << offlineSymbolization << ", callframeCompress:" << callframeCompress
59         << ", stringCompressed:" << stringCompressed << ", rawString:" << rawString <<", pids:";
60         for (std::string pid: pids) {
61             ss << pid <<' ';
62         }
63         ss << ", processName:" << processName << ' ' <<",startupMode: " << startupMode
64            << ", responseLibraryMode: " << responseLibraryMode << ", sampleInterval: " << sampleInterval
65            << ", jsStackReport: " << jsStackReport << ", maxJsStackdepth: " << maxJsStackdepth
66            <<", filterNapiName" << filterNapiName << "mallocFreeMatchingInterval: " << mallocFreeMatchingInterval;
67         return ss.str();
68     }
69 };
70 
71 namespace OHOS::Developtools::Profiler::Hook {
72 bool StartHook(HookData& hookData);
73 void EndHook();
74 } // namespace OHOS::Developtools::Profiler::Hook
75 
76 #endif // HOOK_STANDALONE_H