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