From 2e0bb86ea31531b287cb24871776c9d9efc906dc Mon Sep 17 00:00:00 2001 From: wang2002xu Date: Wed, 18 May 2022 10:32:36 +0800 Subject: [PATCH] feat: add memory tracker HDI Signed-off-by: wang2002xu --- memory_tracker/bundle.json | 39 +++++++++++++ memory_tracker/v1_0/BUILD.gn | 24 ++++++++ .../v1_0/IMemoryTrackerInterface.idl | 34 +++++++++++ memory_tracker/v1_0/MemoryTrackerTypes.idl | 58 +++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 memory_tracker/bundle.json create mode 100644 memory_tracker/v1_0/BUILD.gn create mode 100644 memory_tracker/v1_0/IMemoryTrackerInterface.idl create mode 100644 memory_tracker/v1_0/MemoryTrackerTypes.idl diff --git a/memory_tracker/bundle.json b/memory_tracker/bundle.json new file mode 100644 index 00000000..ffe465d5 --- /dev/null +++ b/memory_tracker/bundle.json @@ -0,0 +1,39 @@ +{ + "name": "memorytracker_device_driver_interface", + "description": "memorytracker_hdf", + "version": "3.1", + "license": "Apache License 2.0", + "component": { + "name": "memorytracker_device_driver_interface", + "subsystem": "hdf", + "syscap": [""], + "adapter_system_type": ["standard"], + "rom": "45KB", + "ram": "100KB", + "deps": { + "components": [ + "ipc", + "device_driver_framework", + "hiviewdfx_hilog_native", + "utils_base" + ], + "third_part": [] + }, + "build": { + "sub_component": [ + "//drivers/interface/memory_tracker/v1_0:libmemorytracker_proxy_1.0" + ], + "test": [], + "inner_kits": [ + { + "name": "//drivers/interface/memory_tracker/v1_0:libmemorytracker_proxy_1.0", + "header": { + "header_files": [ + ], + "header_base": "//drivers/interface/memory_tracker" + } + } + ] + } + } + } \ No newline at end of file diff --git a/memory_tracker/v1_0/BUILD.gn b/memory_tracker/v1_0/BUILD.gn new file mode 100644 index 00000000..333fd694 --- /dev/null +++ b/memory_tracker/v1_0/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//drivers/adapter/uhdf2/hdi.gni") +hdi("memorytracker") { + module_name = "memory_tracker_interface_service" + sources = [ + "IMemoryTrackerInterface.idl", + "MemoryTrackerTypes.idl", + ] + language = "cpp" + subsystem_name = "hdf" + part_name = "memorytracker_device_driver" +} diff --git a/memory_tracker/v1_0/IMemoryTrackerInterface.idl b/memory_tracker/v1_0/IMemoryTrackerInterface.idl new file mode 100644 index 00000000..126776cc --- /dev/null +++ b/memory_tracker/v1_0/IMemoryTrackerInterface.idl @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.memory_tracker.v1_0; + +import ohos.hdi.memory_tracker.v1_0.MemoryTrackerTypes; + +interface IMemoryTrackerInterface { + /** + * @brief Get the memory record with specified type. + * + * @param pid Indicates the process id. If pid equals to 0, it means to get memory records of all processes. + * @param type Indicates type of device. + * @param records Indicates the list of memory record. + * + * @return Returns 0 if the operation is successful. + * @return Returns a negative value if the operation fails. + * + * @since 3.2 + */ + GetDevMem([in] int pid, [in] enum MemoryTrackerType type, [out] struct MemoryRecord[] records); +} \ No newline at end of file diff --git a/memory_tracker/v1_0/MemoryTrackerTypes.idl b/memory_tracker/v1_0/MemoryTrackerTypes.idl new file mode 100644 index 00000000..a8c774f0 --- /dev/null +++ b/memory_tracker/v1_0/MemoryTrackerTypes.idl @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.memory_tracker.v1_0; + +enum MemoryTrackerType { + /* muti-media related */ + MEMORY_TRACKER_TYPE_MM = 0, + /* GL related */ + MEMORY_TRACKER_TYPE_GL = 1, + /* camera related */ + MEMORY_TRACKER_TYPE_CAM = 2, + /* graphic related */ + MEMORY_TRACKER_TYPE_GRAPH = 3, + MEMORY_TRACKER_TYPE_OTHER = 4, + MEMORY_TRACKER_TYPE_COUNTS, +}; + +enum MemoryTrackerFlag { + /* memory shared with other processes */ + FLAG_SHARED_RSS = 2, + /* FLAG_SHARED_RSS / counts of shared processes */ + FLAG_SHARED_PSS = 4, + /* contrary to FLAG_SHARED_RSS */ + FLAG_PRIVATE = 8, + /* memory mapped in smaps */ + FLAG_MAPPED = 16, + /* contrary to FLAG_MAPPED */ + FLAG_UNMAPPED = 32, + /* CPU secure mode related */ + FLAG_PROTECTED = 64, + /* contrary to FLAG_PROTECTED */ + FLAG_UNPROTECTED = 128, + /* managed by system */ + FLAG_SYSTEM = 256, + /* contrary to FLAG_SYSTEM */ + FLAG_SYSTEM_EXCEPT = 512, + +}; + +struct MemoryRecord { + /* MemoryTracker Flags */ + int flags; + /* in Bytes */ + long size; +}; -- Gitee