Blame sysdeps/common/default.c

Packit d37888
#include <config.h>
Packit d37888
Packit d37888
#include <glibtop.h>
Packit d37888
#include <glibtop/sysinfo.h>
Packit d37888
#include <glibtop/union.h>
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_close:
Packit d37888
 *
Packit d37888
 * Close the connection to the server.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_close(void)
Packit d37888
{
Packit d37888
	glibtop_close_r(glibtop_global_server);
Packit d37888
}
Packit d37888
Packit d37888
/**
Packit d37888
 * SECTION:glibtop
Packit d37888
 * @short_description: Server initilization
Packit d37888
 * @stability: Stable
Packit d37888
 *  
Packit d37888
 * You do not need to worry about the #glibtop * server structure if
Packit d37888
 * you don't need - the library exports a #glibtop_global_server
Packit d37888
 * which you can use everywhere a #glibtop * is expected.
Packit d37888
 *
Packit d37888
 * Most of the library and all of the sysdeps function also have an alias
Packit d37888
 * (which is the function name without the <suffix>_l</suffix>, 
Packit d37888
 * <suffix>_s</suffix> or <suffix>_r</suffix> suffix) which don't 
Packit d37888
 * take a #glibtop * as argument but uses the #glibtop_global_server 
Packit d37888
 * instead.
Packit d37888
 */
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_init:
Packit d37888
 *
Packit d37888
 * Server initialization.
Packit d37888
 *
Packit d37888
 * Returns: A #glibtop reference.
Packit d37888
 */
