From f3d42738f667dd09a4da9cc0a863c44e9cdb3666 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 May 2014 12:33:34 +1200 Subject: Debug messages --- freq_tray/getcore.c | 9 +++++---- freq_tray/getcore.h | 2 ++ freq_tray/getfreq.c | 30 +++++++++++++++++++----------- freq_tray/getgov.c | 28 ++++++++++++++++------------ 4 files changed, 42 insertions(+), 27 deletions(-) (limited to 'freq_tray') diff --git a/freq_tray/getcore.c b/freq_tray/getcore.c index a2ee3d3..44b3940 100644 --- a/freq_tray/getcore.c +++ b/freq_tray/getcore.c @@ -22,17 +22,17 @@ #include #include -int NUMBER_OF_CORES; +unsigned int NUMBER_OF_CORES; -static gboolean core_exists(int core) +static gboolean core_exists(unsigned int core) { FILE* fd; char path[80]; char corestr[4]; - sprintf(corestr, "%i", core); + sprintf(corestr, "%d", core); sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); - + debug("Checking if core %d exists by opening '%s'",core,path); return (gboolean)(fd = fopen(path, "r")); } @@ -40,6 +40,7 @@ void gc_init() { NUMBER_OF_CORES = 0; while(core_exists(++NUMBER_OF_CORES)); + debug("Found %d cores\n",NUMBER_OF_CORES); } diff --git a/freq_tray/getcore.h b/freq_tray/getcore.h index fc1fc8d..43dcd12 100644 --- a/freq_tray/getcore.h +++ b/freq_tray/getcore.h @@ -19,6 +19,8 @@ #ifndef GETCORE_H #define GETCORE_H +#include "../debug.h" + void gc_init(); int gc_number(); diff --git a/freq_tray/getfreq.c b/freq_tray/getfreq.c index 02970b4..4b00775 100644 --- a/freq_tray/getfreq.c +++ b/freq_tray/getfreq.c @@ -31,17 +31,21 @@ int NUMBER_OF_AVAILABLE_FREQUENCIES; void gf_init() { + // TO DO : get rid of magic constants gchar freq_string[500]; int i = 0; int j = 0; for(i = 0; i < gc_number(); ++i) { - memset(freq_string, 0, 500); + memset(freq_string, '\0', 500); // Get available governor freqs. If no governor, try next cpu if (gf_available(i, freq_string, 500) == -1) + { + debug("Couldn't find gov on core %d\n",i); continue; + } /* go through every frequency in freq_string */ j = 0; @@ -49,7 +53,7 @@ void gf_init() gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); while(end_of_curr) { - memset(AVAILABLE_FREQUENCIES[i][j], 0, 13); + memset(AVAILABLE_FREQUENCIES[i][j], '\0', 13); memmove(AVAILABLE_FREQUENCIES[i][j], curr, end_of_curr - curr); curr = end_of_curr+1; @@ -58,6 +62,7 @@ void gf_init() } } NUMBER_OF_AVAILABLE_FREQUENCIES = j; + debug("Found %d frequencies\n",j); } int gf_current(int core) @@ -65,20 +70,21 @@ int gf_current(int core) FILE* fd; char buff[13]; char path[80]; - char corestr[4]; int freq; - sprintf(corestr, "%i", core); - - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", core); if(!(fd = fopen(path, "r"))) - return -1; + { + debug("Couldn't open '%s'\n",path); + return -1; + } fgets(buff, 13, fd); freq = atoi(buff); fclose(fd); + debug("Found freq %d on core %d\n",freq,core); return freq; } @@ -86,14 +92,14 @@ int gf_available(int core, char* out, int size) { FILE* fd; char path[80]; - char corestr[4]; - - sprintf(corestr, "%i", core); - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_available_frequencies", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_frequencies", core); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); @@ -111,6 +117,8 @@ void gf_get_frequency_label(int freq, char* out) sprintf(out, "%.2f GHz", freq/pow(10, i-1)); else sprintf(out, "%.2d MHz", freq/1000); + + debug("Prepared freq label '%s' for freq %d\n",out,freq); } char* gf_freqa(int core, int index) diff --git a/freq_tray/getgov.c b/freq_tray/getgov.c index 8fe44a5..181ad41 100644 --- a/freq_tray/getgov.c +++ b/freq_tray/getgov.c @@ -39,18 +39,18 @@ void gg_init() memset(gov_string, '\0', 500); gg_available(i, gov_string, 500); - /* go through every governor in gov_string */ + // go through every governor in gov_string j = 0; gchar* curr = &gov_string[0]; gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " "); while(end_of_curr) { - memset(AVAILABLE_GOVERNORS[i][j], '\0', 13); - memmove(AVAILABLE_GOVERNORS[i][j], curr, end_of_curr - curr); + memset(AVAILABLE_GOVERNORS[i][j], '\0', 13); + memmove(AVAILABLE_GOVERNORS[i][j], curr, end_of_curr - curr); - curr = end_of_curr+1; - end_of_curr = g_strstr_len(curr, strlen(curr), " "); - ++j; + curr = end_of_curr+1; + end_of_curr = g_strstr_len(curr, strlen(curr), " "); + ++j; } } NUMBER_OF_AVAILABLE_GOVERNORS = j; @@ -67,14 +67,18 @@ int gg_current(int core, char* out, int size) sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_governor", corestr); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); - - /* remove newline at the end */ + // Chomp gchar* newline = g_strrstr(out, "\n"); *newline = '\0'; + debug("Current gov for core %d is '%s'\n",core,out); + fclose(fd); return 0; } @@ -83,14 +87,14 @@ int gg_available(int core, char* out, int size) { FILE* fd; char path[80]; - char corestr[4]; - sprintf(corestr, "%i", core); - - sprintf(path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_available_governors", corestr); + sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", core); if(!(fd = fopen(path, "r"))) + { + debug("Couldn't open '%s'\n",path); return -1; + } fgets(out, size, fd); -- cgit v1.1