2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
24 * @brief System memory information.
26 struct procfs_system_memory_usage_info {
27 unsigned long total; /**< Total memory (KiB) */
28 unsigned long used; /**< Used memory (KiB) */
29 unsigned long free; /**< Free memory (KiB) */
30 unsigned long cache; /**< Cache memory (KiB) */
31 unsigned long swap; /**< Swap memory (KiB) */
35 * @brief System cpu usage information.
37 struct procfs_system_cpu_usage_info {
38 unsigned long long user; /** Time running un-niced user processes (clock ticks) */
39 unsigned long long system; /** Time running kernel process (clock ticks) */
40 unsigned long long nice; /** Time running niced user processes (clock ticks) */
41 unsigned long long idle; /** Time running in idle task user processes (clock ticks) */
42 unsigned long long iowait; /** Time waiting for I/O completion (clock ticks) */
43 unsigned long long irq; /** Time servicing interrupts (clock ticks) */
44 unsigned long long softirq; /** Time servicing soft interrupts (clock ticks) */
48 * @brief System load average information.
49 * @notice For more info refer to:
50 * http://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html
51 * https://github.com/torvalds/linux/blob/master/kernel/sched/loadavg.c
53 struct procfs_load_average_info {
54 float one_min_avg; /** One minute load average */
55 float five_min_avg; /** Five minutes load average */
56 float fifteen_min_avg; /** Fifteen minutes load average */
60 * @brief Process memory information.
62 struct procfs_process_memory_usage_info {
63 unsigned long vsz; /** Virtual memory size (KiB) */
64 unsigned long rss; /** Resident set size (KiB) */
65 unsigned long pss; /** Proportional set size (KiB) */
66 unsigned long shared_clean; /** Not modified and mapped by other processes (KiB) */
67 unsigned long shared_dirty; /** Modified and mapped by other processes (KiB) */
68 unsigned long private_clean; /** Not modified and available only to that process (KiB) */
69 unsigned long private_dirty; /** Modified and available only to that process (KiB) */
73 * @brief Process cpu usage information.
75 struct procfs_process_cpu_usage_info {
76 unsigned long long utime; /** Amount of time that this process has been scheduled in user mode (clock ticks) */
77 unsigned long long stime; /** Amount of time that this process has been scheduled in kernel mode (clock ticks) */
81 * @brief Parses information from /proc/loadavg
83 * @param[out] avg structure to be filled.
84 * @return: 0 on success, other value on error
86 int procfs_read_system_load_average(struct procfs_load_average_info *avg);
89 * @brief Parses information from /proc/stat
91 * @param[out] avg structure to be filled.
92 * @return: 0 on success, other value on error
94 int procfs_read_system_cpu_usage(struct procfs_system_cpu_usage_info *usage);
97 * @brief Parses information from /proc/stat, returns system cpu usage per
100 * @param[in] max_cpus maximum number of cpus to read stats from.
101 * @param[out] usage array to be filled.
102 * @return: on success - number of entries correctly written to usage array,
103 * value < 0 if an error occured.
105 * @remark the usage array must be have at least max_cpus lenght.
107 int procfs_read_system_percpu_usage(int max_cpus, struct procfs_system_cpu_usage_info usage[]);
110 * @brief Parses information from /proc/meminfo
112 * @param[out] avg structure to be filled.
113 * @return: 0 on success, other value on error
115 int procfs_read_system_memory_usage(struct procfs_system_memory_usage_info *usage);
118 * @brief Parses information from /proc/{pid}/smaps
120 * @param[in] process pid
121 * @param[out] avg structure to be filled.
122 * @return: 0 on success, other value on error
124 int procfs_read_process_memory_usage(int pid, struct procfs_process_memory_usage_info *usage);
127 * @brief Parses information from /proc/{pid}/stat
129 * @param[in] process pid
130 * @param[out] avg structure to be filled.
131 * @return: 0 on success, other value on error
133 int procfs_read_process_cpu_usage(int pid, struct procfs_process_cpu_usage_info *usage);
136 * @brief Parses information from /proc/uptime
138 * @param[out] uptime Number of seconds after boot
139 * @return: 0 on success, other value on error
141 int procfs_read_uptime(unsigned long *uptime);
144 * @brief Parses information from /sys/devices/system/cpu/possible
146 * @param[out] cpu_count Number of logical cpus availabe in the system.
147 * @return: 0 on success, other value on error
149 int procfs_read_cpu_count(int *cpu_count);
152 * @brief Iterator over pids in /proc/ directory.
154 typedef struct procfs_pid_iterator procfs_pid_iterator_t;
157 * @brief Move iterator to next entry.
159 * @param[in]: itearator
161 * @return returns true if there are more entries available, false otherwise
163 bool procfs_pid_iterator_next(procfs_pid_iterator_t *iterator);
166 * @brief Gets current pid from iterator
168 * @param[in]: itearator
170 * @not User should always check validity of pid, since it not guaranteed that
171 * returned pid is still valid after function returns.
173 int procfs_pid_iterator_get_pid(procfs_pid_iterator_t *iterator);
176 * @brief Frees procfs_pid_iterator_t
178 * @param[in]: itearator
180 void procfs_pid_iterator_free(procfs_pid_iterator_t *iterator);
183 * @brief Gets pid iterator
185 * @return new procfs_pid_iterator_t or NULL or error or no pids is available.
187 * @note the returned value should be released wiht procfs_pid_iterator_free
189 procfs_pid_iterator_t *procfs_get_pid_iterator();