aboutsummaryrefslogtreecommitdiffstats
path: root/logger.c
diff options
context:
space:
mode:
authorPA4WDH2023-05-27 11:20:22 +0200
committerPA4WDH2023-05-27 11:20:22 +0200
commitb80926797863c5a36417eb44a34483bb93610b79 (patch)
tree1a5026e03db338b86671ffe8d556fb57cb3529f0 /logger.c
parentUse CPU Transition Latency as checkdelay when setting new scaling_max_freq (diff)
downloadcputemp2maxfreq-b80926797863c5a36417eb44a34483bb93610b79.tar.gz
cputemp2maxfreq-b80926797863c5a36417eb44a34483bb93610b79.tar.bz2
cputemp2maxfreq-b80926797863c5a36417eb44a34483bb93610b79.zip
Add feature to use unixtime timestamps in logs and CSV
Diffstat (limited to 'logger.c')
-rw-r--r--logger.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/logger.c b/logger.c
index 00ee4a7..315c8c2 100644
--- a/logger.c
+++ b/logger.c
@@ -21,14 +21,21 @@ void logger_none(char *format,...) { }
void logger_stdout(char *format,...)
{
va_list args;
- struct timeval unixtime;
- struct tm *time;
+ struct timeval systime;
+ struct tm *systime_tm;
char timestring[255];
+ time_t unixtime;
- gettimeofday(&unixtime,NULL);
- time=localtime(&unixtime.tv_sec);
- strftime(timestring,255,"%F %T",time);
- printf("%s: ",timestring);
+ if (config.use_unixtime==0)
+ {
+ gettimeofday(&systime,NULL);
+ systime_tm=localtime(&systime.tv_sec);
+ strftime(timestring,sizeof(timestring),"%F %T",systime_tm);
+ printf("%s: ",timestring);
+ } else {
+ unixtime=time(NULL);
+ printf("%ld: ",unixtime);
+ }
va_start(args,format);
vprintf(format,args);
@@ -109,17 +116,24 @@ void csvlog_init()
// Write a single line of CSV data
void csvlog_write()
{
- struct timeval unixtime;
- struct tm *time;
+ struct timeval systime;
+ struct tm *systime_tm;
char timestring[255];
+ time_t unixtime;
DEBUG1_LOG("Writing data series to CSV file\n");
- gettimeofday(&unixtime,NULL);
- time=localtime(&unixtime.tv_sec);
- strftime(timestring,255,"%F %T",time);
+ if (config.use_unixtime==0)
+ {
+ gettimeofday(&systime,NULL);
+ systime_tm=localtime(&systime.tv_sec);
+ strftime(timestring,sizeof(timestring),"\"%F %T\"",systime_tm);
+ } else {
+ unixtime=time(NULL);
+ snprintf(timestring,sizeof(timestring),"%ld",unixtime);
+ }
- fprintf(config.csvfile,"\"%s\",\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\"\n",timestring,cpudata.min_freq,cpudata.max_freq,cpudata.cur_freq,cpudata.cur_temp/1000,config.max_temp/1000,cpudata.scale_max);
+ fprintf(config.csvfile,"%s,\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\"\n",timestring,cpudata.min_freq,cpudata.max_freq,cpudata.cur_freq,cpudata.cur_temp/1000,config.max_temp/1000,cpudata.scale_max);
}
// Close the CSV file