1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef _LIBMEMTRACK_MEMTRACK_H_ 18#define _LIBMEMTRACK_MEMTRACK_H_ 19 20#include <sys/types.h> 21#include <stddef.h> 22#include <cutils/compiler.h> 23 24#ifdef __cplusplus 25extern "C" { 26#endif 27 28/** 29 * struct memtrack_proc 30 * 31 * an opaque handle to the memory stats on a process. 32 * Created with memtrack_proc_new, destroyed by 33 * memtrack_proc_destroy. Can be reused multiple times with 34 * memtrack_proc_get. 35 */ 36struct memtrack_proc; 37 38/** 39 * memtrack_init 40 * 41 * Must be called once before calling any other functions. After this function 42 * is called, everything else is thread-safe. 43 * 44 * Returns 0 on success, -errno on error. 45 */ 46int memtrack_init(void); 47 48/** 49 * memtrack_proc_new 50 * 51 * Return a new handle to hold process memory stats. 52 * 53 * Returns NULL on error. 54 */ 55struct memtrack_proc *memtrack_proc_new(void); 56 57/** 58 * memtrack_proc_destroy 59 * 60 * Free all memory associated with a process memory stats handle. 61 */ 62void memtrack_proc_destroy(struct memtrack_proc *p); 63 64/** 65 * memtrack_proc_get 66 * 67 * Fill a process memory stats handle with data about the given pid. Can be 68 * called on a handle that was just allocated with memtrack_proc_new, 69 * or on a handle that has been previously passed to memtrack_proc_get 70 * to replace the data with new data on the same or another process. It is 71 * expected that the second call on the same handle should not require 72 * allocating any new memory. 73 * 74 * Returns 0 on success, -errno on error. 75 */ 76int memtrack_proc_get(struct memtrack_proc *p, pid_t pid); 77 78/** 79 * memtrack_proc_graphics_total 80 * 81 * Return total amount of memory that has been allocated for use as window 82 * buffers. Does not differentiate between memory that has already been 83 * accounted for by reading /proc/pid/smaps and memory that has not been 84 * accounted for. 85 * 86 * Returns non-negative size in bytes on success, -errno on error. 87 */ 88ssize_t memtrack_proc_graphics_total(struct memtrack_proc *p); 89 90/** 91 * memtrack_proc_graphics_pss 92 * 93 * Return total amount of memory that has been allocated for use as window 94 * buffers, but has not already been accounted for by reading /proc/pid/smaps. 95 * Memory that is shared across processes may already be divided by the 96 * number of processes that share it (preferred), or may be charged in full to 97 * every process that shares it, depending on the capabilities of the driver. 98 * 99 * Returns non-negative size in bytes on success, -errno on error. 100 */ 101ssize_t memtrack_proc_graphics_pss(struct memtrack_proc *p); 102 103/** 104 * memtrack_proc_gl_total 105 * 106 * Same as memtrack_proc_graphics_total, but counts GL memory (which 107 * should not overlap with graphics memory) instead of graphics memory. 108 * 109 * Returns non-negative size in bytes on success, -errno on error. 110 */ 111ssize_t memtrack_proc_gl_total(struct memtrack_proc *p); 112 113/** 114 * memtrack_proc_gl_pss 115 * 116 * Same as memtrack_proc_graphics_total, but counts GL memory (which 117 * should not overlap with graphics memory) instead of graphics memory. 118 * 119 * Returns non-negative size in bytes on success, -errno on error. 120 */ 121ssize_t memtrack_proc_gl_pss(struct memtrack_proc *p); 122 123/** 124 * memtrack_proc_other_total 125 * 126 * Same as memtrack_proc_graphics_total, but counts miscellaneous memory 127 * not tracked by gl or graphics calls above. 128 * 129 * Returns non-negative size in bytes on success, -errno on error. 130 */ 131ssize_t memtrack_proc_other_total(struct memtrack_proc *p); 132 133/** 134 * memtrack_proc_other_pss 135 * 136 * Same as memtrack_proc_graphics_total, but counts miscellaneous memory 137 * not tracked by gl or graphics calls above. 138 * 139 * Returns non-negative size in bytes on success, -errno on error. 140 */ 141ssize_t memtrack_proc_other_pss(struct memtrack_proc *p); 142 143#ifdef __cplusplus 144} 145#endif 146 147#endif 148