Initial revision

This commit is contained in:
Doug MacEachern committed 2004-06-21 22:37:04 +00:00
1 parent 1a7957fb1e
commit dffe0da855
207 files changed
+34390

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
/*
* from sys/hme.h, private to _KERNEL.
* we should be ok provided ksp->ks_data_size == sizeof(struct hmekstat)
* else will need to fallback to using kstat_data_lookup.
*/
struct hmekstat {
struct kstat_named hk_ipackets; /* packets received */
struct kstat_named hk_ierrors; /* input errors */
struct kstat_named hk_opackets; /* packets transmitted */
struct kstat_named hk_oerrors; /* output errors */
struct kstat_named hk_coll; /* collisions encountered */
struct kstat_named hk_defer; /* slots deferred */
struct kstat_named hk_fram; /* framing errors */
struct kstat_named hk_crc; /* crc errors */
struct kstat_named hk_sqerr; /* SQE test errors */
struct kstat_named hk_cvc; /* code violation errors */
struct kstat_named hk_lenerr; /* rx len errors */
struct kstat_named hk_ifspeed; /* interface speed */
struct kstat_named hk_buff; /* buff errors */
struct kstat_named hk_oflo; /* overflow errors */
struct kstat_named hk_uflo; /* underflow errors */
struct kstat_named hk_missed; /* missed/dropped packets */
struct kstat_named hk_tlcol; /* late collisions */
struct kstat_named hk_trtry; /* retry errors */
struct kstat_named hk_fstcol; /* first collisions */
struct kstat_named hk_tnocar; /* no carrier */
struct kstat_named hk_inits; /* initialization */
struct kstat_named hk_nocanput; /* nocanput errors */
struct kstat_named hk_allocbfail; /* allocb failures */
struct kstat_named hk_runt; /* runt errors */
struct kstat_named hk_jab; /* jabber errors */
struct kstat_named hk_babl; /* runt errors */
struct kstat_named hk_tmder; /* tmd errors */
struct kstat_named hk_txlaterr; /* tx late errors */
struct kstat_named hk_rxlaterr; /* rx late errors */
struct kstat_named hk_slvparerr; /* slave parity errors */
struct kstat_named hk_txparerr; /* tx parity errors */
struct kstat_named hk_rxparerr; /* rx parity errors */
struct kstat_named hk_slverrack; /* slave error acks */
struct kstat_named hk_txerrack; /* tx error acks */
struct kstat_named hk_rxerrack; /* rx error acks */
struct kstat_named hk_txtagerr; /* tx tag error */
struct kstat_named hk_rxtagerr; /* rx tag error */
struct kstat_named hk_eoperr; /* eop error */
struct kstat_named hk_notmds; /* tmd errors */
struct kstat_named hk_notbufs; /* tx buf errors */
struct kstat_named hk_norbufs; /* rx buf errors */
struct kstat_named hk_clsn; /* clsn errors */
/*
* required by kstat for MIB II objects(RFC 1213)
*/
struct kstat_named hk_rcvbytes; /* # octets received */
/* MIB - ifInOctets */
struct kstat_named hk_xmtbytes; /* # octets transmitted */
/* MIB - ifOutOctets */
struct kstat_named hk_multircv; /* # multicast packets */
/* delivered to upper layer */
/* MIB - ifInNUcastPkts */
struct kstat_named hk_multixmt; /* # multicast packets */
/* requested to be sent */
/* MIB - ifOutNUcastPkts */
struct kstat_named hk_brdcstrcv; /* # broadcast packets */
/* delivered to upper layer */
/* MIB - ifInNUcastPkts */
struct kstat_named hk_brdcstxmt; /* # broadcast packets */
/* requested to be sent */
/* MIB - ifOutNUcastPkts */
struct kstat_named hk_norcvbuf; /* # rcv packets discarded */
/* MIB - ifInDiscards */
struct kstat_named hk_noxmtbuf; /* # xmt packets discarded */
/* MIB - ifOutDiscards */
struct kstat_named hk_phyfail; /* phy failures */
struct kstat_named hk_link_up; /* Link Status */
};
+255
View File
@@ -0,0 +1,255 @@
#include "sigar.h"
#include "sigar_private.h"
#include "sigar_os.h"
#include "sigar_util.h"
int sigar_get_multi_kstats(sigar_t *sigar,
kstat_list_t *kl,
const char *name,
kstat_t **retval)
{
kstat_ctl_t *kc = sigar->kc;
kstat_t *ksp;
int i = 0;
int dev;
name += kl->nlen; /* e.g. "hme0" + 3 */
dev = atoi(name);
if ((kl->num == 0) || (kstat_chain_update(kc) > 0)) {
while ((ksp = kstat_lookup(kc, kl->name, i, NULL))) {
if (i+1 > kl->num) {
kl->num = i+1;
kl->ks = realloc(kl->ks, kl->num);
}
kl->ks[i] = ksp;
i++;
}
}
if (dev >= kl->num) {
return ENXIO;
}
*retval = kl->ks[dev];
return SIGAR_OK;
}
int sigar_get_kstats(sigar_t *sigar)
{
kstat_ctl_t *kc = sigar->kc;
kstat_t *ksp;
unsigned int i, ncpu = sysconf(_SC_NPROCESSORS_CONF);
ksp = kstat_lookup(kc, "unix", -1, "vminfo");
sigar->ks.vminfo = ksp;
if (ksp) {
kstat_read(kc, ksp, &sigar->vminfo);
if (!sigar->vminfo_snaptime) {
sigar->vminfo_snaptime = ksp->ks_snaptime;
}
}
if (ncpu != sigar->ncpu) {
if (!sigar->ks.lcpu) {
/* init */
sigar->ks.lcpu = ncpu;
sigar->ks.cpu = malloc(sizeof(*(sigar->ks.cpu)) * ncpu);
sigar->ks.cpuid = malloc(sizeof(*(sigar->ks.cpuid)) * ncpu);
}
else {
if (ncpu > sigar->ks.lcpu) {
/* one or more cpus have been added */
sigar->ks.cpu = realloc(sigar->ks.cpu,
sizeof(*(sigar->ks.cpu)) * ncpu);
sigar->ks.cpuid = realloc(sigar->ks.cpuid,
sizeof(*(sigar->ks.cpuid)) * ncpu);
sigar->ks.lcpu = ncpu;
}
/* else or more cpus have been removed */
}
sigar->ncpu = ncpu;
for (i=0, ksp=kc->kc_chain; i<ncpu; ksp=ksp->ks_next) {
char *id;
if (!ksp) {
break;
}
if (strncmp(ksp->ks_name, "cpu_stat", 8)) {
continue;
}
/* from man p_online:
* ``Processor numbers are integers,
* greater than or equal to 0,
* and are defined by the hardware platform.
* Processor numbers are not necessarily contiguous,
* but "not too sparse."``
* so we maintain our own mapping in ks.cpuid[]
*/
id = ksp->ks_name;
while (!sigar_isdigit(*id)) {
id++;
}
sigar->ks.cpu[i] = ksp;
sigar->ks.cpuid[i] = atoi(id);
i++;
}
}
sigar->ks.system = kstat_lookup(kc, "unix", -1, "system_misc");
sigar->ks.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
sigar->ks.mempages = kstat_lookup(kc, "bunyip", -1, "mempages");
return SIGAR_OK;
}
/*
* bincompat is not possible with certain kstat data structures between
* solaris 2.6, 2.7, 2.8, etc. alternative is to use kstat_data_lookup()
* which means everytime we want a stat, must do a linear search
* of ksp->ks_data. eek. so we meet half way and do the search for
* each key once per sigar_t instance. once the initial search has
* been done, we have a table of offsets to quickly access the stats via
* ksp->ks_data + offset. this gives us bincompat without the overhead
* of many kstat_data_lookup calls.
*/
static SIGAR_INLINE int kstat_named_offset(kstat_t *ksp, const char *name)
{
unsigned int i;
kstat_named_t *kn;
for (i=0, kn=ksp->ks_data;
i<ksp->ks_ndata;
i++, kn++)
{
if (strEQ(kn->name, name)) {
return i;
}
}
return -2; /* not found */
}
static char *kstat_keys_lo[] = {
"ipackets", /* RX_PACKETS */
"opackets", /* TX_PACKETS */
NULL
};
static char *kstat_keys_hme[] = {
"ipackets", /* RX_PACKETS */
"rbytes", /* RX_BYTES */
"ierrors", /* RX_ERRORS */
"missed", /* RX_DROPPED */
"oflo", /* RX_OVERRUNS */
"framing", /* RX_FRAME */
"opackets", /* TX_PACKETS */
"obytes", /* TX_BYTES */
"oerrors", /* TX_ERRORS */
"missed", /* TX_DROPPED */
"oflo", /* TX_OVERRUNS */
"collisions", /* TX_COLLISIONS */
"nocarrier", /* TX_CARRIER */
NULL
};
static char *kstat_keys_dmfe[] = {
"ipackets", /* RX_PACKETS */
"rbytes", /* RX_BYTES */
"ierrors", /* RX_ERRORS */
"missed", /* RX_DROPPED */
"oflo", /* RX_OVERRUNS */
"framing", /* RX_FRAME */
"opackets", /* TX_PACKETS */
"obytes", /* TX_BYTES */
"oerrors", /* TX_ERRORS */
"missed", /* TX_DROPPED */
"oflo", /* TX_OVERRUNS */
"collisions", /* TX_COLLISIONS */
"nocarrier", /* TX_CARRIER */
NULL
};
static char *kstat_keys_ge[] = {
"ipackets", /* RX_PACKETS */
"rbytes", /* RX_BYTES */
"ierrors", /* RX_ERRORS */
"drop", /* RX_DROPPED */
"toolong_errors", /* RX_OVERRUNS */
"framing", /* RX_FRAME */
"opackets", /* TX_PACKETS */
"obytes", /* TX_BYTES */
"oerrors", /* TX_ERRORS */
"drop", /* TX_DROPPED */
"toolong_errors", /* TX_OVERRUNS */
"collisions", /* TX_COLLISIONS */
"nocarrier", /* TX_CARRIER */
NULL
};
static char *kstat_keys_eri[] = {
"ipackets", /* RX_PACKETS */
"rbytes", /* RX_BYTES */
"ierrors", /* RX_ERRORS */
"drop", /* RX_DROPPED */
"rx_overflow", /* RX_OVERRUNS */
"parity_error", /* RX_FRAME */
"opackets", /* TX_PACKETS */
"obytes", /* TX_BYTES */
"oerrors", /* TX_ERRORS */
"drop", /* TX_DROPPED */
"rx_overflow", /* TX_OVERRUNS */
"collisions", /* TX_COLLISIONS */
"nocarrier", /* TX_CARRIER */
NULL
};
static char *kstat_keys_system[] = {
"boot_time",
"avenrun_1min",
"avenrun_5min",
"avenrun_15min",
NULL
};
static char *kstat_keys_mempages[] = {
"pages_anon",
"pages_exec",
"pages_vnode",
NULL
};
static char *kstat_keys_syspages[] = {
"pagesfree",
NULL
};
static char **kstat_keys[] = {
kstat_keys_lo,
kstat_keys_hme,
kstat_keys_dmfe,
kstat_keys_ge,
kstat_keys_eri,
kstat_keys_system,
kstat_keys_mempages,
kstat_keys_syspages,
};
void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx)
{
int i;
char **keys = kstat_keys[kidx];
for (i=0; keys[i]; i++) {
offsets[i] = kstat_named_offset(ksp, keys[i]);
}
}
+101
View File
@@ -0,0 +1,101 @@
#include "sigar.h"
#include "sigar_private.h"
#include "sigar_os.h"
#include "sigar_util.h"
#define my_pread(fd, ptr, type, offset) \
(pread(fd, ptr, sizeof(type), offset) == sizeof(type))
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid)
{
int fd, retval = SIGAR_OK;
char buffer[BUFSIZ];
time_t timenow = time(NULL);
if (sigar->pinfo == NULL) {
sigar->pinfo = malloc(sizeof(*sigar->pinfo));
}
if (sigar->last_pid == pid) {
if ((timenow - sigar->last_getprocs) < SIGAR_LAST_PROC_EXPIRE) {
return SIGAR_OK;
}
}
sigar->last_pid = pid;
sigar->last_getprocs = timenow;
(void)SIGAR_PROC_FILENAME(buffer, pid, "/psinfo");
if ((fd = open(buffer, O_RDONLY)) < 0) {
return ESRCH;
}
if (!my_pread(fd, sigar->pinfo, psinfo_t, 0)) {
retval = errno;
}
close(fd);
return retval;
}
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid)
{
int fd, retval = SIGAR_OK;
char buffer[BUFSIZ];
(void)SIGAR_PROC_FILENAME(buffer, pid, "/usage");
if ((fd = open(buffer, O_RDONLY)) < 0) {
return ESRCH;
}
if (!my_pread(fd, prusage, prusage_t, 0)) {
retval = errno;
}
close(fd);
return retval;
}
int sigar_get_cred_get(sigar_t *sigar, prcred_t *prcred, sigar_pid_t pid)
{
int fd, retval = SIGAR_OK;
char buffer[BUFSIZ];
(void)SIGAR_PROC_FILENAME(buffer, pid, "/cred");
if ((fd = open(buffer, O_RDONLY)) < 0) {
return ESRCH;
}
if (!my_pread(fd, prcred, prcred_t, 0)) {
retval = errno;
}
close(fd);
return retval;
}
int sigar_get_proc_status(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid)
{
int fd, retval = SIGAR_OK;
char buffer[BUFSIZ];
(void)SIGAR_PROC_FILENAME(buffer, pid, "/status");
if ((fd = open(buffer, O_RDONLY)) < 0) {
return ESRCH;
}
if (!my_pread(fd, pstatus, pstatus_t, 0)) {
retval = errno;
}
close(fd);
return retval;
}
+249
View File
@@ -0,0 +1,249 @@
#ifndef SIGAR_OS_H
#define SIGAR_OS_H
typedef unsigned long long int u_int64_t;
#include <ctype.h>
#include <assert.h>
#include <malloc.h>
#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>
/* 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;
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);
int sigar_get_cred_get(sigar_t *sigar, prcred_t *prcred, sigar_pid_t pid);
int sigar_get_proc_status(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid);
#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,
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,
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,
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,
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;
struct sigar_t {
SIGAR_T_BASE;
kstat_ctl_t *kc;
/* kstat_lookup() as needed */
struct {
kstat_t *vminfo;
kstat_t **cpu;
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;
vminfo_t vminfo;
hrtime_t vminfo_snaptime;
int pagesize;
time_t last_getprocs;
sigar_pid_t last_pid;
psinfo_t *pinfo;
sigar_cpu_list_t cpulist;
};
#define kSTAT_uint(v, type) \
((sigar->koffsets.type[v] == -2) ? 0 : \
((kstat_named_t *)ksp->ks_data + sigar->koffsets.type[v])->value.ui32)
#define kSYSTEM(v) kSTAT_uint(v, system)
#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
#endif /* SIGAR_OS_H */
File diff suppressed because it is too large. Load diff