Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <kstat.h>
- long getValue(kstat_t *ksp, char *name);
- int main(void) {
- long value;
- kstat_ctl_t *kc;
- kstat_t *data;
- if ((kc = kstat_open()) == NULL) {
- fprintf(stderr, "Failed to open kstat!\n");
- exit(1);
- };
- if ((data = kstat_lookup(kc, "unix", 0, "dnlcstats")) == NULL) {
- fprintf(stderr, "Failed to kstat_lookup!\n");
- exit(1);
- } else {
- (void)kstat_read(kc, data, NULL);
- char *f[8] = {
- "double_enters", "enters",
- "hits", "misses", "negative_cache_hits",
- "pick_free", "pick_heuristic", "pick_last",
- };
- for (int i = 0 ; i < 8 ; i++) {
- if ((value = getValue(data, f[i])) != -1) {
- printf("name: %s | value: %ld\n", f[i], value);
- }
- }
- }
- return 0;
- }
- long getValue(kstat_t *ksp, char *name) {
- int i;
- long value = -1;
- kstat_named_t *fields = KSTAT_NAMED_PTR(ksp);
- for (i = 0 ; i < ksp->ks_ndata ; i++, fields++) {
- if (!strcmp(name, fields->name)) {
- value = fields->value.ui64;
- break;
- }
- }
- return value;
- }
Add Comment
Please, Sign In to add comment