1*4d7e907cSAndroid Build Coastguard Worker/* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project 3*4d7e907cSAndroid Build Coastguard Worker * 4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*4d7e907cSAndroid Build Coastguard Worker * 8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*4d7e907cSAndroid Build Coastguard Worker * 10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License. 15*4d7e907cSAndroid Build Coastguard Worker */ 16*4d7e907cSAndroid Build Coastguard Worker 17*4d7e907cSAndroid Build Coastguard Workerpackage [email protected]; 18*4d7e907cSAndroid Build Coastguard Worker 19*4d7e907cSAndroid Build Coastguard Worker/** 20*4d7e907cSAndroid Build Coastguard Worker * The Memory Tracker HAL is designed to return information about 21*4d7e907cSAndroid Build Coastguard Worker * device-specific memory usage. 22*4d7e907cSAndroid Build Coastguard Worker * The primary goal is to be able to track memory that is not 23*4d7e907cSAndroid Build Coastguard Worker * trackable in any other way, for example texture memory that is allocated by 24*4d7e907cSAndroid Build Coastguard Worker * a process, but not mapped in to that process's address space. 25*4d7e907cSAndroid Build Coastguard Worker * A secondary goal is to be able to categorize memory used by a process into 26*4d7e907cSAndroid Build Coastguard Worker * GL, graphics, etc. All memory sizes must be in real memory usage, 27*4d7e907cSAndroid Build Coastguard Worker * accounting for stride, bit depth, rounding up to page size, etc. 28*4d7e907cSAndroid Build Coastguard Worker * 29*4d7e907cSAndroid Build Coastguard Worker * Constructor for the interface should be used to perform memtrack management 30*4d7e907cSAndroid Build Coastguard Worker * setup actions and is called once before any calls to getMemory(). 31*4d7e907cSAndroid Build Coastguard Worker */ 32*4d7e907cSAndroid Build Coastguard Workerinterface IMemtrack { 33*4d7e907cSAndroid Build Coastguard Worker /** 34*4d7e907cSAndroid Build Coastguard Worker * getMemory() populates MemtrackRecord vector with the sizes of memory 35*4d7e907cSAndroid Build Coastguard Worker * plus associated flags for that memory. 36*4d7e907cSAndroid Build Coastguard Worker * 37*4d7e907cSAndroid Build Coastguard Worker * This function must be thread-safe, it may get called from multiple 38*4d7e907cSAndroid Build Coastguard Worker * threads at the same time. 39*4d7e907cSAndroid Build Coastguard Worker * 40*4d7e907cSAndroid Build Coastguard Worker * A process collecting memory statistics will call getMemory for each 41*4d7e907cSAndroid Build Coastguard Worker * combination of pid and memory type. For each memory type that it 42*4d7e907cSAndroid Build Coastguard Worker * recognizes, the HAL must fill out an array of memtrack_record 43*4d7e907cSAndroid Build Coastguard Worker * structures breaking down the statistics of that memory type as much as 44*4d7e907cSAndroid Build Coastguard Worker * possible. For example, 45*4d7e907cSAndroid Build Coastguard Worker * getMemory(<pid>, GL) might return: 46*4d7e907cSAndroid Build Coastguard Worker * { { 4096, ACCOUNTED | PRIVATE | SYSTEM }, 47*4d7e907cSAndroid Build Coastguard Worker * { 40960, UNACCOUNTED | PRIVATE | SYSTEM }, 48*4d7e907cSAndroid Build Coastguard Worker * { 8192, ACCOUNTED | PRIVATE | DEDICATED }, 49*4d7e907cSAndroid Build Coastguard Worker * { 8192, UNACCOUNTED | PRIVATE | DEDICATED } } 50*4d7e907cSAndroid Build Coastguard Worker * If the HAL cannot differentiate between SYSTEM and DEDICATED memory, it 51*4d7e907cSAndroid Build Coastguard Worker * could return: 52*4d7e907cSAndroid Build Coastguard Worker * { { 12288, ACCOUNTED | PRIVATE }, 53*4d7e907cSAndroid Build Coastguard Worker * { 49152, UNACCOUNTED | PRIVATE } } 54*4d7e907cSAndroid Build Coastguard Worker * 55*4d7e907cSAndroid Build Coastguard Worker * Memory must not overlap between types. For example, a graphics buffer 56*4d7e907cSAndroid Build Coastguard Worker * that has been mapped into the GPU as a surface must show up when 57*4d7e907cSAndroid Build Coastguard Worker * GRAPHICS is requested and not when GL 58*4d7e907cSAndroid Build Coastguard Worker * is requested. 59*4d7e907cSAndroid Build Coastguard Worker * 60*4d7e907cSAndroid Build Coastguard Worker * @param pid process for which memory information is requested 61*4d7e907cSAndroid Build Coastguard Worker * @param type memory type that information is being requested about 62*4d7e907cSAndroid Build Coastguard Worker * @return records vector of MemtrackRecord containing memory information 63*4d7e907cSAndroid Build Coastguard Worker * @return retval SUCCESS on success, TYPE_NOT_FOUND if the type is not 64*4d7e907cSAndroid Build Coastguard Worker * supported. 65*4d7e907cSAndroid Build Coastguard Worker */ 66*4d7e907cSAndroid Build Coastguard Worker getMemory(int32_t pid, MemtrackType type) 67*4d7e907cSAndroid Build Coastguard Worker generates (MemtrackStatus retval, vec<MemtrackRecord> records); 68*4d7e907cSAndroid Build Coastguard Worker}; 69