blob: 2134a6ffe96a39afbc9f3330d243750366087560 [file] [log] [blame]
Colin Crossfc600e42013-09-06 16:41:40 -07001/*
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 Lesinski481b9472013-09-23 18:42:41 -070022
23#ifdef __cplusplus
24extern "C" {
25#endif
Colin Crossfc600e42013-09-06 16:41:40 -070026
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 */
35struct memtrack_proc;
36
37/**
Colin Crossfc600e42013-09-06 16:41:40 -070038 * memtrack_proc_new
39 *
40 * Return a new handle to hold process memory stats.
41 *
42 * Returns NULL on error.
43 */
44struct memtrack_proc *memtrack_proc_new(void);
45
46/**
47 * memtrack_proc_destroy
48 *
49 * Free all memory associated with a process memory stats handle.
50 */
51void memtrack_proc_destroy(struct memtrack_proc *p);
52
53/**
54 * memtrack_proc_get
55 *
56 * Fill a process memory stats handle with data about the given pid. Can be
57 * called on a handle that was just allocated with memtrack_proc_new,
58 * or on a handle that has been previously passed to memtrack_proc_get
59 * to replace the data with new data on the same or another process. It is
60 * expected that the second call on the same handle should not require
61 * allocating any new memory.
62 *
63 * Returns 0 on success, -errno on error.
64 */
65int memtrack_proc_get(struct memtrack_proc *p, pid_t pid);
66
67/**
68 * memtrack_proc_graphics_total
69 *
70 * Return total amount of memory that has been allocated for use as window
71 * buffers. Does not differentiate between memory that has already been
72 * accounted for by reading /proc/pid/smaps and memory that has not been
73 * accounted for.
74 *
75 * Returns non-negative size in bytes on success, -errno on error.
76 */
77ssize_t memtrack_proc_graphics_total(struct memtrack_proc *p);
78
79/**
80 * memtrack_proc_graphics_pss
81 *
82 * Return total amount of memory that has been allocated for use as window
83 * buffers, but has not already been accounted for by reading /proc/pid/smaps.
84 * Memory that is shared across processes may already be divided by the
85 * number of processes that share it (preferred), or may be charged in full to
86 * every process that shares it, depending on the capabilities of the driver.
87 *
88 * Returns non-negative size in bytes on success, -errno on error.
89 */
90ssize_t memtrack_proc_graphics_pss(struct memtrack_proc *p);
91
92/**
93 * memtrack_proc_gl_total
94 *
95 * Same as memtrack_proc_graphics_total, but counts GL memory (which
96 * should not overlap with graphics memory) instead of graphics memory.
97 *
98 * Returns non-negative size in bytes on success, -errno on error.
99 */
100ssize_t memtrack_proc_gl_total(struct memtrack_proc *p);
101
102/**
103 * memtrack_proc_gl_pss
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 */
110ssize_t memtrack_proc_gl_pss(struct memtrack_proc *p);
111
112/**
Richard Uhler587fb6a2015-04-20 10:10:33 -0700113 * memtrack_proc_other_total
Colin Crossfc600e42013-09-06 16:41:40 -0700114 *
115 * Same as memtrack_proc_graphics_total, but counts miscellaneous memory
116 * not tracked by gl or graphics calls above.
117 *
118 * Returns non-negative size in bytes on success, -errno on error.
119 */
120ssize_t memtrack_proc_other_total(struct memtrack_proc *p);
121
122/**
Richard Uhler587fb6a2015-04-20 10:10:33 -0700123 * memtrack_proc_other_pss
Colin Crossfc600e42013-09-06 16:41:40 -0700124 *
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 */
130ssize_t memtrack_proc_other_pss(struct memtrack_proc *p);
131
Adam Lesinski481b9472013-09-23 18:42:41 -0700132#ifdef __cplusplus
133}
134#endif
135
Colin Crossfc600e42013-09-06 16:41:40 -0700136#endif