1 /* 2 * Copyright (c) 2023-2025 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 #ifndef INTERFACES_INNER_API_UNIFIED_COLLECTION_UTILITY_MEM_PROFILER_COLLECTOR_H 16 #define INTERFACES_INNER_API_UNIFIED_COLLECTION_UTILITY_MEM_PROFILER_COLLECTOR_H 17 #include <memory> 18 19 #include "collect_result.h" 20 #include "native_memory_profiler_sa_client_manager.h" 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 namespace UCollectUtil { 25 using ProfilerType = Developtools::NativeDaemon::NativeMemoryProfilerSaClientManager::NativeMemProfilerType; 26 27 struct MemoryProfilerConfig { 28 ProfilerType type; 29 int pid = 0; 30 int duration = 0; 31 int sampleInterval = 0; 32 std::string processName; 33 }; 34 35 struct SimplifiedMemStats { 36 size_t size = 0; 37 size_t allocated = 0; 38 size_t nmalloc = 0; 39 size_t ndalloc = 0; 40 }; 41 42 struct SimplifiedMemConfig { 43 size_t largestSize = 0; 44 size_t secondLargestSize = 0; 45 size_t maxGrowthSize = 0; 46 size_t sampleSize = 0; 47 }; 48 49 class MemProfilerCollector { 50 public: 51 MemProfilerCollector() = default; 52 virtual ~MemProfilerCollector() = default; 53 54 public: 55 virtual int Start(const MemoryProfilerConfig& memoryProfilerConfig) = 0; 56 virtual int StartPrintNmd(int fd, int pid, int type) = 0; 57 virtual int Stop(int pid) = 0; 58 virtual int Stop(const std::string& processName) = 0; 59 virtual int Start(int fd, const MemoryProfilerConfig& memoryProfilerConfig) = 0; 60 virtual int Start(int fd, bool startup, const MemoryProfilerConfig& memoryProfilerConfig) = 0; 61 virtual int Prepare() = 0; 62 virtual int Start(int fd, pid_t pid, uint32_t duration, const SimplifiedMemConfig& config) = 0; 63 virtual int StartPrintSimplifiedNmd(pid_t pid, std::vector<SimplifiedMemStats>& memStats) = 0; 64 static std::shared_ptr<MemProfilerCollector> Create(); 65 }; // MemProfilerCollector 66 } // UCollectUtil 67 } // HiviewDFX 68 } // OHOS 69 #endif // INTERFACES_INNER_API_UNIFIED_COLLECTION_UTILITY_MEM_PROFILER_COLLECTOR_H