summaryrefslogtreecommitdiff
path: root/sysdeps/common/default.c
blob: e3b096f2f434082290f1477af47b9e148dea0bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#include <config.h>

#include <glibtop.h>
#include <glibtop/sysinfo.h>
#include <glibtop/union.h>


/**
 * glibtop_close:
 *
 * Close the connection to the server.
 */
void
glibtop_close(void)
{
	glibtop_close_r(glibtop_global_server);
}

/**
 * SECTION:glibtop
 * @short_description: Server initilization
 * @stability: Stable
 *  
 * You do not need to worry about the #glibtop * server structure if
 * you don't need - the library exports a #glibtop_global_server
 * which you can use everywhere a #glibtop * is expected.
 *
 * Most of the library and all of the sysdeps function also have an alias
 * (which is the function name without the <suffix>_l</suffix>, 
 * <suffix>_s</suffix> or <suffix>_r</suffix> suffix) which don't 
 * take a #glibtop * as argument but uses the #glibtop_global_server 
 * instead.
 */

/**
 * glibtop_init:
 *
 * Server initialization.
 *
 * Returns: A #glibtop reference.
 */
glibtop*
glibtop_init(void)
{
	return glibtop_init_r(&glibtop_global_server, 0, 0);
}


/**
 * glibtop_get_cpu:
 * @buf: A location to return the CPU usage.
 *
 * Get the CPU usage.
 *
 * All CPU units are measured in <type>jiffies</type> which are normally
 * 1/100th of a second (in which case <type>frequency</type> equals 100),
 * but can also be in any other unit. To get seconds, divide them by 
 * <type>frequency</type>.
 */
void
glibtop_get_cpu(glibtop_cpu *buf)
{
	glibtop_get_cpu_l(glibtop_global_server, buf);
}


/**
 * glibtop_get_fsusage:
 * @buf: A location to return the file system usage.
 * @mount_dir: mount dir where to get the information of usage.
 *
 * Get the file system usage for an specific @mount_dir.
 */
void
glibtop_get_fsusage(glibtop_fsusage *buf, const char *mount_dir)
{
	glibtop_get_fsusage_l(glibtop_global_server, buf, mount_dir);
}


/**
 * glibtop_get_uptime:
 * @buf: A location to return the system uptime
 *
 * When porting LibGTop to a new system, you only need to implement 
 * #uptime and #idletime if there's a faster or better way to obtain them
 * as using function(glibtop_cpu) for it. Look at 
 * <filename>sysdeps/freebsd/uptime.c</filename> for an
 * example on how to obtain them using function(glibtop_cpu).
 */
void
glibtop_get_uptime(glibtop_uptime *buf)
{
	glibtop_get_uptime_l(glibtop_global_server, buf);
}


/**
 * glibtop_sysinfo:
 *
 * Returns: The system information through a #glibtop_sysinfo structure.
 */
const glibtop_sysinfo *
glibtop_get_sysinfo(void)
{
	return glibtop_get_sysinfo_s(glibtop_global_server);
}


/**
 * glibtop_get_swap:
 * @buf: A location to return a #glibtop_swap.
 *
 * Get the swap usage.
 */
void
glibtop_get_swap(glibtop_swap *buf)
{
	glibtop_get_swap_l(glibtop_global_server, buf);
}


/**
 * glibtop_get_proc_uid:
 * @buf: A location to return a #glibtop_proc_uid
 * @pid: Process id to get the user and tty information
 * 
 * Get the process user id and tty information.
 */
void
glibtop_get_proc_uid(glibtop_proc_uid *buf, pid_t pid)
{
	glibtop_get_proc_uid_l(glibtop_global_server, buf, pid);
}


/**
 * SECTION:proctime
 * @title: Process Time
 * @short_description: Get process time information
 * @stability: Stable
 */

/**
 * glibtop_get_proc_time:
 * @buf: Returned process time information - see #glibtop_proc_time.
 * @pid: Process id
 *
 * Get process time information.
 */
