Changeset View
Changeset View
Standalone View
Standalone View
head/tools/tools/npe/npestats/npestats.c
Show All 26 Lines | |||||
* THE POSSIBILITY OF SUCH DAMAGES. | * THE POSSIBILITY OF SUCH DAMAGES. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
/* | /* | ||||
* npe statistics class. | * npe statistics class. | ||||
*/ | */ | ||||
#include <sys/types.h> | #include <sys/param.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <err.h> | |||||
#include <signal.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <signal.h> | |||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <err.h> | |||||
#include "npestats.h" | #include "npestats.h" | ||||
#define AFTER(prev) ((prev)+1) | #define AFTER(prev) ((prev)+1) | ||||
static const struct fmt npestats[] = { | static const struct fmt npestats[] = { | ||||
#define S_ALIGN 0 | #define S_ALIGN 0 | ||||
{ 7, "align", "align", "alignment errors" }, | { 7, "align", "align", "alignment errors" }, | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
#undef STAT | #undef STAT | ||||
} | } | ||||
BSDSTAT_DEFINE_BOUNCE(npestatfoo) | BSDSTAT_DEFINE_BOUNCE(npestatfoo) | ||||
struct npestatfoo * | struct npestatfoo * | ||||
npestats_new(const char *ifname, const char *fmtstring) | npestats_new(const char *ifname, const char *fmtstring) | ||||
{ | { | ||||
#define N(a) (sizeof(a) / sizeof(a[0])) | |||||
struct npestatfoo_p *wf; | struct npestatfoo_p *wf; | ||||
wf = calloc(1, sizeof(struct npestatfoo_p)); | wf = calloc(1, sizeof(struct npestatfoo_p)); | ||||
if (wf != NULL) { | if (wf != NULL) { | ||||
bsdstat_init(&wf->base.base, "npestats", npestats, N(npestats)); | bsdstat_init(&wf->base.base, "npestats", npestats, | ||||
nitems(npestats)); | |||||
/* override base methods */ | /* override base methods */ | ||||
wf->base.base.collect_cur = npe_collect_cur; | wf->base.base.collect_cur = npe_collect_cur; | ||||
wf->base.base.collect_tot = npe_collect_tot; | wf->base.base.collect_tot = npe_collect_tot; | ||||
wf->base.base.get_curstat = npe_get_curstat; | wf->base.base.get_curstat = npe_get_curstat; | ||||
wf->base.base.get_totstat = npe_get_totstat; | wf->base.base.get_totstat = npe_get_totstat; | ||||
wf->base.base.update_tot = npe_update_tot; | wf->base.base.update_tot = npe_update_tot; | ||||
/* setup bounce functions for public methods */ | /* setup bounce functions for public methods */ | ||||
BSDSTAT_BOUNCE(wf, npestatfoo); | BSDSTAT_BOUNCE(wf, npestatfoo); | ||||
/* setup our public methods */ | /* setup our public methods */ | ||||
wf->base.setifname = npe_setifname; | wf->base.setifname = npe_setifname; | ||||
npe_setifname(&wf->base, ifname); | npe_setifname(&wf->base, ifname); | ||||
wf->base.setfmt(&wf->base, fmtstring); | wf->base.setfmt(&wf->base, fmtstring); | ||||
} | } | ||||
return &wf->base; | return &wf->base; | ||||
#undef N | |||||
} | } |