My slstatus configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* See LICENSE file for copyright and license details. */
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/sysctl.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include "../../util.h"
  8. inline int
  9. load_uvmexp(struct uvmexp *uvmexp)
  10. {
  11. int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};
  12. size_t size;
  13. size = sizeof(*uvmexp);
  14. return sysctl(uvmexp_mib, 2, uvmexp, &size, NULL, 0) >= 0 ? 1 : 0;
  15. }
  16. const char *
  17. ram_free(void)
  18. {
  19. struct uvmexp uvmexp;
  20. float free;
  21. int free_pages;
  22. if (load_uvmexp(&uvmexp)) {
  23. free_pages = uvmexp.npages - uvmexp.active;
  24. free = (double) (free_pages * uvmexp.pagesize) / 1024 / 1024 / 1024;
  25. return bprintf("%f", free);
  26. }
  27. return NULL;
  28. }
  29. const char *
  30. ram_perc(void)
  31. {
  32. struct uvmexp uvmexp;
  33. int percent;
  34. if (load_uvmexp(&uvmexp)) {
  35. percent = uvmexp.active * 100 / uvmexp.npages;
  36. return bprintf("%d", percent);
  37. }
  38. return NULL;
  39. }
  40. const char *
  41. ram_total(void)
  42. {
  43. struct uvmexp uvmexp;
  44. float total;
  45. if (load_uvmexp(&uvmexp)) {
  46. total = (double) (uvmexp.npages * uvmexp.pagesize) / 1024 / 1024 / 1024;
  47. return bprintf("%f", total);
  48. }
  49. return NULL;
  50. }
  51. const char *
  52. ram_used(void)
  53. {
  54. struct uvmexp uvmexp;
  55. float used;
  56. if (load_uvmexp(&uvmexp)) {
  57. used = (double) (uvmexp.active * uvmexp.pagesize) / 1024 / 1024 / 1024;
  58. return bprintf("%f", used);
  59. }
  60. return NULL;
  61. }