• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef NATIVE_MEMORY_PROFILER_SA_CLIENT_MANAGER_H
17 #define NATIVE_MEMORY_PROFILER_SA_CLIENT_MANAGER_H
18 
19 #include "i_native_memory_profiler_sa.h"
20 #include <iservice_registry.h>
21 
22 #include <memory>
23 
24 namespace OHOS::Developtools::NativeDaemon {
25 struct SimplifiedMemStats {
26     size_t size = 0;
27     size_t allocated = 0;
28     size_t nmalloc = 0;
29     size_t ndalloc = 0;
30 };
31 
32 struct SimplifiedMemConfig {
33     size_t largestSize = 0;
34     size_t secondLargestSize = 0;
35     size_t maxGrowthSize = 0;
36     size_t sampleSize = 0;
37 };
38 
39 class NativeMemoryProfilerSaClientManager {
40 public:
41     enum class NativeMemProfilerType : int32_t {
42         MEM_PROFILER_LIBRARY,
43         MEM_PROFILER_CALL_STACK,
44     };
45     static int32_t Start(std::shared_ptr<NativeMemoryProfilerSaConfig>& config);
46     static int32_t Start(NativeMemProfilerType type, uint32_t pid, uint32_t duration, uint32_t sampleIntervel);
47     static int32_t Stop(uint32_t pid);
48     static int32_t Stop(const std::string& name);
49     static int32_t DumpData(uint32_t fd, std::shared_ptr<NativeMemoryProfilerSaConfig>& config);
50     static int32_t GetMallocStats(int fd, int pid, int type, bool printNmdOnly = false);
51     static int32_t StartPrintSimplifiedNmd(pid_t pid, std::vector<SimplifiedMemStats>& memStats);
52     static int32_t Start(int fd, pid_t pid, uint32_t duration, SimplifiedMemConfig& config);
53     static sptr<IRemoteObject> GetRemoteService();
54 
55 private:
56     static bool CheckConfig(const std::shared_ptr<NativeMemoryProfilerSaConfig>& config);
57 };
58 }
59 
60 #endif // NATIVE_MEMORY_PROFILER_SA_CLIENT_MANAGER_H