void
glibtop_get_proc_time(glibtop_proc_time *buf, pid_t pid)
{
	glibtop_get_proc_time_l(glibtop_global_server, buf, pid);
}


void
glibtop_get_proc_state(glibtop_proc_state *buf, pid_t pid)
{
	glibtop_get_proc_state_l(glibtop_global_server, buf, pid);
}


void
glibtop_get_proc_signal(glibtop_proc_signal *buf, pid_t pid)
{
	glibtop_get_proc_signal_l(glibtop_global_server, buf, pid);
}


void
glibtop_get_proc_segment(glibtop_proc_segment *buf, pid_t pid)
{
	glibtop_get_proc_segment_l(glibtop_global_server, buf, pid);
}


glibtop_open_files_entry *
glibtop_get_proc_open_files(glibtop_proc_open_files *buf, pid_t pid)
{
	return glibtop_get_proc_open_files_l(glibtop_global_server, buf, pid);
}


void
glibtop_get_proc_mem(glibtop_proc_mem *buf, pid_t pid)
{
	glibtop_get_proc_mem_l(glibtop_global_server, buf, pid);
}


glibtop_map_entry *
glibtop_get_proc_map(glibtop_proc_map *buf, pid_t pid)
{
	return glibtop_get_proc_map_l(glibtop_global_server, buf, pid);
}


/**
 * SECTION:procargs
 * @title: Process Arguments
 * @short_description: Get process command line arguments
 * @see_also: #libgtop-Process-List
 * @stability: Stable
 */

/**
 * glibtop_get_proc_args:
 * @buf: Struct with @size of returned string.
 * @pid: Process id
 * @max_len: Maximum length of string to return (use zero to get all arguments).
 *
 * Get process command line arguments.
 *
 * Returns: @pid's command line arguments separated by null bytes; the length of 
 * this string is returned in the @buf size field.  You are required to free
 * the string when done.
 */
char *
glibtop_get_proc_args(glibtop_proc_args *buf, pid_t pid, unsigned max_len)
{
	return glibtop_get_proc_args_l(glibtop_global_server, buf, pid, max_len);
}


/**
 * glibtop_get_proc_argv
 * @buf: Struct with @size of combined returned arguments.
 * @pid: Process id
 * @max_len: Maximum length of all arguments combined (use zero to get all arguments).
 *
 * Get process command line arguments.
 *
 * Returns: A NULL-terminated array of strings with all arguments of process pid
 * (up to @max_len characters).  Remember to <function>g_strfreev</function>
 * the returned array to avoid a memory leak.
 */
char **
glibtop_get_proc_argv(glibtop_proc_args *buf, pid_t pid, unsigned max_len)
{
	return glibtop_get_proc_argv_l(glibtop_global_server, buf, pid, max_len);
}


/**
 * SECTION:proclist
 * @title: Process List
 * @short_description: List running processes
 * @stability: Stable
 */

/**
 * glibtop_get_proclist
 * @buf: Extra return information, see #glibtop_proclist.
 * @which: Criteria for processes in returned list.  See the <type>GLIBTOP_KERN_PROC_*</type> and <type>GLIBTOP_EXCLUDE_*</type> constants.
 * @arg: Extra arguments applied to @which.  Only <type>GLIBTOP_KERN_PROC_*</type> constants take arguments, see each constant definition for particular @arg description.
 *
 * Returns: A list of running processes or <type>NULL</type> on error.  The
 * returned list is allocated using <function>g_malloc</function> and must be
 * freed using <function>g_free</function> to avoid a memory leak.
 */
pid_t*
glibtop_get_proclist(glibtop_proclist *buf, gint64 which, gint64 arg)
{
	return glibtop_get_proclist_l(glibtop_global_server, buf, which, arg);
}


void
glibtop_get_proc_kernel(glibtop_proc_kernel *buf, pid_t pid)
{
	glibtop_get_proc_kernel_l(glibtop_global_server, buf, pid);
}


/**
 * SECTION:ppp
 * @short_description: PPP Usage.
 * @see_also: #libgtop-netload, #libgtop-netlist
 * @stability: Stable
 *
 * Management of a PPP device.
 */

