Merge "Memtrack HAL: Add stable AIDL implementation" am: e5d68ba29c
am: be07fd2de6
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1518666 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I9c17a00485554becde5863be2b6cb0a0d337b850
This commit is contained in:
commit
8f356a5035
18 changed files with 597 additions and 0 deletions
|
@ -334,6 +334,13 @@
|
||||||
<instance>default</instance>
|
<instance>default</instance>
|
||||||
</interface>
|
</interface>
|
||||||
</hal>
|
</hal>
|
||||||
|
<hal format="aidl" optional="true">
|
||||||
|
<name>android.hardware.memtrack</name>
|
||||||
|
<interface>
|
||||||
|
<name>IMemtrack</name>
|
||||||
|
<instance>default</instance>
|
||||||
|
</interface>
|
||||||
|
</hal>
|
||||||
<hal format="hidl" optional="true">
|
<hal format="hidl" optional="true">
|
||||||
<name>android.hardware.memtrack</name>
|
<name>android.hardware.memtrack</name>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
|
|
33
memtrack/aidl/Android.bp
Normal file
33
memtrack/aidl/Android.bp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2020 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
aidl_interface {
|
||||||
|
name: "android.hardware.memtrack",
|
||||||
|
vendor_available: true,
|
||||||
|
srcs: ["android/hardware/memtrack/*.aidl"],
|
||||||
|
stability: "vintf",
|
||||||
|
backend: {
|
||||||
|
cpp: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
java: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
ndk: {
|
||||||
|
vndk: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
|
||||||
|
// edit this file. It looks like you are doing that because you have modified
|
||||||
|
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
|
||||||
|
// from an interface or a field from a parcelable and it broke the build. That
|
||||||
|
// breakage is intended.
|
||||||
|
//
|
||||||
|
// You must not make a backward incompatible changes to the AIDL files built
|
||||||
|
// with the aidl_interface module type with versions property set. The module
|
||||||
|
// type is used to build AIDL files in a way that they can be used across
|
||||||
|
// independently updatable components of the system. If a device is shipped
|
||||||
|
// with such a backward incompatible change, it has a high risk of breaking
|
||||||
|
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||||
|
|
||||||
|
package android.hardware.memtrack;
|
||||||
|
@VintfStability
|
||||||
|
parcelable DeviceInfo {
|
||||||
|
int id;
|
||||||
|
@utf8InCpp String name;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
|
||||||
|
// edit this file. It looks like you are doing that because you have modified
|
||||||
|
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
|
||||||
|
// from an interface or a field from a parcelable and it broke the build. That
|
||||||
|
// breakage is intended.
|
||||||
|
//
|
||||||
|
// You must not make a backward incompatible changes to the AIDL files built
|
||||||
|
// with the aidl_interface module type with versions property set. The module
|
||||||
|
// type is used to build AIDL files in a way that they can be used across
|
||||||
|
// independently updatable components of the system. If a device is shipped
|
||||||
|
// with such a backward incompatible change, it has a high risk of breaking
|
||||||
|
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||||
|
|
||||||
|
package android.hardware.memtrack;
|
||||||
|
@VintfStability
|
||||||
|
interface IMemtrack {
|
||||||
|
android.hardware.memtrack.MemtrackRecord[] getMemory(in int pid, in android.hardware.memtrack.MemtrackType type);
|
||||||
|
android.hardware.memtrack.DeviceInfo[] getGpuDeviceInfo();
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
|
||||||
|
// edit this file. It looks like you are doing that because you have modified
|
||||||
|
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
|
||||||
|
// from an interface or a field from a parcelable and it broke the build. That
|
||||||
|
// breakage is intended.
|
||||||
|
//
|
||||||
|
// You must not make a backward incompatible changes to the AIDL files built
|
||||||
|
// with the aidl_interface module type with versions property set. The module
|
||||||
|
// type is used to build AIDL files in a way that they can be used across
|
||||||
|
// independently updatable components of the system. If a device is shipped
|
||||||
|
// with such a backward incompatible change, it has a high risk of breaking
|
||||||
|
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||||
|
|
||||||
|
package android.hardware.memtrack;
|
||||||
|
@VintfStability
|
||||||
|
parcelable MemtrackRecord {
|
||||||
|
int flags;
|
||||||
|
long sizeInBytes;
|
||||||
|
const int FLAG_SMAPS_ACCOUNTED = 2;
|
||||||
|
const int FLAG_SMAPS_UNACCOUNTED = 4;
|
||||||
|
const int FLAG_SHARED = 8;
|
||||||
|
const int FLAG_SHARED_PSS = 16;
|
||||||
|
const int FLAG_PRIVATE = 32;
|
||||||
|
const int FLAG_SYSTEM = 64;
|
||||||
|
const int FLAG_DEDICATED = 128;
|
||||||
|
const int FLAG_NONSECURE = 256;
|
||||||
|
const int FLAG_SECURE = 512;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
|
||||||
|
// edit this file. It looks like you are doing that because you have modified
|
||||||
|
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
|
||||||
|
// from an interface or a field from a parcelable and it broke the build. That
|
||||||
|
// breakage is intended.
|
||||||
|
//
|
||||||
|
// You must not make a backward incompatible changes to the AIDL files built
|
||||||
|
// with the aidl_interface module type with versions property set. The module
|
||||||
|
// type is used to build AIDL files in a way that they can be used across
|
||||||
|
// independently updatable components of the system. If a device is shipped
|
||||||
|
// with such a backward incompatible change, it has a high risk of breaking
|
||||||
|
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||||
|
|
||||||
|
package android.hardware.memtrack;
|
||||||
|
@Backing(type="int") @VintfStability
|
||||||
|
enum MemtrackType {
|
||||||
|
OTHER = 0,
|
||||||
|
GL = 1,
|
||||||
|
GRAPHICS = 2,
|
||||||
|
MULTIMEDIA = 3,
|
||||||
|
CAMERA = 4,
|
||||||
|
NUM_TYPES = 5,
|
||||||
|
}
|
29
memtrack/aidl/android/hardware/memtrack/DeviceInfo.aidl
Normal file
29
memtrack/aidl/android/hardware/memtrack/DeviceInfo.aidl
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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 android.hardware.memtrack;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A vector of DeviceInfo is returned by the function getGpuDeviceInfo().
|
||||||
|
* Each entry consists of the device name and the device id.
|
||||||
|
* See getGpuDeviceInfo() for further details.
|
||||||
|
*/
|
||||||
|
@VintfStability
|
||||||
|
parcelable DeviceInfo {
|
||||||
|
int id;
|
||||||
|
@utf8InCpp String name;
|
||||||
|
}
|
||||||
|
|
82
memtrack/aidl/android/hardware/memtrack/IMemtrack.aidl
Normal file
82
memtrack/aidl/android/hardware/memtrack/IMemtrack.aidl
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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 android.hardware.memtrack;
|
||||||
|
|
||||||
|
import android.hardware.memtrack.DeviceInfo;
|
||||||
|
import android.hardware.memtrack.MemtrackRecord;
|
||||||
|
import android.hardware.memtrack.MemtrackType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Memory Tracker HAL is designed to return information about
|
||||||
|
* device-specific memory usage.
|
||||||
|
* The primary goal is to be able to track memory that is not
|
||||||
|
* trackable in any other way, for example texture memory that is allocated by
|
||||||
|
* a process, but not mapped in to that process's address space.
|
||||||
|
* A secondary goal is to be able to categorize memory used by a process into
|
||||||
|
* GL, graphics, etc. All memory sizes must be in real memory usage,
|
||||||
|
* accounting for stride, bit depth, rounding up to page size, etc.
|
||||||
|
*
|
||||||
|
* Constructor for the interface should be used to perform memtrack management
|
||||||
|
* setup actions and is called once before any calls to getMemory().
|
||||||
|
*/
|
||||||
|
@VintfStability
|
||||||
|
interface IMemtrack {
|
||||||
|
/**
|
||||||
|
* getMemory() populates MemtrackRecord vector with the sizes of memory
|
||||||
|
* plus associated flags for that memory.
|
||||||
|
*
|
||||||
|
* A process collecting memory statistics will call getMemory for each
|
||||||
|
* combination of pid and memory type. For each memory type that it
|
||||||
|
* recognizes, the HAL must fill out an array of memtrack_record
|
||||||
|
* structures breaking down the statistics of that memory type as much as
|
||||||
|
* possible. For example,
|
||||||
|
* getMemory(<pid>, GL) might return:
|
||||||
|
* { { 4096, ACCOUNTED | PRIVATE | SYSTEM },
|
||||||
|
* { 40960, UNACCOUNTED | PRIVATE | SYSTEM },
|
||||||
|
* { 8192, ACCOUNTED | PRIVATE | DEDICATED },
|
||||||
|
* { 8192, UNACCOUNTED | PRIVATE | DEDICATED } }
|
||||||
|
* If the HAL cannot differentiate between SYSTEM and DEDICATED memory, it
|
||||||
|
* could return:
|
||||||
|
* { { 12288, ACCOUNTED | PRIVATE },
|
||||||
|
* { 49152, UNACCOUNTED | PRIVATE } }
|
||||||
|
*
|
||||||
|
* Memory must not overlap between types. For example, a graphics buffer
|
||||||
|
* that has been mapped into the GPU as a surface must show up when
|
||||||
|
* GRAPHICS is requested and not when GL
|
||||||
|
* is requested.
|
||||||
|
*
|
||||||
|
* @param pid process for which memory information is requested
|
||||||
|
* @param type memory type that information is being requested about
|
||||||
|
* @return vector of MemtrackRecord containing memory information
|
||||||
|
*/
|
||||||
|
MemtrackRecord[] getMemory(in int pid, in MemtrackType type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getGpuDeviceInfo() populates DeviceInfo with the ID and name
|
||||||
|
* of each GPU device.
|
||||||
|
*
|
||||||
|
* For example, getGpuDeviceInfor, might return:
|
||||||
|
* { { 0, <gpu-device-name> },
|
||||||
|
* { 1, <gpu-device-name> } }
|
||||||
|
*
|
||||||
|
* This information is used to identify GPU devices for GPU specific
|
||||||
|
* memory accounting (e.g. DMA buffer usage).
|
||||||
|
*
|
||||||
|
* @return vector of DeviceInfo populated for all GPU devices.
|
||||||
|
*/
|
||||||
|
DeviceInfo[] getGpuDeviceInfo();
|
||||||
|
}
|
43
memtrack/aidl/android/hardware/memtrack/MemtrackRecord.aidl
Normal file
43
memtrack/aidl/android/hardware/memtrack/MemtrackRecord.aidl
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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 android.hardware.memtrack;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A vector of MemtrackRecord is returned by the function getMemory().
|
||||||
|
* Each record consists of the size of the memory used by the process and
|
||||||
|
* flags indicate all the MemtrackFlags that are valid for this record.
|
||||||
|
* see getMemory() comments for further details.
|
||||||
|
*/
|
||||||
|
@VintfStability
|
||||||
|
parcelable MemtrackRecord {
|
||||||
|
/* Memtrack Flags */
|
||||||
|
const int FLAG_SMAPS_ACCOUNTED = 1 << 1;
|
||||||
|
const int FLAG_SMAPS_UNACCOUNTED = 1 << 2;
|
||||||
|
const int FLAG_SHARED = 1 << 3;
|
||||||
|
const int FLAG_SHARED_PSS = 1 << 4;
|
||||||
|
const int FLAG_PRIVATE = 1 << 5;
|
||||||
|
const int FLAG_SYSTEM = 1 << 6;
|
||||||
|
const int FLAG_DEDICATED = 1 << 7;
|
||||||
|
const int FLAG_NONSECURE = 1 << 8;
|
||||||
|
const int FLAG_SECURE = 1 << 9;
|
||||||
|
|
||||||
|
/* Bitfield indicating all flags that are valid for this record */
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
long sizeInBytes;
|
||||||
|
}
|
||||||
|
|
31
memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl
Normal file
31
memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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 android.hardware.memtrack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags which define the usage of the memory buffers.
|
||||||
|
*/
|
||||||
|
@VintfStability
|
||||||
|
@Backing(type="int")
|
||||||
|
enum MemtrackType {
|
||||||
|
OTHER = 0,
|
||||||
|
GL = 1,
|
||||||
|
GRAPHICS = 2,
|
||||||
|
MULTIMEDIA = 3,
|
||||||
|
CAMERA = 4,
|
||||||
|
NUM_TYPES,
|
||||||
|
}
|
30
memtrack/aidl/default/Android.bp
Normal file
30
memtrack/aidl/default/Android.bp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (C) 2020 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
cc_binary {
|
||||||
|
name: "android.hardware.memtrack-service.example",
|
||||||
|
relative_install_path: "hw",
|
||||||
|
init_rc: ["memtrack-default.rc"],
|
||||||
|
vintf_fragments: ["memtrack-default.xml"],
|
||||||
|
vendor: true,
|
||||||
|
shared_libs: [
|
||||||
|
"libbase",
|
||||||
|
"libbinder_ndk",
|
||||||
|
"android.hardware.memtrack-ndk_platform",
|
||||||
|
],
|
||||||
|
srcs: [
|
||||||
|
"main.cpp",
|
||||||
|
"Memtrack.cpp",
|
||||||
|
],
|
||||||
|
}
|
44
memtrack/aidl/default/Memtrack.cpp
Normal file
44
memtrack/aidl/default/Memtrack.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Memtrack.h"
|
||||||
|
|
||||||
|
namespace aidl {
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace memtrack {
|
||||||
|
|
||||||
|
ndk::ScopedAStatus Memtrack::getMemory(int pid, MemtrackType type,
|
||||||
|
std::vector<MemtrackRecord>* _aidl_return) {
|
||||||
|
if (pid < 0) {
|
||||||
|
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
|
||||||
|
}
|
||||||
|
if (type < MemtrackType::OTHER || type >= MemtrackType::NUM_TYPES) {
|
||||||
|
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||||
|
}
|
||||||
|
_aidl_return->clear();
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus Memtrack::getGpuDeviceInfo(std::vector<DeviceInfo>* _aidl_return) {
|
||||||
|
_aidl_return->clear();
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace memtrack
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
||||||
|
} // namespace aidl
|
39
memtrack/aidl/default/Memtrack.h
Normal file
39
memtrack/aidl/default/Memtrack.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <aidl/android/hardware/memtrack/BnMemtrack.h>
|
||||||
|
#include <aidl/android/hardware/memtrack/DeviceInfo.h>
|
||||||
|
#include <aidl/android/hardware/memtrack/MemtrackRecord.h>
|
||||||
|
#include <aidl/android/hardware/memtrack/MemtrackType.h>
|
||||||
|
|
||||||
|
namespace aidl {
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace memtrack {
|
||||||
|
|
||||||
|
class Memtrack : public BnMemtrack {
|
||||||
|
ndk::ScopedAStatus getMemory(int pid, MemtrackType type,
|
||||||
|
std::vector<MemtrackRecord>* _aidl_return) override;
|
||||||
|
|
||||||
|
ndk::ScopedAStatus getGpuDeviceInfo(std::vector<DeviceInfo>* _aidl_return) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace memtrack
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
||||||
|
} // namespace aidl
|
36
memtrack/aidl/default/main.cpp
Normal file
36
memtrack/aidl/default/main.cpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Memtrack.h"
|
||||||
|
|
||||||
|
#include <android-base/logging.h>
|
||||||
|
#include <android/binder_manager.h>
|
||||||
|
#include <android/binder_process.h>
|
||||||
|
|
||||||
|
using aidl::android::hardware::memtrack::Memtrack;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||||
|
std::shared_ptr<Memtrack> memtrack = ndk::SharedRefBase::make<Memtrack>();
|
||||||
|
|
||||||
|
const std::string instance = std::string() + Memtrack::descriptor + "/default";
|
||||||
|
binder_status_t status =
|
||||||
|
AServiceManager_addService(memtrack->asBinder().get(), instance.c_str());
|
||||||
|
CHECK(status == STATUS_OK);
|
||||||
|
|
||||||
|
ABinderProcess_joinThreadPool();
|
||||||
|
return EXIT_FAILURE; // Unreachable
|
||||||
|
}
|
4
memtrack/aidl/default/memtrack-default.rc
Normal file
4
memtrack/aidl/default/memtrack-default.rc
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
service vendor.memtrack-default /vendor/bin/hw/android.hardware.memtrack-service.example
|
||||||
|
class hal
|
||||||
|
user nobody
|
||||||
|
group system
|
7
memtrack/aidl/default/memtrack-default.xml
Normal file
7
memtrack/aidl/default/memtrack-default.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<manifest version="1.0" type="device">
|
||||||
|
<hal format="aidl">
|
||||||
|
<name>android.hardware.memtrack</name>
|
||||||
|
<fqname>IMemtrack/default</fqname>
|
||||||
|
</hal>
|
||||||
|
</manifest>
|
||||||
|
|
17
memtrack/aidl/vts/Android.bp
Normal file
17
memtrack/aidl/vts/Android.bp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
cc_test {
|
||||||
|
name: "VtsHalMemtrackTargetTest",
|
||||||
|
defaults: [
|
||||||
|
"VtsHalTargetTestDefaults",
|
||||||
|
"use_libaidlvintf_gtest_helper_static",
|
||||||
|
],
|
||||||
|
srcs: ["VtsHalMemtrackTargetTest.cpp"],
|
||||||
|
shared_libs: [
|
||||||
|
"libbinder_ndk",
|
||||||
|
],
|
||||||
|
static_libs: [
|
||||||
|
"android.hardware.memtrack-unstable-ndk_platform",
|
||||||
|
],
|
||||||
|
test_suites: [
|
||||||
|
"vts-core",
|
||||||
|
],
|
||||||
|
}
|
90
memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp
Normal file
90
memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#include <aidl/Gtest.h>
|
||||||
|
#include <aidl/Vintf.h>
|
||||||
|
|
||||||
|
#include <aidl/android/hardware/memtrack/DeviceInfo.h>
|
||||||
|
#include <aidl/android/hardware/memtrack/IMemtrack.h>
|
||||||
|
#include <aidl/android/hardware/memtrack/MemtrackType.h>
|
||||||
|
#include <android/binder_manager.h>
|
||||||
|
#include <android/binder_process.h>
|
||||||
|
|
||||||
|
using aidl::android::hardware::memtrack::DeviceInfo;
|
||||||
|
using aidl::android::hardware::memtrack::IMemtrack;
|
||||||
|
using aidl::android::hardware::memtrack::MemtrackRecord;
|
||||||
|
using aidl::android::hardware::memtrack::MemtrackType;
|
||||||
|
|
||||||
|
class MemtrackAidlTest : public testing::TestWithParam<std::string> {
|
||||||
|
public:
|
||||||
|
virtual void SetUp() override {
|
||||||
|
const auto instance = std::string() + IMemtrack::descriptor + "/default";
|
||||||
|
auto memtrackBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str()));
|
||||||
|
memtrack_ = IMemtrack::fromBinder(memtrackBinder);
|
||||||
|
ASSERT_NE(memtrack_, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<IMemtrack> memtrack_;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_P(MemtrackAidlTest, GetMemoryInvalidPid) {
|
||||||
|
int pid = -1;
|
||||||
|
MemtrackType type = MemtrackType::OTHER;
|
||||||
|
std::vector<MemtrackRecord> records;
|
||||||
|
|
||||||
|
auto status = memtrack_->getMemory(pid, type, &records);
|
||||||
|
|
||||||
|
EXPECT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_P(MemtrackAidlTest, GetMemoryInvalidType) {
|
||||||
|
int pid = 1;
|
||||||
|
MemtrackType type = MemtrackType::NUM_TYPES;
|
||||||
|
std::vector<MemtrackRecord> records;
|
||||||
|
|
||||||
|
auto status = memtrack_->getMemory(pid, type, &records);
|
||||||
|
|
||||||
|
EXPECT_EQ(status.getExceptionCode(), EX_UNSUPPORTED_OPERATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_P(MemtrackAidlTest, GetMemory) {
|
||||||
|
int pid = 1;
|
||||||
|
MemtrackType type = MemtrackType::OTHER;
|
||||||
|
std::vector<MemtrackRecord> records;
|
||||||
|
|
||||||
|
auto status = memtrack_->getMemory(pid, type, &records);
|
||||||
|
|
||||||
|
EXPECT_TRUE(status.isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_P(MemtrackAidlTest, GetGpuDeviceInfo) {
|
||||||
|
std::vector<DeviceInfo> device_info;
|
||||||
|
|
||||||
|
auto status = memtrack_->getGpuDeviceInfo(&device_info);
|
||||||
|
|
||||||
|
EXPECT_TRUE(status.isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MemtrackAidlTest);
|
||||||
|
INSTANTIATE_TEST_SUITE_P(PerInstance, MemtrackAidlTest,
|
||||||
|
testing::ValuesIn(android::getAidlHalInstanceNames(IMemtrack::descriptor)),
|
||||||
|
android::PrintInstanceNameToString);
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
ABinderProcess_setThreadPoolMaxThreadCount(1);
|
||||||
|
ABinderProcess_startThreadPool();
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
Loading…
Reference in a new issue