summaryrefslogtreecommitdiff
path: root/slstatus.c
diff options
context:
space:
mode:
authorAaron Marcher <info@nulltime.net>2017-06-12 23:56:21 +0200
committerAaron Marcher <info@nulltime.net>2017-06-12 23:56:21 +0200
commit832b21ca4b4ba866e010a6f52c0f84919c7123f2 (patch)
tree5548cf87c541045123b392c6cc8626e5409da41a /slstatus.c
parent259e967cbf855d1ed3886c7afafb1bfe6ab11645 (diff)
add cpu_freq function
Diffstat (limited to 'slstatus.c')
-rw-r--r--slstatus.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/slstatus.c b/slstatus.c
index caccc6e..993eba4 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -37,6 +37,7 @@ static char *smprintf(const char *fmt, ...);
static char *battery_perc(const char *bat);
static char *battery_power(const char *bat);
static char *battery_state(const char *bat);
+static char *cpu_freq(void);
static char *cpu_perc(void);
static char *datetime(const char *fmt);
static char *disk_free(const char *mnt);
@@ -168,6 +169,23 @@ battery_state(const char *bat)
}
static char *
+cpu_freq(void)
+{
+ int freq;
+ FILE *fp;
+
+ fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
+ if (fp == NULL) {
+ warn("Failed to open file /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
+ return smprintf("%s", UNKNOWN_STR);
+ }
+ fscanf(fp, "%i", &freq);
+ fclose(fp);
+
+ return smprintf("%d", (freq + 500) / 1000);
+}
+
+static char *
cpu_perc(void)
{
int perc;