/**
 * glibtop_get_ppp:
 * @buf: A location to return the PPP usage
 * @short device: The device to ask information
 *
 * Get the PPP usage.
 */
void
glibtop_get_ppp(glibtop_ppp *buf, unsigned short device)
{
	glibtop_get_ppp_l(glibtop_global_server, buf, device);
}

/**
 * SECTION:netlist
 * @short_description: Network Devices List.
 * @see_also: #libgtop-netload
 * @stability: Stable
 *
 * The application class handles ...
 */

/**
 * glibtop_get_nelist:
 * @buf:
 *
 * Get the list of network devices.
 *
 * Returns: A list of network devices.
 */
char**
glibtop_get_netlist(glibtop_netlist *buf)
{
	return glibtop_get_netlist_l(glibtop_global_server, buf);
}

/**
 * SECTION:netload
 * @short_description: Network Load.
 * @see_also: #libtop-netlist
 * @stability: Stable
 *
 * The application class handles ...
 */


/**
 * glibtop_get_netload:
 * @buf: The variable where the results will be assigned.
 * @interface: The name of the network interface.
 *
 * Recolects network statistics for @interface
 * (which is the same than in <application>ifconfig</application>).  
 * The values are returned into @buf.
 */ 
void
glibtop_get_netload(glibtop_netload *buf, const char *interface)
{
	glibtop_get_netload_l(glibtop_global_server, buf, interface);
}


glibtop_mountentry *
glibtop_get_mountlist(glibtop_mountlist *buf, int all_fs)
{
	return glibtop_get_mountlist_l(glibtop_global_server, buf, all_fs);
}


/**
 * glibtop_get_mem:
 * @buf: Buffer where the output will be given.
 *
 * Get the memory usage. Unless explicitly stated otherwise, all memory
 * units are in bytes.
 */
void
glibtop_get_mem(glibtop_mem *buf)
{
	glibtop_get_mem_l(glibtop_global_server, buf);
}


void
glibtop_get_loadavg(glibtop_loadavg *buf)
{
	glibtop_get_loadavg_l(glibtop_global_server, buf);
}


void
glibtop_get_msg_limits(glibtop_msg_limits *buf)
{
	glibtop_get_msg_limits_l(glibtop_global_server, buf);
}


void
glibtop_get_sem_limits(glibtop_sem_limits *buf)
{
	glibtop_get_sem_limits_l(glibtop_global_server, buf);
}


void
glibtop_get_shm_limits(glibtop_shm_limits *buf)
{
	glibtop_get_shm_limits_l(glibtop_global_server, buf);
}


void
glibtop_get_sysdeps(glibtop_sysdeps *buf)
{
	glibtop_get_sysdeps_r(glibtop_global_server, buf);
}


/**
 * glibtop_get_proc_wd:
 * @buf:
 * @pid: Process id to get the user and tty information
 *
 * Get the root directory and the working directories
 *
 * Returns: A NULL-terminated list of working directories.
 */
char**
glibtop_get_proc_wd(glibtop_proc_wd *buf, pid_t pid)
{
	return glibtop_get_proc_wd_l(glibtop_global_server, buf, pid);
}


/**
 * glibtop_get_proc_affinity:
 * @buf:
 * @pid: Process id to get the affinity
 *
 * Get the processor affinity list for a process
 *
 * Returns: A list of processor ID of 'buf.number' elements.
 */
guint16 *
glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid)
{
	return glibtop_get_proc_affinity_l(glibtop_global_server, buf, pid);
}

/**
 * glibtop_get_proc_io: Get the io stats for the given pid
 * @buf: Buffer where the result will be given
 * @pid: Process id to get the io stats for
 *
 * Get the io stats for a process
 *
 * Returns: A list of processor ID of 'buf.number' elements.
 */
void
glibtop_get_proc_io(glibtop_proc_io *buf, pid_t pid)
{
	return glibtop_get_proc_io_l(glibtop_global_server, buf, pid);
}