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.
 
 
 
 

66 lines
1.3 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #if defined(__linux__)
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "../util.h"
  6. const char *
  7. cpu_freq(void)
  8. {
  9. int freq;
  10. return (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
  11. "%i", &freq) == 1) ?
  12. bprintf("%d", (freq + 500) / 1000) : NULL;
  13. }
  14. const char *
  15. cpu_perc(void)
  16. {
  17. int perc;
  18. static long double a[7];
  19. static int valid;
  20. long double b[7];
  21. memcpy(b, a, sizeof(b));
  22. if (pscanf("/proc/stat", "%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf", &a[0], &a[1], &a[2],
  23. &a[3], &a[4], &a[5], &a[6]) != 7) {
  24. return NULL;
  25. }
  26. if (!valid) {
  27. valid = 1;
  28. return NULL;
  29. }
  30. perc = 100 * ((b[0]+b[1]+b[2]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[5]+a[6])) /
  31. ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]));
  32. return bprintf("%d", perc);
  33. }
  34. const char *
  35. cpu_iowait(void)
  36. {
  37. int perc;
  38. static int valid;
  39. static long double a[7];
  40. long double b[7];
  41. memcpy(b, a, sizeof(b));
  42. if (pscanf("/proc/stat", "%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf", &a[0], &a[1], &a[2],
  43. &a[3], &a[4], &a[5], &a[6]) != 7) {
  44. return NULL;
  45. }
  46. if (!valid) {
  47. valid = 1;
  48. return NULL;
  49. }
  50. perc = 100 * ((b[4]) - (a[4])) /
  51. ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]));
  52. return bprintf("%d", perc);
  53. }
  54. #endif