2006-07-16 01:46:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
|
|
|
* This file is part of SIGAR.
|
|
|
|
*
|
|
|
|
* SIGAR is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation. This program is distributed
|
|
|
|
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
|
|
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
#ifndef SIGAR_OS_H
|
|
|
|
#define SIGAR_OS_H
|
|
|
|
|
2007-02-08 00:32:36 +08:00
|
|
|
#ifndef _POSIX_PTHREAD_SEMANTICS
|
|
|
|
#define _POSIX_PTHREAD_SEMANTICS
|
|
|
|
#endif
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
typedef unsigned long long int u_int64_t;
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
2005-11-10 03:20:44 +08:00
|
|
|
#ifndef DMALLOC
|
2004-06-22 06:37:04 +08:00
|
|
|
#include <malloc.h>
|
2005-11-10 03:20:44 +08:00
|
|
|
#endif
|
2004-06-22 06:37:04 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/processor.h>
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#include <kstat.h>
|
|
|
|
#include <procfs.h>
|
|
|
|
|
2005-03-12 05:30:17 +08:00
|
|
|
#include "get_mib2.h"
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
/* avoid -Wall warning since solaris doesnt have a prototype for this */
|
|
|
|
int getdomainname(char *, int);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
kstat_t **ks;
|
|
|
|
int num;
|
|
|
|
char *name;
|
|
|
|
int nlen;
|
|
|
|
} kstat_list_t;
|
|
|
|
|
2005-12-10 03:24:40 +08:00
|
|
|
SIGAR_INLINE kid_t sigar_kstat_update(sigar_t *sigar);
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
int sigar_get_kstats(sigar_t *sigar);
|
|
|
|
|
|
|
|
int sigar_get_multi_kstats(sigar_t *sigar,
|
|
|
|
kstat_list_t *kl,
|
|
|
|
const char *name,
|
|
|
|
kstat_t **retval);
|
|
|
|
|
|
|
|
void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx);
|
|
|
|
|
|
|
|
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid);
|
|
|
|
|
|
|
|
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid);
|
|
|
|
|
2004-09-05 03:01:44 +08:00
|
|
|
int sigar_proc_status_get(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid);
|
2004-06-22 06:37:04 +08:00
|
|
|
|
|
|
|
#define CPU_ONLINE(n) \
|
|
|
|
(p_online(n, P_STATUS) == P_ONLINE)
|
|
|
|
|
|
|
|
/* loopback interface only has these two metrics */
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_LO_RX_PACKETS,
|
|
|
|
KSTAT_LO_TX_PACKETS,
|
|
|
|
KSTAT_LO_MAX
|
|
|
|
} kstat_lo_off_e;
|
|
|
|
|
|
|
|
/* hme, ge and dmfe network devices provide
|
|
|
|
* the same metrics, but in some cases with
|
|
|
|
* different names and in all cases, the
|
|
|
|
* offsets are different.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_HME_RX_PACKETS,
|
|
|
|
KSTAT_HME_RX_BYTES,
|
|
|
|
KSTAT_HME_RX_ERRORS,
|
|
|
|
KSTAT_HME_RX_DROPPED,
|
|
|
|
KSTAT_HME_RX_OVERRUNS,
|
|
|
|
KSTAT_HME_RX_FRAME,
|
|
|
|
KSTAT_HME_TX_PACKETS,
|
|
|
|
KSTAT_HME_TX_BYTES,
|
|
|
|
KSTAT_HME_TX_ERRORS,
|
|
|
|
KSTAT_HME_TX_DROPPED,
|
|
|
|
KSTAT_HME_TX_OVERRUNS,
|
|
|
|
KSTAT_HME_TX_COLLISIONS,
|
|
|
|
KSTAT_HME_TX_CARRIER,
|
2006-03-07 09:20:58 +08:00
|
|
|
KSTAT_HME_SPEED,
|
2004-06-22 06:37:04 +08:00
|
|
|
KSTAT_HME_MAX
|
|
|
|
} kstat_hme_off_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_DMFE_RX_PACKETS,
|
|
|
|
KSTAT_DMFE_RX_BYTES,
|
|
|
|
KSTAT_DMFE_RX_ERRORS,
|
|
|
|
KSTAT_DMFE_RX_DROPPED,
|
|
|
|
KSTAT_DMFE_RX_OVERRUNS,
|
|
|
|
KSTAT_DMFE_RX_FRAME,
|
|
|
|
KSTAT_DMFE_TX_PACKETS,
|
|
|
|
KSTAT_DMFE_TX_BYTES,
|
|
|
|
KSTAT_DMFE_TX_ERRORS,
|
|
|
|
KSTAT_DMFE_TX_DROPPED,
|
|
|
|
KSTAT_DMFE_TX_OVERRUNS,
|
|
|
|
KSTAT_DMFE_TX_COLLISIONS,
|
|
|
|
KSTAT_DMFE_TX_CARRIER,
|
2006-03-07 09:20:58 +08:00
|
|
|
KSTAT_DMFE_SPEED,
|
2004-06-22 06:37:04 +08:00
|
|
|
KSTAT_DMFE_MAX
|
|
|
|
} kstat_dmfe_off_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_GE_RX_PACKETS,
|
|
|
|
KSTAT_GE_RX_BYTES,
|
|
|
|
KSTAT_GE_RX_ERRORS,
|
|
|
|
KSTAT_GE_RX_DROPPED,
|
|
|
|
KSTAT_GE_RX_OVERRUNS,
|
|
|
|
KSTAT_GE_RX_FRAME,
|
|
|
|
KSTAT_GE_TX_PACKETS,
|
|
|
|
KSTAT_GE_TX_BYTES,
|
|
|
|
KSTAT_GE_TX_ERRORS,
|
|
|
|
KSTAT_GE_TX_DROPPED,
|
|
|
|
KSTAT_GE_TX_OVERRUNS,
|
|
|
|
KSTAT_GE_TX_COLLISIONS,
|
|
|
|
KSTAT_GE_TX_CARRIER,
|
2006-03-07 09:20:58 +08:00
|
|
|
KSTAT_GE_SPEED,
|
2004-06-22 06:37:04 +08:00
|
|
|
KSTAT_GE_MAX
|
|
|
|
} kstat_ge_off_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_ERI_RX_PACKETS,
|
|
|
|
KSTAT_ERI_RX_BYTES,
|
|
|
|
KSTAT_ERI_RX_ERRORS,
|
|
|
|
KSTAT_ERI_RX_DROPPED,
|
|
|
|
KSTAT_ERI_RX_OVERRUNS,
|
|
|
|
KSTAT_ERI_RX_FRAME,
|
|
|
|
KSTAT_ERI_TX_PACKETS,
|
|
|
|
KSTAT_ERI_TX_BYTES,
|
|
|
|
KSTAT_ERI_TX_ERRORS,
|
|
|
|
KSTAT_ERI_TX_DROPPED,
|
|
|
|
KSTAT_ERI_TX_OVERRUNS,
|
|
|
|
KSTAT_ERI_TX_COLLISIONS,
|
|
|
|
KSTAT_ERI_TX_CARRIER,
|
2006-03-07 09:20:58 +08:00
|
|
|
KSTAT_ERI_SPEED,
|
2004-06-22 06:37:04 +08:00
|
|
|
KSTAT_ERI_MAX
|
|
|
|
} kstat_eri_off_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_SYSTEM_BOOT_TIME,
|
|
|
|
KSTAT_SYSTEM_LOADAVG_1,
|
|
|
|
KSTAT_SYSTEM_LOADAVG_2,
|
|
|
|
KSTAT_SYSTEM_LOADAVG_3,
|
|
|
|
KSTAT_SYSTEM_MAX
|
|
|
|
} kstat_system_off_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_MEMPAGES_ANON,
|
|
|
|
KSTAT_MEMPAGES_EXEC,
|
|
|
|
KSTAT_MEMPAGES_VNODE,
|
|
|
|
KSTAT_MEMPAGES_MAX
|
|
|
|
} kstat_mempages_off_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KSTAT_SYSPAGES_FREE,
|
|
|
|
KSTAT_SYSPAGES_MAX
|
|
|
|
} kstat_syspages_off_e;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
KSTAT_KEYS_lo,
|
|
|
|
KSTAT_KEYS_hme,
|
|
|
|
KSTAT_KEYS_dmfe,
|
|
|
|
KSTAT_KEYS_ge,
|
|
|
|
KSTAT_KEYS_eri,
|
|
|
|
KSTAT_KEYS_system,
|
|
|
|
KSTAT_KEYS_mempages,
|
|
|
|
KSTAT_KEYS_syspages,
|
|
|
|
} kstat_keys_e;
|
|
|
|
|
2004-07-06 06:28:31 +08:00
|
|
|
typedef struct ps_prochandle * (*proc_grab_func_t)(pid_t, int, int *);
|
|
|
|
|
2004-07-30 10:15:05 +08:00
|
|
|
typedef void (*proc_free_func_t)(struct ps_prochandle *);
|
2004-07-06 06:28:31 +08:00
|
|
|
|
2004-07-30 10:15:05 +08:00
|
|
|
typedef void (*proc_objname_func_t)(struct ps_prochandle *,
|
|
|
|
uintptr_t, const char *, size_t);
|
2004-07-06 06:28:31 +08:00
|
|
|
|
2004-07-30 09:57:58 +08:00
|
|
|
typedef char * (*proc_dirname_func_t)(const char *, char *, size_t);
|
|
|
|
|
2004-07-30 10:15:05 +08:00
|
|
|
typedef char * (*proc_exename_func_t)(struct ps_prochandle *, char *, size_t);
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
struct sigar_t {
|
|
|
|
SIGAR_T_BASE;
|
|
|
|
|
2004-09-05 06:59:40 +08:00
|
|
|
int solaris_version;
|
2005-12-10 09:01:44 +08:00
|
|
|
int use_ucb_ps;
|
2004-09-05 06:59:40 +08:00
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
kstat_ctl_t *kc;
|
|
|
|
|
|
|
|
/* kstat_lookup() as needed */
|
|
|
|
struct {
|
|
|
|
kstat_t **cpu;
|
2006-05-03 15:02:35 +08:00
|
|
|
kstat_t **cpu_info;
|
2004-06-22 06:37:04 +08:00
|
|
|
processorid_t *cpuid;
|
|
|
|
unsigned int lcpu; /* number malloced slots in the cpu array above */
|
|
|
|
kstat_t *system;
|
|
|
|
kstat_t *syspages;
|
|
|
|
kstat_t *mempages;
|
|
|
|
kstat_list_t hme;
|
|
|
|
kstat_list_t dmfe;
|
|
|
|
kstat_list_t ge;
|
|
|
|
kstat_list_t eri;
|
|
|
|
kstat_list_t lo;
|
|
|
|
} ks;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int lo[KSTAT_LO_MAX];
|
|
|
|
int hme[KSTAT_HME_MAX];
|
|
|
|
int dmfe[KSTAT_DMFE_MAX];
|
|
|
|
int ge[KSTAT_GE_MAX];
|
|
|
|
int eri[KSTAT_ERI_MAX];
|
|
|
|
int system[KSTAT_SYSTEM_MAX];
|
|
|
|
int mempages[KSTAT_MEMPAGES_MAX];
|
|
|
|
int syspages[KSTAT_SYSPAGES_MAX];
|
|
|
|
} koffsets;
|
|
|
|
|
|
|
|
int pagesize;
|
|
|
|
|
|
|
|
time_t last_getprocs;
|
|
|
|
sigar_pid_t last_pid;
|
|
|
|
psinfo_t *pinfo;
|
|
|
|
sigar_cpu_list_t cpulist;
|
2004-07-06 06:28:31 +08:00
|
|
|
|
|
|
|
/* libproc.so interface */
|
|
|
|
void *plib;
|
|
|
|
proc_grab_func_t pgrab;
|
|
|
|
proc_free_func_t pfree;
|
|
|
|
proc_objname_func_t pobjname;
|
2004-07-30 09:57:58 +08:00
|
|
|
proc_dirname_func_t pdirname;
|
2004-07-30 10:15:05 +08:00
|
|
|
proc_exename_func_t pexename;
|
2004-12-07 13:06:03 +08:00
|
|
|
|
|
|
|
sigar_cache_t *fsdev;
|
2005-12-10 10:33:49 +08:00
|
|
|
sigar_cache_t *pargs;
|
2005-03-12 05:30:17 +08:00
|
|
|
|
|
|
|
solaris_mib2_t mib2;
|
2004-06-22 06:37:04 +08:00
|
|
|
};
|
|
|
|
|
2007-01-18 01:19:06 +08:00
|
|
|
#ifdef SIGAR_64BIT
|
|
|
|
#define KSTAT_UINT ui64
|
|
|
|
#else
|
|
|
|
#define KSTAT_UINT ui32
|
|
|
|
#endif
|
|
|
|
|
2007-01-18 02:14:14 +08:00
|
|
|
#define kSTAT_exists(v, type) \
|
|
|
|
(sigar->koffsets.type[v] != -2)
|
|
|
|
|
|
|
|
#define kSTAT_ptr(v, type) \
|
|
|
|
((kstat_named_t *)ksp->ks_data + sigar->koffsets.type[v])
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
#define kSTAT_uint(v, type) \
|
2007-01-18 02:14:14 +08:00
|
|
|
(kSTAT_exists(v, type) ? kSTAT_ptr(v, type)->value.KSTAT_UINT : 0)
|
|
|
|
|
|
|
|
#define kSTAT_ui32(v, type) \
|
|
|
|
(kSTAT_exists(v, type) ? kSTAT_ptr(v, type)->value.ui32 : 0)
|
2004-06-22 06:37:04 +08:00
|
|
|
|
2007-01-18 02:14:14 +08:00
|
|
|
#define kSYSTEM(v) kSTAT_ui32(v, system)
|
2004-06-22 06:37:04 +08:00
|
|
|
|
|
|
|
#define kMEMPAGES(v) kSTAT_uint(v, mempages)
|
|
|
|
|
|
|
|
#define kSYSPAGES(v) kSTAT_uint(v, syspages)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init(sigar, ksp, type) \
|
|
|
|
if (sigar->koffsets.type[0] == -1) \
|
|
|
|
sigar_koffsets_lookup(ksp, sigar->koffsets.type, KSTAT_KEYS_##type)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_lo(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, lo)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_hme(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, hme)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_dmfe(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, dmfe)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_ge(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, ge)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_eri(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, eri)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_system(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, system)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_mempages(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, mempages)
|
|
|
|
|
|
|
|
#define sigar_koffsets_init_syspages(sigar, ksp) \
|
|
|
|
sigar_koffsets_init(sigar, ksp, syspages)
|
|
|
|
|
|
|
|
#define HAVE_READDIR_R
|
|
|
|
#define HAVE_GETPWNAM_R
|
|
|
|
#define HAVE_GETPWUID_R
|
|
|
|
|
2005-03-12 14:22:35 +08:00
|
|
|
#define SIGAR_EMIB2 (SIGAR_OS_START_ERROR+1)
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
#endif /* SIGAR_OS_H */
|
|
|
|
|