version 1.4, 2020/08/10 06:51:40 |
version 1.5, 2020/08/11 01:07:47 |
|
|
static void kstat_list(struct kstat_tree *, int, unsigned int, |
static void kstat_list(struct kstat_tree *, int, unsigned int, |
struct kstat_filters *); |
struct kstat_filters *); |
static void kstat_print(struct kstat_tree *); |
static void kstat_print(struct kstat_tree *); |
|
static void kstat_read(struct kstat_tree *, int); |
|
|
__dead static void |
__dead static void |
usage(void) |
usage(void) |
{ |
{ |
extern char *__progname; |
extern char *__progname; |
|
|
fprintf(stderr, "usage: %s [name|provider:0:name:unit ...]\n", |
fprintf(stderr, "usage: %s [-w wait] " |
__progname); |
"[name|provider:0:name:unit ...]\n", __progname); |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
struct kstat_tree kt = RBT_INITIALIZER(); |
struct kstat_tree kt = RBT_INITIALIZER(); |
unsigned int version; |
unsigned int version; |
int fd; |
int fd; |
|
const char *errstr; |
|
int ch; |
|
struct timespec interval = { 0, 0 }; |
int i; |
int i; |
|
|
for (i = 1; i < argc; i++) { |
while ((ch = getopt(argc, argv, "w:")) != -1) { |
|
switch (ch) { |
|
case 'w': |
|
interval.tv_sec = strtonum(optarg, 1, 100000000, |
|
&errstr); |
|
if (errstr != NULL) |
|
errx(1, "wait %s: %s", optarg, errstr); |
|
break; |
|
default: |
|
usage(); |
|
} |
|
} |
|
|
|
argc -= optind; |
|
argv += optind; |
|
|
|
for (i = 0; i < argc; i++) { |
struct kstat_filter *kf = kstat_filter_parse(argv[i]); |
struct kstat_filter *kf = kstat_filter_parse(argv[i]); |
TAILQ_INSERT_TAIL(&kfs, kf, kf_entry); |
TAILQ_INSERT_TAIL(&kfs, kf, kf_entry); |
} |
} |
|
|
kstat_list(&kt, fd, version, &kfs); |
kstat_list(&kt, fd, version, &kfs); |
kstat_print(&kt); |
kstat_print(&kt); |
|
|
|
if (interval.tv_sec == 0) |
|
return (0); |
|
|
|
for (;;) { |
|
nanosleep(&interval, NULL); |
|
|
|
kstat_read(&kt, fd); |
|
kstat_print(&kt); |
|
} |
|
|
return (0); |
return (0); |
} |
} |
|
|
|
|
hexdump(ksreq->ks_data, ksreq->ks_datalen); |
hexdump(ksreq->ks_data, ksreq->ks_datalen); |
break; |
break; |
} |
} |
|
} |
|
} |
|
|
|
static void |
|
kstat_read(struct kstat_tree *kt, int fd) |
|
{ |
|
struct kstat_entry *kse; |
|
struct kstat_req *ksreq; |
|
|
|
RBT_FOREACH(kse, kstat_tree, kt) { |
|
ksreq = &kse->kstat; |
|
if (ioctl(fd, KSTATIOC_FIND_ID, ksreq) == -1) |
|
err(1, "update id %llu", ksreq->ks_id); |
} |
} |
} |
} |