Packit d37888
glibtop*
Packit d37888
glibtop_init(void)
Packit d37888
{
Packit d37888
	return glibtop_init_r(&glibtop_global_server, 0, 0);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_cpu:
Packit d37888
 * @buf: A location to return the CPU usage.
Packit d37888
 *
Packit d37888
 * Get the CPU usage.
Packit d37888
 *
Packit d37888
 * All CPU units are measured in <type>jiffies</type> which are normally
Packit d37888
 * 1/100th of a second (in which case <type>frequency</type> equals 100),
Packit d37888
 * but can also be in any other unit. To get seconds, divide them by 
Packit d37888
 * <type>frequency</type>.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_cpu(glibtop_cpu *buf)
Packit d37888
{
Packit d37888
	glibtop_get_cpu_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_fsusage:
Packit d37888
 * @buf: A location to return the file system usage.
Packit d37888
 * @mount_dir: mount dir where to get the information of usage.
Packit d37888
 *
Packit d37888
 * Get the file system usage for an specific @mount_dir.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_fsusage(glibtop_fsusage *buf, const char *mount_dir)
Packit d37888
{
Packit d37888
	glibtop_get_fsusage_l(glibtop_global_server, buf, mount_dir);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_uptime:
Packit d37888
 * @buf: A location to return the system uptime
Packit d37888
 *
Packit d37888
 * When porting LibGTop to a new system, you only need to implement 
Packit d37888
 * #uptime and #idletime if there's a faster or better way to obtain them
Packit d37888
 * as using function(glibtop_cpu) for it. Look at 
Packit d37888
 * <filename>sysdeps/freebsd/uptime.c</filename> for an
Packit d37888
 * example on how to obtain them using function(glibtop_cpu).
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_uptime(glibtop_uptime *buf)
Packit d37888
{
Packit d37888
	glibtop_get_uptime_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_sysinfo:
Packit d37888
 *
Packit d37888
 * Returns: The system information through a #glibtop_sysinfo structure.
Packit d37888
 */
Packit d37888
const glibtop_sysinfo *
Packit d37888
glibtop_get_sysinfo(void)
Packit d37888
{
Packit d37888
	return glibtop_get_sysinfo_s(glibtop_global_server);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_swap:
Packit d37888
 * @buf: A location to return a #glibtop_swap.
Packit d37888
 *
Packit d37888
 * Get the swap usage.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_swap(glibtop_swap *buf)
Packit d37888
{
Packit d37888
	glibtop_get_swap_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proc_uid:
Packit d37888
 * @buf: A location to return a #glibtop_proc_uid
Packit d37888
 * @pid: Process id to get the user and tty information
Packit d37888
 * 
Packit d37888
 * Get the process user id and tty information.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_proc_uid(glibtop_proc_uid *buf, pid_t pid)
Packit d37888
{
Packit d37888
	glibtop_get_proc_uid_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * SECTION:proctime
Packit d37888
 * @title: Process Time
Packit d37888
 * @short_description: Get process time information
Packit d37888
 * @stability: Stable
Packit d37888
 */
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proc_time:
Packit d37888
 * @buf: Returned process time information - see #glibtop_proc_time.
Packit d37888
 * @pid: Process id
Packit d37888
 *
Packit d37888
 * Get process time information.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_proc_time(glibtop_proc_time *buf, pid_t pid)
Packit d37888
{
Packit d37888
	glibtop_get_proc_time_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_proc_state(glibtop_proc_state *buf, pid_t pid)
Packit d37888
{
Packit d37888
	glibtop_get_proc_state_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_proc_signal(glibtop_proc_signal *buf, pid_t pid)
Packit d37888
{
Packit d37888
	glibtop_get_proc_signal_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_proc_segment(glibtop_proc_segment *buf, pid_t pid)
Packit d37888
{
Packit d37888
	glibtop_get_proc_segment_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
glibtop_open_files_entry *
Packit d37888
glibtop_get_proc_open_files(glibtop_proc_open_files *buf, pid_t pid)
Packit d37888
{
Packit d37888
	return glibtop_get_proc_open_files_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_proc_mem(glibtop_proc_mem *buf, pid_t pid)
Packit d37888
{
Packit d37888
	glibtop_get_proc_mem_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
glibtop_map_entry *
Packit d37888
glibtop_get_proc_map(glibtop_proc_map *buf, pid_t pid)
Packit d37888
{
Packit d37888
	return glibtop_get_proc_map_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * SECTION:procargs
Packit d37888
 * @title: Process Arguments
Packit d37888
 * @short_description: Get process command line arguments
Packit d37888
 * @see_also: #libgtop-Process-List
Packit d37888
 * @stability: Stable
Packit d37888
 */
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proc_args:
Packit d37888
 * @buf: Struct with @size of returned string.
Packit d37888
 * @pid: Process id
Packit d37888
 * @max_len: Maximum length of string to return (use zero to get all arguments).
Packit d37888
 *
Packit d37888
 * Get process command line arguments.
Packit d37888
 *
Packit d37888
 * Returns: @pid's command line arguments separated by null bytes; the length of 
Packit d37888
 * this string is returned in the @buf size field.  You are required to free
Packit d37888
 * the string when done.
Packit d37888
 */
Packit d37888
char *
Packit d37888
glibtop_get_proc_args(glibtop_proc_args *buf, pid_t pid, unsigned max_len)
Packit d37888
{
Packit d37888
	return glibtop_get_proc_args_l(glibtop_global_server, buf, pid, max_len);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proc_argv
Packit d37888
 * @buf: Struct with @size of combined returned arguments.
Packit d37888
 * @pid: Process id
Packit d37888
 * @max_len: Maximum length of all arguments combined (use zero to get all arguments).
Packit d37888
 *
Packit d37888
 * Get process command line arguments.
Packit d37888
 *
Packit d37888
 * Returns: A NULL-terminated array of strings with all arguments of process pid
Packit d37888
 * (up to @max_len characters).  Remember to <function>g_strfreev</function>
Packit d37888
 * the returned array to avoid a memory leak.
Packit d37888
 */
Packit d37888
char **
Packit d37888
glibtop_get_proc_argv(glibtop_proc_args *buf, pid_t pid, unsigned max_len)
Packit d37888
{
Packit d37888
	return glibtop_get_proc_argv_l(glibtop_global_server, buf, pid, max_len);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * SECTION:proclist
Packit d37888
 * @title: Process List
Packit d37888
 * @short_description: List running processes
Packit d37888
 * @stability: Stable
Packit d37888
 */
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proclist
Packit d37888
 * @buf: Extra return information, see #glibtop_proclist.
Packit d37888
 * @which: Criteria for processes in returned list.  See the <type>GLIBTOP_KERN_PROC_*</type> and <type>GLIBTOP_EXCLUDE_*</type> constants.
Packit d37888
 * @arg: Extra arguments applied to @which.  Only <type>GLIBTOP_KERN_PROC_*</type> constants take arguments, see each constant definition for particular @arg description.
Packit d37888
 *
Packit d37888
 * Returns: A list of running processes or <type>NULL</type> on error.  The
Packit d37888
 * returned list is allocated using <function>g_malloc</function> and must be
Packit d37888
 * freed using <function>g_free</function> to avoid a memory leak.
Packit d37888
 */
Packit d37888
pid_t*
Packit d37888
glibtop_get_proclist(glibtop_proclist *buf, gint64 which, gint64 arg)
Packit d37888
{
Packit d37888
	return glibtop_get_proclist_l(glibtop_global_server, buf, which, arg);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_proc_kernel(glibtop_proc_kernel *buf, pid_t pid)
Packit d37888
{
Packit d37888
	glibtop_get_proc_kernel_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * SECTION:ppp
Packit d37888
 * @short_description: PPP Usage.
Packit d37888
 * @see_also: #libgtop-netload, #libgtop-netlist
Packit d37888
 * @stability: Stable
Packit d37888
 *
Packit d37888
 * Management of a PPP device.
Packit d37888
 */
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_ppp:
Packit d37888
 * @buf: A location to return the PPP usage
Packit d37888
 * @short device: The device to ask information
Packit d37888
 *
Packit d37888
 * Get the PPP usage.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_ppp(glibtop_ppp *buf, unsigned short device)
Packit d37888
{
Packit d37888
	glibtop_get_ppp_l(glibtop_global_server, buf, device);
Packit d37888
}
Packit d37888
Packit d37888
/**
Packit d37888
 * SECTION:netlist
Packit d37888
 * @short_description: Network Devices List.
Packit d37888
 * @see_also: #libgtop-netload
Packit d37888
 * @stability: Stable
Packit d37888
 *
Packit d37888
 * The application class handles ...
Packit d37888
 */
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_nelist:
Packit d37888
 * @buf:
Packit d37888
 *
Packit d37888
 * Get the list of network devices.
Packit d37888
 *
Packit d37888
 * Returns: A list of network devices.
Packit d37888
 */
Packit d37888
char**
Packit d37888
glibtop_get_netlist(glibtop_netlist *buf)
Packit d37888
{
Packit d37888
	return glibtop_get_netlist_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
/**
Packit d37888
 * SECTION:netload
Packit d37888
 * @short_description: Network Load.
Packit d37888
 * @see_also: #libtop-netlist
Packit d37888
 * @stability: Stable
Packit d37888
 *
Packit d37888
 * The application class handles ...
Packit d37888
 */
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_netload:
Packit d37888
 * @buf: The variable where the results will be assigned.
Packit d37888
 * @interface: The name of the network interface.
Packit d37888
 *
Packit d37888
 * Recolects network statistics for @interface
Packit d37888
 * (which is the same than in <application>ifconfig</application>).  
Packit d37888
 * The values are returned into @buf.
Packit d37888
 */ 
Packit d37888
void
Packit d37888
glibtop_get_netload(glibtop_netload *buf, const char *interface)
Packit d37888
{
Packit d37888
	glibtop_get_netload_l(glibtop_global_server, buf, interface);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
glibtop_mountentry *
Packit d37888
glibtop_get_mountlist(glibtop_mountlist *buf, int all_fs)
Packit d37888
{
Packit d37888
	return glibtop_get_mountlist_l(glibtop_global_server, buf, all_fs);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_mem:
Packit d37888
 * @buf: Buffer where the output will be given.
Packit d37888
 *
Packit d37888
 * Get the memory usage. Unless explicitly stated otherwise, all memory
Packit d37888
 * units are in bytes.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_mem(glibtop_mem *buf)
Packit d37888
{
Packit d37888
	glibtop_get_mem_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_loadavg(glibtop_loadavg *buf)
Packit d37888
{
Packit d37888
	glibtop_get_loadavg_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_msg_limits(glibtop_msg_limits *buf)
Packit d37888
{
Packit d37888
	glibtop_get_msg_limits_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_sem_limits(glibtop_sem_limits *buf)
Packit d37888
{
Packit d37888
	glibtop_get_sem_limits_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_shm_limits(glibtop_shm_limits *buf)
Packit d37888
{
Packit d37888
	glibtop_get_shm_limits_l(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
void
Packit d37888
glibtop_get_sysdeps(glibtop_sysdeps *buf)
Packit d37888
{
Packit d37888
	glibtop_get_sysdeps_r(glibtop_global_server, buf);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proc_wd:
Packit d37888
 * @buf:
Packit d37888
 * @pid: Process id to get the user and tty information
Packit d37888
 *
Packit d37888
 * Get the root directory and the working directories
Packit d37888
 *
Packit d37888
 * Returns: A NULL-terminated list of working directories.
Packit d37888
 */
Packit d37888
char**
Packit d37888
glibtop_get_proc_wd(glibtop_proc_wd *buf, pid_t pid)
Packit d37888
{
Packit d37888
	return glibtop_get_proc_wd_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proc_affinity:
Packit d37888
 * @buf:
Packit d37888
 * @pid: Process id to get the affinity
Packit d37888
 *
Packit d37888
 * Get the processor affinity list for a process
Packit d37888
 *
Packit d37888
 * Returns: A list of processor ID of 'buf.number' elements.
Packit d37888
 */
Packit d37888
guint16 *
Packit d37888
glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid)
Packit d37888
{
Packit d37888
	return glibtop_get_proc_affinity_l(glibtop_global_server, buf, pid);
Packit d37888
}
Packit d37888
Packit d37888
/**
Packit d37888
 * glibtop_get_proc_io: Get the io stats for the given pid
Packit d37888
 * @buf: Buffer where the result will be given
Packit d37888
 * @pid: Process id to get the io stats for
Packit d37888
 *
Packit d37888
 * Get the io stats for a process
Packit d37888
 *
Packit d37888
 * Returns: A list of processor ID of 'buf.number' elements.
Packit d37888
 */
Packit d37888
void
Packit d37888
glibtop_get_proc_io(glibtop_proc_io *buf, pid_t pid)
Packit d37888
{
Packit d37888
	return glibtop_get_proc_io_l(glibtop_global_server, buf, pid);
Packit d37888
}