Guest User

Untitled

a guest
May 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <kstat.h>
  5.  
  6.  
  7. long getValue(kstat_t *ksp, char *name);
  8.  
  9. int main(void) {
  10. long value;
  11. kstat_ctl_t *kc;
  12. kstat_t *data;
  13.  
  14. if ((kc = kstat_open()) == NULL) {
  15. fprintf(stderr, "Failed to open kstat!\n");
  16. exit(1);
  17. };
  18.  
  19. if ((data = kstat_lookup(kc, "unix", 0, "dnlcstats")) == NULL) {
  20. fprintf(stderr, "Failed to kstat_lookup!\n");
  21. exit(1);
  22. } else {
  23. (void)kstat_read(kc, data, NULL);
  24. char *f[8] = {
  25. "double_enters", "enters",
  26. "hits", "misses", "negative_cache_hits",
  27. "pick_free", "pick_heuristic", "pick_last",
  28. };
  29. for (int i = 0 ; i < 8 ; i++) {
  30. if ((value = getValue(data, f[i])) != -1) {
  31. printf("name: %s | value: %ld\n", f[i], value);
  32. }
  33. }
  34. }
  35. return 0;
  36. }
  37.  
  38. long getValue(kstat_t *ksp, char *name) {
  39. int i;
  40. long value = -1;
  41. kstat_named_t *fields = KSTAT_NAMED_PTR(ksp);
  42.  
  43. for (i = 0 ; i < ksp->ks_ndata ; i++, fields++) {
  44. if (!strcmp(name, fields->name)) {
  45. value = fields->value.ui64;
  46. break;
  47. }
  48. }
  49. return value;
  50. }
Add Comment
Please, Sign In to add comment