sigar/src/os/osf1/osf1_sigar.c

366 lines
7.9 KiB
C
Raw Normal View History

2004-09-06 11:02:04 +08:00
#include "sigar.h"
#include "sigar_private.h"
#include "sigar_os.h"
#include "sigar_util.h"
2004-09-07 10:00:59 +08:00
#include <sys/mount.h>
#include <sys/fs_types.h>
2004-09-06 11:02:04 +08:00
int sigar_os_open(sigar_t **sigar)
{
*sigar = malloc(sizeof(**sigar));
2004-09-06 12:25:29 +08:00
(*sigar)->pagesize = getpagesize();
2004-09-07 00:20:19 +08:00
(*sigar)->boot_time = 0;
2004-09-07 02:14:50 +08:00
(*sigar)->mhz = 0;
2004-09-06 12:25:29 +08:00
2004-09-06 11:02:04 +08:00
return SIGAR_OK;
}
int sigar_os_close(sigar_t *sigar)
{
free(sigar);
return SIGAR_OK;
}
char *sigar_os_error_string(int err)
{
return NULL;
}
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
{
2004-09-06 11:27:05 +08:00
vm_statistics_data_t vmstats;
vm_statistics(task_self(), &vmstats);
mem->free = vmstats.free_count * vmstats.pagesize;
mem->used = vmstats.active_count * vmstats.pagesize;
mem->total =
mem->free + mem->used +
((vmstats.inactive_count + vmstats.wire_count) * vmstats.pagesize);
sigar_mem_calc_ram(sigar, mem);
2004-09-06 11:02:04 +08:00
mem->shared = -1;
mem->buffer = -1;
mem->cached = -1;
return SIGAR_OK;
}
int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
{
2004-09-06 12:25:29 +08:00
struct tbl_swapinfo info;
table(TBL_SWAPINFO, -1, &info, 1, sizeof(info));
swap->total = info.size;
swap->free = info.free;
swap->total *= sigar->pagesize;
swap->free *= sigar->pagesize;
swap->used = swap->total - swap->free;
2004-09-06 11:02:04 +08:00
return SIGAR_OK;
}
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
{
2004-09-07 00:39:54 +08:00
struct tbl_sysinfo sysinfo;
if (table(TBL_SYSINFO, 0, &sysinfo, 1, sizeof(sysinfo)) != 1) {
return errno;
}
cpu->user = sysinfo.si_user;
cpu->nice = sysinfo.si_nice;
cpu->sys = sysinfo.si_sys;
cpu->idle = sysinfo.si_idle;
2004-09-06 11:02:04 +08:00
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
return SIGAR_OK;
}
int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
{
2004-09-07 01:31:48 +08:00
sigar_cpu_t *cpu;
sigar_cpu_list_create(cpulist);
/* XXX multi cpu */
cpu = &cpulist->data[cpulist->number++];
return sigar_cpu_get(sigar, cpu);
2004-09-06 11:02:04 +08:00
}
int sigar_uptime_get(sigar_t *sigar,
sigar_uptime_t *uptime)
{
2004-09-07 00:20:19 +08:00
if (sigar->boot_time == 0) {
struct tbl_sysinfo sysinfo;
if (table(TBL_SYSINFO, 0, &sysinfo, 1, sizeof(sysinfo)) != 1) {
return errno;
}
sigar->boot_time = sysinfo.si_boottime;
}
uptime->uptime = time(NULL) - sigar->boot_time;
2004-09-06 11:02:04 +08:00
return SIGAR_OK;
}
int sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg)
{
2004-09-07 00:14:16 +08:00
int i;
struct tbl_loadavg avg;
if (table(TBL_LOADAVG, 0, &avg, 1, sizeof(avg)) < 0) {
return errno;
}
if (avg.tl_lscale) {
for (i=0; i<3; i++) {
loadavg->loadavg[i] =
((double)avg.tl_avenrun.l[i] /
(double)avg.tl_lscale);
}
}
else {
for (i=0; i<3; i++) {
loadavg->loadavg[i] = avg.tl_avenrun.d[i];
}
}
2004-09-06 11:02:04 +08:00
return SIGAR_OK;
}
int sigar_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist)
{
return SIGAR_ENOTIMPL;
}
int sigar_proc_stat_get(sigar_t *sigar,
sigar_proc_stat_t *procstat)
{
int status = /* XXX optimize */
sigar_proc_count(sigar, &procstat->total);
return status;
}
int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_mem_t *procmem)
{
procmem->size = -1;
procmem->vsize = -1;
procmem->share = -1;
procmem->rss = -1;
procmem->resident = -1;
return SIGAR_OK;
}
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_cred_t *proccred)
{
proccred->uid = -1;
proccred->gid = -1;
proccred->euid = -1;
proccred->egid = -1;
return SIGAR_OK;
}
int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_time_t *proctime)
{
proctime->start_time = -1;
proctime->user = -1;
proctime->sys = -1;
proctime->total = proctime->user + proctime->sys;
return SIGAR_OK;
}
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_state_t *procstate)
{
SIGAR_SSTRCPY(procstate->name, "java");
procstate->ppid = -1;
procstate->priority = -1;
procstate->nice = -1;
procstate->tty = -1;
procstate->state = 'R';
return SIGAR_OK;
}
int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_args_t *procargs)
{
return SIGAR_ENOTIMPL;
}
int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_env_t *procenv)
{
return SIGAR_ENOTIMPL;
}
int sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_fd_t *procfd)
{
procfd->total = -1;
return SIGAR_OK;
}
int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_exe_t *procexe)
{
return SIGAR_ENOTIMPL;
}
int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_modules_t *procmods)
{
return SIGAR_ENOTIMPL;
}
int sigar_os_fs_type_get(sigar_file_system_t *fsp)
{
fsp->type = SIGAR_FSTYPE_UNKNOWN;
return SIGAR_OK;
}
2004-09-07 10:00:59 +08:00
static int sigar_fsstat(struct statfs **fs, int *num)
{
int size;
if ((*num = getfsstat(NULL, 0, MNT_WAIT)) < 0) {
return errno;
}
size = ((*num)+1) * sizeof(struct statfs);
*fs = malloc(size);
if ((*num = getfsstat(*fs, size, MNT_WAIT)) < 0) {
free(fs);
return errno;
}
return SIGAR_OK;
}
2004-09-06 11:02:04 +08:00
int sigar_file_system_list_get(sigar_t *sigar,
sigar_file_system_list_t *fslist)
{
2004-09-07 10:00:59 +08:00
int i, num, status;
struct statfs *fs;
if ((status = sigar_fsstat(&fs, &num)) != SIGAR_OK) {
return status;
}
2004-09-06 11:02:04 +08:00
sigar_file_system_list_create(fslist);
2004-09-07 10:00:59 +08:00
for (i=0; i<num; i++) {
sigar_file_system_t *fsp;
SIGAR_FILE_SYSTEM_LIST_GROW(fslist);
fsp = &fslist->data[fslist->number++];
SIGAR_SSTRCPY(fsp->dir_name, fs[i].f_mntonname);
SIGAR_SSTRCPY(fsp->dev_name, fs[i].f_mntfromname);
SIGAR_SSTRCPY(fsp->sys_type_name, mnt_names[fs[i].f_type]);
sigar_fs_type_init(fsp);
}
free(fs);
2004-09-06 11:02:04 +08:00
return SIGAR_OK;
}
int sigar_file_system_usage_get(sigar_t *sigar,
const char *dirname,
sigar_file_system_usage_t *fsusage)
{
fsusage->total = -1;
fsusage->free = -1;
fsusage->avail = -1;
fsusage->files = -1;
fsusage->free_files = -1;
return SIGAR_OK;
}
int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos)
{
sigar_cpu_info_t *info;
2004-09-07 02:14:50 +08:00
if (sigar->mhz == 0) {
struct tbl_sysinfo sysinfo;
if (table(TBL_SYSINFO, 0, &sysinfo, 1, sizeof(sysinfo)) != 1) {
return errno;
}
sigar->mhz = sysinfo.si_hz;
}
2004-09-06 11:02:04 +08:00
sigar_cpu_info_list_create(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++];
2004-09-07 02:14:50 +08:00
SIGAR_SSTRCPY(info->vendor, "DEC");
SIGAR_SSTRCPY(info->model, "alpha");
info->mhz = sigar->mhz;
2004-09-06 11:02:04 +08:00
info->cache_size = -1;
return SIGAR_OK;
}
int sigar_net_route_list_get(sigar_t *sigar,
sigar_net_route_list_t *routelist)
{
return SIGAR_ENOTIMPL;
}
int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat)
{
ifstat->rx_bytes = -1;
ifstat->rx_packets = -1;
ifstat->rx_errors = -1;
ifstat->rx_dropped = -1;
ifstat->rx_overruns = -1;
ifstat->rx_frame = -1;
ifstat->tx_bytes = -1;
ifstat->tx_packets = -1;
ifstat->tx_errors = -1;
ifstat->tx_dropped = -1;
ifstat->tx_overruns = -1;
ifstat->tx_collisions = -1;
ifstat->tx_carrier = -1;
return SIGAR_OK;
}
int sigar_net_connection_list_get(sigar_t *sigar,
sigar_net_connection_list_t *connlist,
int flags)
{
return SIGAR_ENOTIMPL;
}