15 #define __TRACE_H_REV "\ 16 $RCSfile: trace.h,v $\ 18 $Date: 2009/10/09 20:03:00 $" 21 # include <linux/types.h> 23 # include <sys/types.h> 24 # include <sys/stat.h> 28 # include <sys/mman.h> 29 # include <sys/ioctl.h> 38 # include <sys/time.h> 41 # include <rms/util/trace_intr.h> 67 #define TRACE( lvl, msg, params... ) \ 69 struct timeval lclTime={0,0};\ 72 lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\ 73 if ((traceControl_sp->mode&(1<<0)) && (traceLevel_ip[lidx+0]&(1<<lvl)))\ 76 TRACE_FUNCTION( &lclTime, TRACE_TID, lvl, msg , ## params );\ 78 TRACE_USER_FUNCTION( &lclTime, TRACE_TID, lvl, msg , ## params );\ 88 #define TRACE_MAXIMUM_NUMBER_OF_FUNCTIONS (sizeof(int)*8) 94 # define TRACE_NAME "" 107 #define traceControl_TimeDiff( sooner, later ) \ 109 secs = later.tv_sec - sooner.tv_sec;\ 110 usecs = later.tv_usec - sooner.tv_usec;\ 111 ((secs*1000000) + usecs);\ 115 #if __GNUC_MINOR__ == 96 || __GNUC__ == 3 116 # define TRACE_COMPILER_DOES_DYNAMIC_ARRAYS 0 118 # define TRACE_COMPILER_DOES_DYNAMIC_ARRAYS 1 125 #define TRACE_NUM_PARAMETER_INTS 6 145 char blockMarker[28];
218 # include <linux/time.h> 219 # include <linux/version.h> 220 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 221 # include <asm/system.h> 222 # include <linux/trace_sys.h> 226 extern int tracePMC[];
228 struct s_traceEntry *
229 traceCircularQueuePut(
int, ... );
236 # define TRACE_INIT_CHECK 254 # define TRACE_FUNCTION( tv_adr, tid, lvl, msg, params...) \ 256 { unsigned long __flags__;\ 257 struct s_traceEntry *traceEntry_sp;\ 258 local_save_flags( __flags__ );\ 259 local_irq_disable();\ 260 traceEntry_sp = traceCircularQueuePut( tid, lvl, msg , ## params );\ 261 *tv_adr = traceEntry_sp->time;\ 262 local_irq_restore( __flags__ );\ 266 # ifndef TRACE_USER_FUNCTION 267 extern void (*(*trace_kernel_functions)[])(
struct timeval*,
int,
int,
char*, ... );
282 # define TRACE_USER_FUNCTION( tv_adr, tid, lvl, msg, params... ) \ 286 lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\ 287 for (_ii_=1; _ii_<traceControl_sp->numberOfFunctions; _ii_++)\ 288 { if ((traceControl_sp->mode&(1<<_ii_)) && (traceLevel_ip[lidx+_ii_]&(1<<lvl)))\ 290 if ((*trace_kernel_functions)[_ii_-1])\ 291 { char _tmp_buf_[traceControl_sp->messageSize_bytes+4];\ 293 if ((tv_adr)->tv_sec == 0) do_gettimeofday( tv_adr );\ 294 for (_jj_=0; (_jj_<traceControl_sp->messageSize_bytes) && *((msg)+_jj_); _jj_++)\ 295 { _tmp_buf_[_jj_] = *((msg)+_jj_);\ 297 _tmp_buf_[_jj_] = '\n'; _jj_++;\ 298 _tmp_buf_[_jj_] = '\0';\ 299 (*trace_kernel_functions)[_ii_-1]( tv_adr, tid, lvl, _tmp_buf_ , ## params );\ 315 #define traceControl_Mode( new_mode ) \ 317 old_mode = traceControl_sp->mode;\ 318 traceControl_sp->mode = new_mode;\ 328 #define traceControl_ModeGet() \ 329 ({ traceControl_sp->mode;\ 359 # define TRACE_INIT_CHECK do\ 360 { if (!traceControl_sp)traceControl_Init("");\ 366 # define TRACE_TID traceTID 379 # define TRACE_FUNCTION( tv_adr, tid, lvl, msg, params... ) \ 380 trace_function( tv_adr, tid\ 381 ,lvl, msg , ## params ) 383 #ifndef TRACE_FUNCTIONS 392 #define TRACE_FUNCTIONS {0,0,trace_printf} 412 localtime_r( (time_t *)&tv_sp->tv_sec, &tm_s );
413 timlen = strftime( timbuf,
sizeof(timbuf),
"%a %H:%M:%S", &tm_s );
415 sprintf( &timbuf[timlen],
".%06d: ", (
int)tv_sp->tv_usec );
416 newbuf = (
char *)alloca( timlen+strlen(&timbuf[timlen])+strlen(msg)+2 );
419 sprintf( newbuf,
"%s%s\n", timbuf, msg );
422 vprintf( newbuf, ap );
429 # ifndef TRACE_USER_FUNCTION 444 # define TRACE_USER_FUNCTION( tv_adr, tid, lvl, msg, params... ) \ 448 lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\ 449 for (_ii_=1; _ii_<traceControl_sp->numberOfFunctions; _ii_++)\ 450 { if ((traceControl_sp->mode&(1<<_ii_)) && (traceLevel_ip[lidx+_ii_]&(1<<lvl)))\ 451 { if (trace_user_functions[_ii_-1])\ 452 { if ((tv_adr)->tv_sec == 0) gettimeofday( tv_adr, 0 );\ 453 trace_user_functions[_ii_-1](tv_adr,tid,lvl, msg , ## params );\ 498 if (traceControl_sp)
return (0);
505 /
sizeof(disabled_level[0]));
507 traceControl_fd =
open(
"/proc/trace/control", O_RDONLY );
508 if (traceControl_fd == -1)
509 { perror(
"open /proc/trace/control" );
510 fprintf(
stderr,
"continueing with disabled tracing\n" );
524 fd_map =
open(
"/proc/trace/map", O_RDONLY );
526 { perror(
"open /proc/trace/map" );
527 fprintf(
stderr,
"continueing with disabled tracing\n" );
529 traceControl_fd = -1;
533 /
sizeof(disabled_level[0]));
543 if (traceControl_sp == (
void *)-1)
544 { perror(
"mmap /proc/trace/map" );
545 fprintf(
stderr,
"continueing with disabled tracing\n" );
547 traceControl_fd = -1;
551 /
sizeof(disabled_level[0]));
562 traceLevel_ip = (
int *)mmap( 0
563 , levelArraySize *
sizeof(
int)
569 if (traceLevel_ip == (
void *)-1)
570 { perror(
"mmap level" );
571 fprintf(
stderr,
"continueing with disabled tracing\n" );
573 traceControl_fd = -1;
577 /
sizeof(disabled_level[0]));
597 #define traceControl_ReInit( name ) \ 599 if (!traceControl_sp)\ 600 { traceControl_Init("");\ 602 else if (traceControl_fd > 0)\ 604 union u_traceIoctl ioctl_data;\ 605 ioctl_data.generic.ptr = name;\ 606 __sts__ = ioctl( traceControl_fd, traceIoctl_e_init, &ioctl_data );\ 607 traceTID = ioctl_data.generic.num;\ 618 #define traceControl_Mode( new_mode ) \ 620 if (!traceControl_sp) traceControl_Init("");\ 621 old_mode = traceControl_sp->mode;\ 622 if (traceControl_fd > 0)\ 623 { ioctl( traceControl_fd, traceIoctl_e_modeSet, new_mode );\ 633 #define traceControl_ModeGet() \ 634 ({ if (!traceControl_sp) traceControl_Init("");\ 635 traceControl_sp->mode;\ 643 #define traceControl_ModeSet( mask ) \ 644 ({ int old_mode, new_mode;\ 645 if (!traceControl_sp) traceControl_Init("");\ 646 old_mode = traceControl_sp->mode;\ 647 new_mode = old_mode | mask;\ 648 if (traceControl_fd > 0)\ 649 { ioctl( traceControl_fd, traceIoctl_e_modeSet, new_mode );\ 652 { traceControl_sp->mode = new_mode;\ 662 #define traceControl_ModeClr( mask ) \ 663 ({ int old_mode, new_mode;\ 664 if (!traceControl_sp) traceControl_Init("");\ 665 old_mode = traceControl_sp->mode;\ 666 new_mode = old_mode & ~mask;\ 667 if (traceControl_fd > 0)\ 668 { ioctl( traceControl_fd, traceIoctl_e_modeSet, new_mode );\ 671 { traceControl_sp->mode = new_mode;\ 679 #define traceControl_Reset() \ 680 ({ if (!traceControl_sp) traceControl_Init("");\ 681 if (traceControl_fd > 0)\ 682 { ioctl( traceControl_fd, traceIoctl_e_reset, 0 );\ 693 #define traceControl_PMCGet( which ) \ 694 ({ union u_traceIoctl ioctl_data;\ 695 if (!traceControl_sp) traceControl_Init("");\ 696 if (traceControl_fd > 0)\ 697 { ioctl_data.pmc.whichIn_cpuidOut = which;\ 698 ioctl( traceControl_fd, traceIoctl_e_PMCGet, &ioctl_data );\ 700 ioctl_data.pmc.pmc_data_val;\ 713 #define traceControl_PMCRead( which, cpuidOut_ptr ) \ 714 ({ union u_traceIoctl ioctl_data;\ 715 if (!traceControl_sp) traceControl_Init("");\ 716 if (traceControl_fd > 0)\ 717 { ioctl_data.pmc.whichIn_cpuidOut = which;\ 718 ioctl( traceControl_fd, traceIoctl_e_PMCGet, &ioctl_data );\ 720 *(cpuidOut_ptr) = ioctl_data.pmc.whichIn_cpuidOut;\ 721 ioctl_data.pmc.pmc_data_val;\ 734 #define traceControl_LevelSet( func, __mask__ ) \ 735 ({ union u_traceIoctl ioctl_data;\ 736 if (!traceControl_sp) traceControl_Init("");\ 737 if (traceControl_fd > 0)\ 738 { ioctl_data.generic.num = traceTID;\ 739 ioctl_data.generic.ptr = (void*)func;\ 740 ioctl_data.generic.mask = __mask__;\ 741 ioctl( traceControl_fd, traceIoctl_e_levelSet, &ioctl_data );\ 743 else if (func < (sizeof(disabled_level)/sizeof(int)))\ 744 { traceLevel_ip[func] = __mask__;\ 754 #define traceControl_LevelGet( func ) \ 756 if (!traceControl_sp) traceControl_Init("");\ 757 lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\ 758 traceLevel_ip[lidx+func];\
struct s_tracePrint * print_sp
static int * traceLevel_ip
static int disabled_level[4]
static void trace_printf(struct timeval *tv_sp, int tid, int lvl, char *msg,...)
static int traceControl_Init(char *name)
void(* func_ptr_t)(struct timeval *, int, int, char *,...)
int circularQueueEntriesUsed
int circularQueueSize_bytes
procfile open("FD_BRL_v0.txt")
static struct s_traceControl disabled_control
int numberOfParameter_integers
struct u_traceIoctl::@35 generic
static int traceControl_fd
static struct s_traceControl * traceControl_sp
unsigned long long pmc_data_val
char * circularQueueFirst
int circularQueueEntrySize_bytes
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
static func_ptr_t trace_user_functions[]