lasp/beamforming/c/ascee_tracer.c

77 lines
2.0 KiB
C
Raw Normal View History

2018-01-29 15:14:50 +00:00
// si_tracer.c
//
// last-edit-by: J.A. de Jong
//
// Description:
//
//////////////////////////////////////////////////////////////////////
#if TRACER == 1
#include <stdio.h>
#include "ascee_tracer.h"
2018-01-29 15:14:50 +00:00
#include "types.h"
#ifdef _REENTRANT
#include <stdatomic.h>
static _Thread_local us ASCEE_FN_LEVEL = 0;
static _Atomic(int) TRACERNAME = ATOMIC_VAR_INIT(DEFAULTTRACERLEVEL);
2018-01-29 15:14:50 +00:00
void setTracerLevel(int level) {
atomic_store(&TRACERNAME,level);
}
int getTracerLevel() {
return atomic_load(&TRACERNAME);
}
2018-01-29 15:14:50 +00:00
#else
int TRACERNAME;
static us ASCEE_FN_LEVEL = 0;
2018-01-29 15:14:50 +00:00
/* setTracerLevel and getTracerLevel are defined as macros in
* tracer.h */
#endif
void indent_trace() {
for(us i=0;i<ASCEE_FN_LEVEL;i++) {
printf("--");
}
printf("* ");
}
2018-01-29 15:14:50 +00:00
void trace_impl(const char* file,int pos, const char * string){
indent_trace();
2018-01-29 15:14:50 +00:00
printf(annestr(TRACERNAME) ":%s:%i: %s\n",file,pos,string);
}
void fstrace_impl(const char* file,int pos,const char* fn){
ASCEE_FN_LEVEL++;
indent_trace();
2018-01-29 15:14:50 +00:00
printf(annestr(TRACERNAME) ":%s:%i: start function: %s()\n",file,pos,fn);
}
void fetrace_impl(const char* file,int pos,const char* fn){
indent_trace();
2018-01-29 15:14:50 +00:00
printf(annestr(TRACERNAME) ":%s:%i: end function: %s()\n",file,pos,fn);
ASCEE_FN_LEVEL--;
2018-01-29 15:14:50 +00:00
}
void ivartrace_impl(const char* pos,int line,const char* varname, int var){
indent_trace();
2018-01-29 15:14:50 +00:00
printf(annestr(TRACERNAME) ":%s:%i: %s = %i\n",pos,line,varname,var);
}
void uvartrace_impl(const char* pos,int line,const char* varname,size_t var){
indent_trace();
2018-01-29 15:14:50 +00:00
printf(annestr(TRACERNAME) ":%s:%i: %s = %zu\n",pos,line,varname,var);
}
void dvartrace_impl(const char* pos,int line,const char* varname, d var){
indent_trace();
2018-01-29 15:14:50 +00:00
printf(annestr(TRACERNAME) ":%s:%i: %s = %0.5e\n",pos,line,varname,var);
}
void cvartrace_impl(const char* pos,int line,const char* varname, c var){
indent_trace();
2018-01-29 15:14:50 +00:00
printf(annestr(TRACERNAME) ":%s:%i: %s = %0.5e+%0.5ei\n",pos,line,varname,creal(var),cimag(var));
}
#endif
//////////////////////////////////////////////////////////////////////