1 #include <config.h>
2
3 #include <glibtop.h>
4 #include <glibtop/sysinfo.h>
5 #include <glibtop/union.h>
6
7
8 /**
9 * glibtop_close:
10 *
11 * Close the connection to the server.
12 */
13 void
glibtop_close(void)14 glibtop_close(void)
15 {
16 glibtop_close_r(glibtop_global_server);
17 }
18
19 /**
20 * SECTION:glibtop
21 * @short_description: Server initilization
22 * @stability: Stable
23 *
24 * You do not need to worry about the #glibtop * server structure if
25 * you don't need - the library exports a #glibtop_global_server
26 * which you can use everywhere a #glibtop * is expected.
27 *
28 * Most of the library and all of the sysdeps function also have an alias
29 * (which is the function name without the <suffix>_l</suffix>,
30 * <suffix>_s</suffix> or <suffix>_r</suffix> suffix) which don't
31 * take a #glibtop * as argument but uses the #glibtop_global_server
32 * instead.
33 */
34
35 /**
36 * glibtop_init:
37 *
38 * Server initialization.
39 *
40 * Returns: A #glibtop reference.
41 */
42 glibtop*
glibtop_init(void)43 glibtop_init(void)
44 {
45 return glibtop_init_r(&glibtop_global_server, 0, 0);
46 }
47
48
49 /**
50 * glibtop_get_cpu:
51 * @buf: A location to return the CPU usage.
52 *
53 * Get the CPU usage.
54 *
55 * All CPU units are measured in <type>jiffies</type> which are normally
56 * 1/100th of a second (in which case <type>frequency</type> equals 100),
57 * but can also be in any other unit. To get seconds, divide them by
58 * <type>frequency</type>.
59 */
60 void
glibtop_get_cpu(glibtop_cpu * buf)61 glibtop_get_cpu(glibtop_cpu *buf)
62 {
63 glibtop_get_cpu_l(glibtop_global_server, buf);
64 }
65
66
67 /**
68 * glibtop_get_fsusage:
69 * @buf: A location to return the file system usage.
70 * @mount_dir: mount dir where to get the information of usage.
71 *
72 * Get the file system usage for an specific @mount_dir.
73 */
74 void
glibtop_get_fsusage(glibtop_fsusage * buf,const char * mount_dir)75 glibtop_get_fsusage(glibtop_fsusage *buf, const char *mount_dir)
76 {
77 glibtop_get_fsusage_l(glibtop_global_server, buf, mount_dir);
78 }
79
80
81 /**
82 * glibtop_get_uptime:
83 * @buf: A location to return the system uptime
84 *
85 * When porting LibGTop to a new system, you only need to implement
86 * #uptime and #idletime if there's a faster or better way to obtain them
87 * as using function(glibtop_cpu) for it. Look at
88 * <filename>sysdeps/freebsd/uptime.c</filename> for an
89 * example on how to obtain them using function(glibtop_cpu).
90 */
91 void
glibtop_get_uptime(glibtop_uptime * buf)92 glibtop_get_uptime(glibtop_uptime *buf)
93 {
94 glibtop_get_uptime_l(glibtop_global_server, buf);
95 }
96
97
98 /**
99 * glibtop_sysinfo:
100 *
101 * Returns: The system information through a #glibtop_sysinfo structure.
102 */
103 const glibtop_sysinfo *
glibtop_get_sysinfo(void)104 glibtop_get_sysinfo(void)
105 {
106 return glibtop_get_sysinfo_s(glibtop_global_server);
107 }
108
109
110 /**
111 * glibtop_get_swap:
112 * @buf: A location to return a #glibtop_swap.
113 *
114 * Get the swap usage.
115 */
116 void
glibtop_get_swap(glibtop_swap * buf)117 glibtop_get_swap(glibtop_swap *buf)
118 {
119 glibtop_get_swap_l(glibtop_global_server, buf);
120 }
121
122
123 /**
124 * glibtop_get_proc_uid:
125 * @buf: A location to return a #glibtop_proc_uid
126 * @pid: Process id to get the user and tty information
127 *
128 * Get the process user id and tty information.
129 */
130 void
glibtop_get_proc_uid(glibtop_proc_uid * buf,pid_t pid)131 glibtop_get_proc_uid(glibtop_proc_uid *buf, pid_t pid)
132 {
133 glibtop_get_proc_uid_l(glibtop_global_server, buf, pid);
134 }
135
136
137 /**
138 * SECTION:proctime
139 * @title: Process Time
140 * @short_description: Get process time information
141 * @stability: Stable
142 */
143
144 /**
145 * glibtop_get_proc_time:
146 * @buf: Returned process time information - see #glibtop_proc_time.
147 * @pid: Process id
148 *
149 * Get process time information.
150 */
151 void
glibtop_get_proc_time(glibtop_proc_time * buf,pid_t pid)152 glibtop_get_proc_time(glibtop_proc_time *buf, pid_t pid)
153 {
154 glibtop_get_proc_time_l(glibtop_global_server, buf, pid);
155 }
156
157
158 void
glibtop_get_proc_state(glibtop_proc_state * buf,pid_t pid)159 glibtop_get_proc_state(glibtop_proc_state *buf, pid_t pid)
160 {
161 glibtop_get_proc_state_l(glibtop_global_server, buf, pid);
162 }
163
164
165 void
glibtop_get_proc_signal(glibtop_proc_signal * buf,pid_t pid)166 glibtop_get_proc_signal(glibtop_proc_signal *buf, pid_t pid)
167 {
168 glibtop_get_proc_signal_l(glibtop_global_server, buf, pid);
169 }
170
171
172 void
glibtop_get_proc_segment(glibtop_proc_segment * buf,pid_t pid)173 glibtop_get_proc_segment(glibtop_proc_segment *buf, pid_t pid)
174 {
175 glibtop_get_proc_segment_l(glibtop_global_server, buf, pid);
176 }
177
178
179 glibtop_open_files_entry *
glibtop_get_proc_open_files(glibtop_proc_open_files * buf,pid_t pid)180 glibtop_get_proc_open_files(glibtop_proc_open_files *buf, pid_t pid)
181 {
182 return glibtop_get_proc_open_files_l(glibtop_global_server, buf, pid);
183 }
184
185
186 void
glibtop_get_proc_mem(glibtop_proc_mem * buf,pid_t pid)187 glibtop_get_proc_mem(glibtop_proc_mem *buf, pid_t pid)
188 {
189 glibtop_get_proc_mem_l(glibtop_global_server, buf, pid);
190 }
191
192
193 glibtop_map_entry *
glibtop_get_proc_map(glibtop_proc_map * buf,pid_t pid)194 glibtop_get_proc_map(glibtop_proc_map *buf, pid_t pid)
195 {
196 return glibtop_get_proc_map_l(glibtop_global_server, buf, pid);
197 }
198
199
200 /**
201 * SECTION:procargs
202 * @title: Process Arguments
203 * @short_description: Get process command line arguments
204 * @see_also: #libgtop-Process-List
205 * @stability: Stable
206 */
207
208 /**
209 * glibtop_get_proc_args:
210 * @buf: Struct with @size of returned string.
211 * @pid: Process id
212 * @max_len: Maximum length of string to return (use zero to get all arguments).
213 *
214 * Get process command line arguments.
215 *
216 * Returns: @pid's command line arguments separated by null bytes; the length of
217 * this string is returned in the @buf size field. You are required to free
218 * the string when done.
219 */
220 char *
glibtop_get_proc_args(glibtop_proc_args * buf,pid_t pid,unsigned max_len)221 glibtop_get_proc_args(glibtop_proc_args *buf, pid_t pid, unsigned max_len)
222 {
223 return glibtop_get_proc_args_l(glibtop_global_server, buf, pid, max_len);
224 }
225
226
227 /**
228 * glibtop_get_proc_argv
229 * @buf: Struct with @size of combined returned arguments.
230 * @pid: Process id
231 * @max_len: Maximum length of all arguments combined (use zero to get all arguments).
232 *
233 * Get process command line arguments.
234 *
235 * Returns: A NULL-terminated array of strings with all arguments of process pid
236 * (up to @max_len characters). Remember to <function>g_strfreev</function>
237 * the returned array to avoid a memory leak.
238 */
239 char **
glibtop_get_proc_argv(glibtop_proc_args * buf,pid_t pid,unsigned max_len)240 glibtop_get_proc_argv(glibtop_proc_args *buf, pid_t pid, unsigned max_len)
241 {
242 return glibtop_get_proc_argv_l(glibtop_global_server, buf, pid, max_len);
243 }
244
245
246 /**
247 * SECTION:proclist
248 * @title: Process List
249 * @short_description: List running processes
250 * @stability: Stable
251 */
252
253 /**
254 * glibtop_get_proclist
255 * @buf: Extra return information, see #glibtop_proclist.
256 * @which: Criteria for processes in returned list. See the <type>GLIBTOP_KERN_PROC_*</type> and <type>GLIBTOP_EXCLUDE_*</type> constants.
257 * @arg: Extra arguments applied to @which. Only <type>GLIBTOP_KERN_PROC_*</type> constants take arguments, see each constant definition for particular @arg description.
258 *
259 * Returns: A list of running processes or <type>NULL</type> on error. The
260 * returned list is allocated using <function>g_malloc</function> and must be
261 * freed using <function>g_free</function> to avoid a memory leak.
262 */
263 pid_t*
glibtop_get_proclist(glibtop_proclist * buf,gint64 which,gint64 arg)264 glibtop_get_proclist(glibtop_proclist *buf, gint64 which, gint64 arg)
265 {
266 return glibtop_get_proclist_l(glibtop_global_server, buf, which, arg);
267 }
268
269
270 void
glibtop_get_proc_kernel(glibtop_proc_kernel * buf,pid_t pid)271 glibtop_get_proc_kernel(glibtop_proc_kernel *buf, pid_t pid)
272 {
273 glibtop_get_proc_kernel_l(glibtop_global_server, buf, pid);
274 }
275
276
277 /**
278 * SECTION:ppp
279 * @short_description: PPP Usage.
280 * @see_also: #libgtop-netload, #libgtop-netlist
281 * @stability: Stable
282 *
283 * Management of a PPP device.
284 */
285
286 /**
287 * glibtop_get_ppp:
288 * @buf: A location to return the PPP usage
289 * @short device: The device to ask information
290 *
291 * Get the PPP usage.
292 */
293 void
glibtop_get_ppp(glibtop_ppp * buf,unsigned short device)294 glibtop_get_ppp(glibtop_ppp *buf, unsigned short device)
295 {
296 glibtop_get_ppp_l(glibtop_global_server, buf, device);
297 }
298
299 /**
300 * SECTION:netlist
301 * @short_description: Network Devices List.
302 * @see_also: #libgtop-netload
303 * @stability: Stable
304 *
305 * The application class handles ...
306 */
307
308 /**
309 * glibtop_get_nelist:
310 * @buf:
311 *
312 * Get the list of network devices.
313 *
314 * Returns: A list of network devices.
315 */
316 char**
glibtop_get_netlist(glibtop_netlist * buf)317 glibtop_get_netlist(glibtop_netlist *buf)
318 {
319 return glibtop_get_netlist_l(glibtop_global_server, buf);
320 }
321
322 /**
323 * SECTION:netload
324 * @short_description: Network Load.
325 * @see_also: #libtop-netlist
326 * @stability: Stable
327 *
328 * The application class handles ...
329 */
330
331
332 /**
333 * glibtop_get_netload:
334 * @buf: The variable where the results will be assigned.
335 * @interface: The name of the network interface.
336 *
337 * Recolects network statistics for @interface
338 * (which is the same than in <application>ifconfig</application>).
339 * The values are returned into @buf.
340 */
341 void
glibtop_get_netload(glibtop_netload * buf,const char * interface)342 glibtop_get_netload(glibtop_netload *buf, const char *interface)
343 {
344 glibtop_get_netload_l(glibtop_global_server, buf, interface);
345 }
346
347
348 glibtop_mountentry *
glibtop_get_mountlist(glibtop_mountlist * buf,int all_fs)349 glibtop_get_mountlist(glibtop_mountlist *buf, int all_fs)
350 {
351 return glibtop_get_mountlist_l(glibtop_global_server, buf, all_fs);
352 }
353
354
355 /**
356 * glibtop_get_mem:
357 * @buf: Buffer where the output will be given.
358 *
359 * Get the memory usage. Unless explicitly stated otherwise, all memory
360 * units are in bytes.
361 */
362 void
glibtop_get_mem(glibtop_mem * buf)363 glibtop_get_mem(glibtop_mem *buf)
364 {
365 glibtop_get_mem_l(glibtop_global_server, buf);
366 }
367
368
369 void
glibtop_get_loadavg(glibtop_loadavg * buf)370 glibtop_get_loadavg(glibtop_loadavg *buf)
371 {
372 glibtop_get_loadavg_l(glibtop_global_server, buf);
373 }
374
375
376 void
glibtop_get_msg_limits(glibtop_msg_limits * buf)377 glibtop_get_msg_limits(glibtop_msg_limits *buf)
378 {
379 glibtop_get_msg_limits_l(glibtop_global_server, buf);
380 }
381
382
383 void
glibtop_get_sem_limits(glibtop_sem_limits * buf)384 glibtop_get_sem_limits(glibtop_sem_limits *buf)
385 {
386 glibtop_get_sem_limits_l(glibtop_global_server, buf);
387 }
388
389
390 void
glibtop_get_shm_limits(glibtop_shm_limits * buf)391 glibtop_get_shm_limits(glibtop_shm_limits *buf)
392 {
393 glibtop_get_shm_limits_l(glibtop_global_server, buf);
394 }
395
396
397 void
glibtop_get_sysdeps(glibtop_sysdeps * buf)398 glibtop_get_sysdeps(glibtop_sysdeps *buf)
399 {
400 glibtop_get_sysdeps_r(glibtop_global_server, buf);
401 }
402
403
404 /**
405 * glibtop_get_proc_wd:
406 * @buf:
407 * @pid: Process id to get the user and tty information
408 *
409 * Get the root directory and the working directories
410 *
411 * Returns: A NULL-terminated list of working directories.
412 */
413 char**
glibtop_get_proc_wd(glibtop_proc_wd * buf,pid_t pid)414 glibtop_get_proc_wd(glibtop_proc_wd *buf, pid_t pid)
415 {
416 return glibtop_get_proc_wd_l(glibtop_global_server, buf, pid);
417 }
418
419
420 /**
421 * glibtop_get_proc_affinity:
422 * @buf:
423 * @pid: Process id to get the affinity
424 *
425 * Get the processor affinity list for a process
426 *
427 * Returns: A list of processor ID of 'buf.number' elements.
428 */
429 guint16 *
glibtop_get_proc_affinity(glibtop_proc_affinity * buf,pid_t pid)430 glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid)
431 {
432 return glibtop_get_proc_affinity_l(glibtop_global_server, buf, pid);
433 }
434
435 /**
436 * glibtop_get_proc_io: Get the io stats for the given pid
437 * @buf: Buffer where the result will be given
438 * @pid: Process id to get the io stats for
439 *
440 * Get the io stats for a process
441 *
442 * Returns: A list of processor ID of 'buf.number' elements.
443 */
444 void
glibtop_get_proc_io(glibtop_proc_io * buf,pid_t pid)445 glibtop_get_proc_io(glibtop_proc_io *buf, pid_t pid)
446 {
447 return glibtop_get_proc_io_l(glibtop_global_server, buf, pid);
448 }
449