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.
 
 
 
 

64 lines
1.3 KiB

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