Colin Cross | fc600e4 | 2013-09-06 16:41:40 -0700 | [diff] [blame] | 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> |
Adam Lesinski | 481b947 | 2013-09-23 18:42:41 -0700 | [diff] [blame] | 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
Colin Cross | fc600e4 | 2013-09-06 16:41:40 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * struct memtrack_proc |
| 29 | * |
| 30 | * an opaque handle to the memory stats on a process. |
| 31 | * Created with memtrack_proc_new, destroyed by |
| 32 | * memtrack_proc_destroy. Can be reused multiple times with |
| 33 | * memtrack_proc_get. |
| 34 | */ |
| 35 | struct memtrack_proc; |
| 36 | |
| 37 | /** |
| 38 | * memtrack_init |
| 39 | * |
| 40 | * Must be called once before calling any other functions. After this function |
| 41 | * is called, everything else is thread-safe. |
| 42 | * |
| 43 | * Returns 0 on success, -errno on error. |
| 44 | */ |
| 45 | int memtrack_init(void); |
| 46 | |
| 47 | /** |
| 48 | * memtrack_proc_new |
| 49 | * |
| 50 | * Return a new handle to hold process memory stats. |
| 51 | * |
| 52 | * Returns NULL on error. |
| 53 | */ |
| 54 | struct memtrack_proc *memtrack_proc_new(void); |
| 55 | |
| 56 | /** |
| 57 | * memtrack_proc_destroy |
| 58 | * |
| 59 | * Free all memory associated with a process memory stats handle. |
| 60 | */ |
| 61 | void memtrack_proc_destroy(struct memtrack_proc *p); |
| 62 | |
| 63 | /** |
| 64 | * memtrack_proc_get |
| 65 | * |
| 66 | * Fill a process memory stats handle with data about the given pid. Can be |
| 67 | * called on a handle that was just allocated with memtrack_proc_new, |
| 68 | * or on a handle that has been previously passed to memtrack_proc_get |
| 69 | * to replace the data with new data on the same or another process. It is |
| 70 | * expected that the second call on the same handle should not require |
| 71 | * allocating any new memory. |
| 72 | * |
| 73 | * Returns 0 on success, -errno on error. |
| 74 | */ |
| 75 | int memtrack_proc_get(struct memtrack_proc *p, pid_t pid); |
| 76 | |
| 77 | /** |
| 78 | * memtrack_proc_graphics_total |
| 79 | * |
| 80 | * Return total amount of memory that has been allocated for use as window |
| 81 | * buffers. Does not differentiate between memory that has already been |
| 82 | * accounted for by reading /proc/pid/smaps and memory that has not been |
| 83 | * accounted for. |
| 84 | * |
| 85 | * Returns non-negative size in bytes on success, -errno on error. |
| 86 | */ |
| 87 | ssize_t memtrack_proc_graphics_total(struct memtrack_proc *p); |
| 88 | |
| 89 | /** |
| 90 | * memtrack_proc_graphics_pss |
| 91 | * |
| 92 | * Return total amount of memory that has been allocated for use as window |
| 93 | * buffers, but has not already been accounted for by reading /proc/pid/smaps. |
| 94 | * Memory that is shared across processes may already be divided by the |
| 95 | * number of processes that share it (preferred), or may be charged in full to |
| 96 | * every process that shares it, depending on the capabilities of the driver. |
| 97 | * |
| 98 | * Returns non-negative size in bytes on success, -errno on error. |
| 99 | */ |
| 100 | ssize_t memtrack_proc_graphics_pss(struct memtrack_proc *p); |
| 101 | |
| 102 | /** |
| 103 | * memtrack_proc_gl_total |
| 104 | * |
| 105 | * Same as memtrack_proc_graphics_total, but counts GL memory (which |
| 106 | * should not overlap with graphics memory) instead of graphics memory. |
| 107 | * |
| 108 | * Returns non-negative size in bytes on success, -errno on error. |
| 109 | */ |
| 110 | ssize_t memtrack_proc_gl_total(struct memtrack_proc *p); |
| 111 | |
| 112 | /** |
| 113 | * memtrack_proc_gl_pss |
| 114 | * |
| 115 | * Same as memtrack_proc_graphics_total, but counts GL memory (which |
| 116 | * should not overlap with graphics memory) instead of graphics memory. |
| 117 | * |
| 118 | * Returns non-negative size in bytes on success, -errno on error. |
| 119 | */ |
| 120 | ssize_t memtrack_proc_gl_pss(struct memtrack_proc *p); |
| 121 | |
| 122 | /** |
Richard Uhler | 587fb6a | 2015-04-20 10:10:33 -0700 | [diff] [blame] | 123 | * memtrack_proc_other_total |
Colin Cross | fc600e4 | 2013-09-06 16:41:40 -0700 | [diff] [blame] | 124 | * |
| 125 | * Same as memtrack_proc_graphics_total, but counts miscellaneous memory |
| 126 | * not tracked by gl or graphics calls above. |
| 127 | * |
| 128 | * Returns non-negative size in bytes on success, -errno on error. |
| 129 | */ |
| 130 | ssize_t memtrack_proc_other_total(struct memtrack_proc *p); |
| 131 | |
| 132 | /** |
Richard Uhler | 587fb6a | 2015-04-20 10:10:33 -0700 | [diff] [blame] | 133 | * memtrack_proc_other_pss |
Colin Cross | fc600e4 | 2013-09-06 16:41:40 -0700 | [diff] [blame] | 134 | * |
| 135 | * Same as memtrack_proc_graphics_total, but counts miscellaneous memory |
| 136 | * not tracked by gl or graphics calls above. |
| 137 | * |
| 138 | * Returns non-negative size in bytes on success, -errno on error. |
| 139 | */ |
| 140 | ssize_t memtrack_proc_other_pss(struct memtrack_proc *p); |
| 141 | |
Adam Lesinski | 481b947 | 2013-09-23 18:42:41 -0700 | [diff] [blame] | 142 | #ifdef __cplusplus |
| 143 | } |
| 144 | #endif |
| 145 | |
Colin Cross | fc600e4 | 2013-09-06 16:41:40 -0700 | [diff] [blame] | 146 | #endif |