Merge branch 'sigar-1.6'

This commit is contained in:
Doug MacEachern 2009-07-02 13:58:29 -07:00
commit a19c5a3454
3 changed files with 54 additions and 519 deletions

View File

@ -21,84 +21,6 @@
#include "sigar_util.h" #include "sigar_util.h"
#include "sigar_os.h" #include "sigar_os.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;
kid_t id = sigar_kstat_update(sigar);
if (id == -1) {
return errno;
}
name += kl->nlen; /* e.g. "hme0" + 3 */
dev = atoi(name);
if ((kl->num == 0) || (id > 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 * sizeof(*kl->ks));
}
kl->ks[i] = ksp;
i++;
}
}
if (dev >= kl->num) {
return ENXIO;
}
*retval = kl->ks[dev];
return SIGAR_OK;
}
#define KSTAT_LIST_INIT(sigar, dev) \
sigar->koffsets.dev[0] = -1; \
sigar->ks.dev.num = 0; \
sigar->ks.dev.ks = NULL; \
sigar->ks.dev.name = #dev; \
sigar->ks.dev.nlen = sizeof(#dev)-1
void sigar_init_multi_kstats(sigar_t *sigar)
{
KSTAT_LIST_INIT(sigar, lo);
KSTAT_LIST_INIT(sigar, hme);
KSTAT_LIST_INIT(sigar, dmfe);
KSTAT_LIST_INIT(sigar, ge);
KSTAT_LIST_INIT(sigar, eri);
}
void sigar_free_multi_kstats(sigar_t *sigar)
{
if (sigar->ks.lo.num) {
free(sigar->ks.lo.ks);
KSTAT_LIST_INIT(sigar, lo);
}
if (sigar->ks.hme.num) {
free(sigar->ks.hme.ks);
KSTAT_LIST_INIT(sigar, hme);
}
if (sigar->ks.dmfe.num) {
free(sigar->ks.dmfe.ks);
KSTAT_LIST_INIT(sigar, dmfe);
}
if (sigar->ks.ge.num) {
free(sigar->ks.ge.ks);
KSTAT_LIST_INIT(sigar, ge);
}
if (sigar->ks.eri.num) {
free(sigar->ks.eri.ks);
KSTAT_LIST_INIT(sigar, eri);
}
}
int sigar_get_kstats(sigar_t *sigar) int sigar_get_kstats(sigar_t *sigar)
{ {
kstat_ctl_t *kc = sigar->kc; kstat_ctl_t *kc = sigar->kc;
@ -169,9 +91,6 @@ int sigar_get_kstats(sigar_t *sigar)
sigar->ks.syspages = kstat_lookup(kc, "unix", -1, "system_pages"); sigar->ks.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
sigar->ks.mempages = kstat_lookup(kc, "bunyip", -1, "mempages"); sigar->ks.mempages = kstat_lookup(kc, "bunyip", -1, "mempages");
/* reset offsets on kstat_chain_update */
sigar_free_multi_kstats(sigar);
return SIGAR_OK; return SIGAR_OK;
} }
@ -225,84 +144,6 @@ static SIGAR_INLINE int kstat_named_offset(kstat_t *ksp, const char *name)
return -2; /* not found */ 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 */
"ifspeed", /* SPEED */
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 */
"ifspeed", /* SPEED */
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 */
"ifspeed", /* SPEED */
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 */
"ifspeed", /* SPEED */
NULL
};
static char *kstat_keys_system[] = { static char *kstat_keys_system[] = {
"boot_time", "boot_time",
"avenrun_1min", "avenrun_1min",
@ -324,11 +165,6 @@ static char *kstat_keys_syspages[] = {
}; };
static char **kstat_keys[] = { static char **kstat_keys[] = {
kstat_keys_lo,
kstat_keys_hme,
kstat_keys_dmfe,
kstat_keys_ge,
kstat_keys_eri,
kstat_keys_system, kstat_keys_system,
kstat_keys_mempages, kstat_keys_mempages,
kstat_keys_syspages, kstat_keys_syspages,

View File

@ -79,90 +79,6 @@ int sigar_proc_status_get(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid);
#define CPU_ONLINE(n) \ #define CPU_ONLINE(n) \
(p_online(n, P_STATUS) == P_ONLINE) (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_SPEED,
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_SPEED,
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_SPEED,
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_SPEED,
KSTAT_ERI_MAX
} kstat_eri_off_e;
typedef enum { typedef enum {
KSTAT_SYSTEM_BOOT_TIME, KSTAT_SYSTEM_BOOT_TIME,
KSTAT_SYSTEM_LOADAVG_1, KSTAT_SYSTEM_LOADAVG_1,
@ -184,11 +100,6 @@ typedef enum {
} kstat_syspages_off_e; } kstat_syspages_off_e;
enum { enum {
KSTAT_KEYS_lo,
KSTAT_KEYS_hme,
KSTAT_KEYS_dmfe,
KSTAT_KEYS_ge,
KSTAT_KEYS_eri,
KSTAT_KEYS_system, KSTAT_KEYS_system,
KSTAT_KEYS_mempages, KSTAT_KEYS_mempages,
KSTAT_KEYS_syspages, KSTAT_KEYS_syspages,
@ -234,19 +145,9 @@ struct sigar_t {
kstat_t *system; kstat_t *system;
kstat_t *syspages; kstat_t *syspages;
kstat_t *mempages; kstat_t *mempages;
kstat_list_t hme;
kstat_list_t dmfe;
kstat_list_t ge;
kstat_list_t eri;
kstat_list_t lo;
} ks; } ks;
struct { 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 system[KSTAT_SYSTEM_MAX];
int mempages[KSTAT_MEMPAGES_MAX]; int mempages[KSTAT_MEMPAGES_MAX];
int syspages[KSTAT_SYSPAGES_MAX]; int syspages[KSTAT_SYSPAGES_MAX];
@ -305,21 +206,6 @@ struct sigar_t {
if (sigar->koffsets.type[0] == -1) \ if (sigar->koffsets.type[0] == -1) \
sigar_koffsets_lookup(ksp, sigar->koffsets.type, KSTAT_KEYS_##type) 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) \ #define sigar_koffsets_init_system(sigar, ksp) \
sigar_koffsets_init(sigar, ksp, system) sigar_koffsets_init(sigar, ksp, system)

View File

@ -118,8 +118,6 @@ int sigar_os_open(sigar_t **sig)
sigar->koffsets.mempages[0] = -1; sigar->koffsets.mempages[0] = -1;
sigar->koffsets.syspages[0] = -1; sigar->koffsets.syspages[0] = -1;
sigar_init_multi_kstats(sigar);
if ((status = sigar_get_kstats(sigar)) != SIGAR_OK) { if ((status = sigar_get_kstats(sigar)) != SIGAR_OK) {
fprintf(stderr, "status=%d\n", status); fprintf(stderr, "status=%d\n", status);
} }
@ -154,8 +152,6 @@ int sigar_os_close(sigar_t *sigar)
{ {
kstat_close(sigar->kc); kstat_close(sigar->kc);
sigar_free_multi_kstats(sigar);
if (sigar->ks.lcpu) { if (sigar->ks.lcpu) {
free(sigar->ks.cpu); free(sigar->ks.cpu);
free(sigar->ks.cpu_info); free(sigar->ks.cpu_info);
@ -1923,207 +1919,6 @@ int sigar_net_route_list_get(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
#define kHME(v) kSTAT_uint(v, hme)
static int sigar_net_ifstat_get_hme(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat)
{
kstat_ctl_t *kc = sigar->kc;
kstat_t *ksp;
int status;
status = sigar_get_multi_kstats(sigar, &sigar->ks.hme,
name, &ksp);
if (status != SIGAR_OK) {
return status;
}
kstat_read(kc, ksp, NULL);
sigar_koffsets_init_hme(sigar, ksp);
ifstat->rx_packets = kHME(KSTAT_HME_RX_PACKETS);
ifstat->rx_bytes = kHME(KSTAT_HME_RX_BYTES);
ifstat->rx_errors = kHME(KSTAT_HME_RX_ERRORS);
ifstat->rx_dropped = kHME(KSTAT_HME_RX_DROPPED); /*XXX*/
ifstat->rx_overruns = kHME(KSTAT_HME_RX_OVERRUNS); /*XXX*/
ifstat->rx_frame = kHME(KSTAT_HME_RX_FRAME);
ifstat->tx_packets = kHME(KSTAT_HME_TX_PACKETS);
ifstat->tx_bytes = kHME(KSTAT_HME_TX_BYTES);
ifstat->tx_errors = kHME(KSTAT_HME_TX_ERRORS);
ifstat->tx_dropped = kHME(KSTAT_HME_TX_DROPPED); /*XXX*/
ifstat->tx_overruns = kHME(KSTAT_HME_TX_OVERRUNS); /*XXX*/
ifstat->tx_collisions = kHME(KSTAT_HME_TX_COLLISIONS);
ifstat->tx_carrier = kHME(KSTAT_HME_TX_CARRIER);
ifstat->speed = kHME(KSTAT_HME_SPEED);
return SIGAR_OK;
}
#define kDMFE(v) kSTAT_uint(v, dmfe)
static int sigar_net_ifstat_get_dmfe(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat)
{
kstat_ctl_t *kc = sigar->kc;
kstat_t *ksp;
int status;
status = sigar_get_multi_kstats(sigar, &sigar->ks.dmfe,
name, &ksp);
if (status != SIGAR_OK) {
return status;
}
kstat_read(kc, ksp, NULL);
sigar_koffsets_init_dmfe(sigar, ksp);
ifstat->rx_packets = kDMFE(KSTAT_DMFE_RX_PACKETS);
ifstat->rx_bytes = kDMFE(KSTAT_DMFE_RX_BYTES);
ifstat->rx_errors = kDMFE(KSTAT_DMFE_RX_ERRORS);
ifstat->rx_dropped = kDMFE(KSTAT_DMFE_RX_DROPPED); /*XXX*/
ifstat->rx_overruns = kDMFE(KSTAT_DMFE_RX_OVERRUNS); /*XXX*/
ifstat->rx_frame = kDMFE(KSTAT_DMFE_RX_FRAME);
ifstat->tx_packets = kDMFE(KSTAT_DMFE_TX_PACKETS);
ifstat->tx_bytes = kDMFE(KSTAT_DMFE_TX_BYTES);
ifstat->tx_errors = kDMFE(KSTAT_DMFE_TX_ERRORS);
ifstat->tx_dropped = kDMFE(KSTAT_DMFE_TX_DROPPED); /*XXX*/
ifstat->tx_overruns = kDMFE(KSTAT_DMFE_TX_OVERRUNS); /*XXX*/
ifstat->tx_collisions = kDMFE(KSTAT_DMFE_TX_COLLISIONS);
ifstat->tx_carrier = kDMFE(KSTAT_DMFE_TX_CARRIER);
ifstat->speed = kDMFE(KSTAT_DMFE_SPEED);
return SIGAR_OK;
}
#define kGE(v) kSTAT_uint(v, ge)
static int sigar_net_ifstat_get_ge(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat)
{
kstat_ctl_t *kc = sigar->kc;
kstat_t *ksp;
int status;
status = sigar_get_multi_kstats(sigar, &sigar->ks.ge,
name, &ksp);
if (status != SIGAR_OK) {
return status;
}
kstat_read(kc, ksp, NULL);
sigar_koffsets_init_ge(sigar, ksp);
ifstat->rx_packets = kGE(KSTAT_GE_RX_PACKETS);
ifstat->rx_bytes = kGE(KSTAT_GE_RX_BYTES);
ifstat->rx_errors = kGE(KSTAT_GE_RX_ERRORS);
ifstat->rx_dropped = kGE(KSTAT_GE_RX_DROPPED); /*XXX*/
ifstat->rx_overruns = kGE(KSTAT_GE_RX_OVERRUNS); /*XXX*/
ifstat->rx_frame = kGE(KSTAT_GE_RX_FRAME);
ifstat->tx_packets = kGE(KSTAT_GE_TX_PACKETS);
ifstat->tx_bytes = kGE(KSTAT_GE_TX_BYTES);
ifstat->tx_errors = kGE(KSTAT_GE_TX_ERRORS);
ifstat->tx_dropped = kGE(KSTAT_GE_TX_DROPPED); /*XXX*/
ifstat->tx_overruns = kGE(KSTAT_GE_TX_OVERRUNS); /*XXX*/
ifstat->tx_collisions = kGE(KSTAT_GE_TX_COLLISIONS);
ifstat->tx_carrier = kGE(KSTAT_GE_TX_CARRIER);
ifstat->speed = kGE(KSTAT_GE_SPEED);
return SIGAR_OK;
}
#define kERI(v) kSTAT_uint(v, eri)
static int sigar_net_ifstat_get_eri(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat)
{
kstat_ctl_t *kc = sigar->kc;
kstat_t *ksp;
int status;
status = sigar_get_multi_kstats(sigar, &sigar->ks.eri,
name, &ksp);
if (status != SIGAR_OK) {
return status;
}
kstat_read(kc, ksp, NULL);
sigar_koffsets_init_eri(sigar, ksp);
ifstat->rx_packets = kERI(KSTAT_ERI_RX_PACKETS);
ifstat->rx_bytes = kERI(KSTAT_ERI_RX_BYTES);
ifstat->rx_errors = kERI(KSTAT_ERI_RX_ERRORS);
ifstat->rx_dropped = kERI(KSTAT_ERI_RX_DROPPED); /*XXX*/
ifstat->rx_overruns = kERI(KSTAT_ERI_RX_OVERRUNS); /*XXX*/
ifstat->rx_frame = kERI(KSTAT_ERI_RX_FRAME);
ifstat->tx_packets = kERI(KSTAT_ERI_TX_PACKETS);
ifstat->tx_bytes = kERI(KSTAT_ERI_TX_BYTES);
ifstat->tx_errors = kERI(KSTAT_ERI_TX_ERRORS);
ifstat->tx_dropped = kERI(KSTAT_ERI_TX_DROPPED); /*XXX*/
ifstat->tx_overruns = kERI(KSTAT_ERI_TX_OVERRUNS); /*XXX*/
ifstat->tx_collisions = kERI(KSTAT_ERI_TX_COLLISIONS);
ifstat->tx_carrier = kERI(KSTAT_ERI_TX_CARRIER);
ifstat->speed = kERI(KSTAT_ERI_SPEED);
return SIGAR_OK;
}
#define kLO(v) kSTAT_uint(v, lo)
#define jLO aHO
static int sigar_net_ifstat_get_lo(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat)
{
kstat_ctl_t *kc = sigar->kc;
kstat_t *ksp;
int status;
status = sigar_get_multi_kstats(sigar, &sigar->ks.lo,
name, &ksp);
if (status != SIGAR_OK) {
return status;
}
kstat_read(kc, ksp, NULL);
sigar_koffsets_init_lo(sigar, ksp);
ifstat->rx_packets = kLO(KSTAT_LO_RX_PACKETS);
ifstat->rx_bytes = SIGAR_FIELD_NOTIMPL;
ifstat->rx_errors = SIGAR_FIELD_NOTIMPL;
ifstat->rx_dropped = SIGAR_FIELD_NOTIMPL;
ifstat->rx_overruns = SIGAR_FIELD_NOTIMPL;
ifstat->rx_frame = SIGAR_FIELD_NOTIMPL;
ifstat->tx_packets = kLO(KSTAT_LO_TX_PACKETS);
ifstat->tx_bytes = SIGAR_FIELD_NOTIMPL;
ifstat->tx_errors = SIGAR_FIELD_NOTIMPL;
ifstat->tx_dropped = SIGAR_FIELD_NOTIMPL;
ifstat->tx_overruns = SIGAR_FIELD_NOTIMPL;
ifstat->tx_collisions = SIGAR_FIELD_NOTIMPL;
ifstat->tx_carrier = SIGAR_FIELD_NOTIMPL;
ifstat->speed = SIGAR_FIELD_NOTIMPL;
return SIGAR_OK;
}
static void ifstat_kstat_common(sigar_net_interface_stat_t *ifstat, static void ifstat_kstat_common(sigar_net_interface_stat_t *ifstat,
kstat_named_t *data, int ndata) kstat_named_t *data, int ndata)
{ {
@ -2148,7 +1943,12 @@ static void ifstat_kstat_common(sigar_net_interface_stat_t *ifstat,
break; break;
case 'i': case 'i':
if (strEQ(ptr, "ipackets")) { if (strEQ(ptr, "ipackets")) {
ifstat->rx_packets = value; if (ifstat->rx_packets == 0) {
ifstat->rx_packets = value;
}
}
else if (strEQ(ptr, "ipackets64")) {
ifstat->rx_packets = data[i].value.ui64;
} }
else if (strEQ(ptr, "ierrors")) { else if (strEQ(ptr, "ierrors")) {
ifstat->rx_errors = value; ifstat->rx_errors = value;
@ -2175,7 +1975,12 @@ static void ifstat_kstat_common(sigar_net_interface_stat_t *ifstat,
break; break;
case 'o': case 'o':
if (strEQ(ptr, "obytes")) { if (strEQ(ptr, "obytes")) {
ifstat->tx_bytes = value; if (ifstat->tx_bytes == 0) {
ifstat->tx_bytes = value;
}
}
else if (strEQ(ptr, "obytes64")) {
ifstat->tx_bytes = data[i].value.ui64;
} }
else if (strEQ(ptr, "oerrors")) { else if (strEQ(ptr, "oerrors")) {
ifstat->tx_errors = value; ifstat->tx_errors = value;
@ -2184,7 +1989,12 @@ static void ifstat_kstat_common(sigar_net_interface_stat_t *ifstat,
ifstat->tx_overruns = value; ifstat->tx_overruns = value;
} }
else if (strEQ(ptr, "opackets")) { else if (strEQ(ptr, "opackets")) {
ifstat->tx_packets = value; if (ifstat->tx_packets == 0) {
ifstat->tx_packets = value;
}
}
else if (strEQ(ptr, "opackets64")) {
ifstat->tx_packets = data[i].value.ui64;
} }
else if (strEQ(ptr, "toolong_errors")) { else if (strEQ(ptr, "toolong_errors")) {
ifstat->tx_overruns = value; ifstat->tx_overruns = value;
@ -2192,7 +2002,12 @@ static void ifstat_kstat_common(sigar_net_interface_stat_t *ifstat,
break; break;
case 'r': case 'r':
if (strEQ(ptr, "rbytes")) { if (strEQ(ptr, "rbytes")) {
ifstat->rx_bytes = value; if (ifstat->rx_bytes == 0) {
ifstat->rx_bytes = value;
}
}
else if (strEQ(ptr, "rbytes64")) {
ifstat->rx_bytes = data[i].value.ui64;
} }
else if (strEQ(ptr, "rx_overflow")) { else if (strEQ(ptr, "rx_overflow")) {
ifstat->rx_overruns = value; ifstat->rx_overruns = value;
@ -2223,8 +2038,6 @@ static int sigar_net_ifstat_get_any(sigar_t *sigar, const char *name,
return ENOENT; return ENOENT;
} }
SIGAR_ZERO(ifstat);
data = (kstat_named_t *)ksp->ks_data; data = (kstat_named_t *)ksp->ks_data;
ifstat_kstat_common(ifstat, data, ksp->ks_ndata); ifstat_kstat_common(ifstat, data, ksp->ks_ndata);
@ -2232,42 +2045,42 @@ static int sigar_net_ifstat_get_any(sigar_t *sigar, const char *name,
return SIGAR_OK; return SIGAR_OK;
} }
/* loopback interface only has rx/tx packets */
static int sigar_net_ifstat_get_lo(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat)
{
ifstat->rx_packets = 0;
ifstat->rx_bytes = SIGAR_FIELD_NOTIMPL;
ifstat->rx_errors = SIGAR_FIELD_NOTIMPL;
ifstat->rx_dropped = SIGAR_FIELD_NOTIMPL;
ifstat->rx_overruns = SIGAR_FIELD_NOTIMPL;
ifstat->rx_frame = SIGAR_FIELD_NOTIMPL;
ifstat->tx_packets = 0;
ifstat->tx_bytes = SIGAR_FIELD_NOTIMPL;
ifstat->tx_errors = SIGAR_FIELD_NOTIMPL;
ifstat->tx_dropped = SIGAR_FIELD_NOTIMPL;
ifstat->tx_overruns = SIGAR_FIELD_NOTIMPL;
ifstat->tx_collisions = SIGAR_FIELD_NOTIMPL;
ifstat->tx_carrier = SIGAR_FIELD_NOTIMPL;
ifstat->speed = SIGAR_FIELD_NOTIMPL;
return sigar_net_ifstat_get_any(sigar, name, ifstat);
}
int sigar_net_interface_stat_get(sigar_t *sigar, const char *name, int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
sigar_net_interface_stat_t *ifstat) sigar_net_interface_stat_t *ifstat)
{ {
ifstat->speed = SIGAR_FIELD_NOTIMPL; ifstat->speed = SIGAR_FIELD_NOTIMPL;
switch (*name) { if (strnEQ(name, "lo", 2)) {
case 'd': return sigar_net_ifstat_get_lo(sigar, name, ifstat);
if (strnEQ(name, "dmfe", 4)) { }
return sigar_net_ifstat_get_dmfe(sigar, name, ifstat); else {
} SIGAR_ZERO(ifstat);
break; return sigar_net_ifstat_get_any(sigar, name, ifstat);
case 'e':
if (strnEQ(name, "eri", 3)) {
return sigar_net_ifstat_get_eri(sigar, name, ifstat);
}
break;
case 'g':
if (strnEQ(name, "ge", 2)) {
return sigar_net_ifstat_get_ge(sigar, name, ifstat);
}
break;
case 'h':
if (strnEQ(name, "hme", 3)) {
return sigar_net_ifstat_get_hme(sigar, name, ifstat);
}
break;
case 'l':
if (strnEQ(name, "lo", 2)) {
return sigar_net_ifstat_get_lo(sigar, name, ifstat);
}
break;
default:
break;
} }
return sigar_net_ifstat_get_any(sigar, name, ifstat);
} }
#define TCPQ_SIZE(s) ((s) >= 0 ? (s) : 0) #define TCPQ_SIZE(s) ((s) >= 0 ? (s) : 0)