⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trace.h

📁 TRACE的源代码,在LINUX调试程序要使用的.
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef __TRACE_H#define __TRACE_H/*  This file (trace.h) was created by Ron Rechenmacher <ron@fnal.gov> on    Dec 20, 1999. "TERMS AND CONDITIONS" governing this file are in the README    or COPYING file. If you do not have such a file, one can be obtained by    contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.*/#define __TRACE_H_REV	"\$RCSfile: trace.h,v $\$Revision: 1.40 $\$Date: 2004/02/07 02:40:41 $"#ifdef __KERNEL__# include <linux/types.h>	/* pid_t */#else# include <sys/types.h>		/* pid_t, open */# include <sys/stat.h>		/* open */# include <stdio.h>		/* perror */# include <fcntl.h>		/* open */# include <unistd.h>		/* mmap */# include <sys/mman.h>		/* mmap */# include <sys/ioctl.h>		/* ioctl */# include <string.h>		/* strlen */# ifdef __USE_POSIX#  include <time.h>		/* localtime_r */# else#  define __USE_POSIX#  include <time.h>		/* localtime_r */#  undef __USE_POSIX# endif# include <sys/time.h>		/* NESTED by time.h struct timeval */# include <stdarg.h>		/* varargs */# include <stdio.h>		/* printf */# include <asm/trace_intr.h>	/* *** THE APPROPRIATE trace_function! *** */# include <stdlib.h>		/* malloc */# include <alloca.h>		/* alloca */#endif#define TRACE( lvl, msg, params... ) \({      int		lidx;\        struct timeval	lclTime={0,0};/*an indication that no trace occurred*/\    /* first function activated sets the reference time */\    TRACE_INIT_CHECK;\    lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\    if ((traceControl_sp->mode&(1<<0)) && (traceLevel_ip[lidx+0]&(1<<lvl)))\    {   /* need to provide a way to return time (only when in user space\	   though?maybe?) */\	TRACE_FUNCTION( &lclTime, TRACE_TID, lvl, msg , ## params );\    }\    TRACE_USER_FUNCTION( &lclTime, TRACE_TID, lvl, msg , ## params );\    lclTime;\})/*  Currently defined "traceControls":    Init,		function, for each kernel/userspace    ReInit,		#define,  userspace    Mode,		#define,  for each kernel/userspace    ModeGet,		#define,  for each kernel/userspace    ModeSet,		#define,  userspace    ModeClr,		#define,  userspace    Reset,		#define,  userspace    PMCGet,		#define,  userspace    TimeDiff,		#define,  one used for both kernel/userspace    LevelSet,		#define,  userspace    LevelGet,		#define,  userspace*/#define TRACE_CNTL( cmd, args... ) traceControl_##cmd( args )/*---------------------------------------------------------------------------*//* always 8 bits in a byte */#define TRACE_MAXIMUM_NUMBER_OF_FUNCTIONS	(sizeof(int)*8)	/* maximum */# ifndef TRACE_NAME#  define TRACE_NAME ""# endif/*  possibilities:    sec higher, usec lower   i.e. 11.500000 vs. 10.600000  1*1000000 + -100000    sec higher, usec same    i.e. 11.500000 vs. 10.500000    sec higher, usec higher  i.e. 11.500000 vs. 10.400000    sec same,   usec lower   i.e. 11.500000 vs. 11.600000    sec same,   usec same    i.e. 11.500000 vs. 11.500000    sec same,   usec higher  i.e. 11.500000 vs. 11.400000*/#define traceControl_TimeDiff( sooner, later )  \				({  int	secs, usecs;\				    secs  = later.tv_sec - sooner.tv_sec;\				    usecs = later.tv_usec - sooner.tv_usec;\				    ((secs*1000000) + usecs);\				})/*----------------------------------------------------------------------------*/#if __GNUC_MINOR__ == 96 || __GNUC__ == 3# define TRACE_COMPILER_DOES_DYNAMIC_ARRAYS 0#else# define TRACE_COMPILER_DOES_DYNAMIC_ARRAYS 1#endif#define TRACE_NUM_PARAMETER_INTS	6struct	s_tracePrint{   char	*heading;    int		width;    char	type;    int		offset;};struct s_traceControl{   char		blockMarker[28];	/* so we could search physical mem from external bus */    /*  these should have corresponding setup global variables */    int			numberOfTID;    int			nameSize_bytes;    int			numberOfFunctions;    int			circularQueueSize_bytes;    int			messageSize_bytes;    int			numberOfParameter_integers;    struct s_tracePrint	*print_sp;    int			printAscending;    int			printHeading;    int			mode;               /* global mode */    int			initializationOK;   /* do not allow mode change					       unless OK */    /*  THE SIZE OF THE AREAS THE FOLLOWING POINTERS POINT TO DEPEND ON THE	CONFIGURATION */      /*  the user can have direct write access to the area where these point to */    int			*initialLevel;    /* the area where these pointers point to needs to be controlled */    char		*name_a;    int			circularQueueEntrySize_bytes; /* includes processor							 dependent/specific */    int			circularQueueEntries;    char		*circularQueueFirst; /* ptr to 1st byte of 1st entry */    char		*circularQueueLast; /* ptr to 1st byte of last entry */    char		*circularQueueHead;    char		*circularQueueTail;    int			circularQueueFull;    int			circularQueueEntriesUsed; /* for convenience */};enum e_traceIoctl{   traceIoctl_e_init,    traceIoctl_e_mapControl,    traceIoctl_e_mapLevel,    traceIoctl_e_reset,    traceIoctl_e_versionGet,    traceIoctl_e_cpuGet,    traceIoctl_e_modeSet,    traceIoctl_e_levelSet,    traceIoctl_e_PMCGet};union u_traceIoctl{   struct    {   int			num;	void			*ptr;	int			mask;  /* mask will also contain cpuid for PMC Get/Read */    } generic;    struct    {   unsigned long long	pmc_data_val;	int			whichIn_cpuidOut;    } pmc;};/*----------------------------------------------------------------------------*/#ifdef __KERNEL__# include <linux/time.h>	/* do_gettimeofday */# include <linux/version.h>      /* LINUX_VERSION_CODE, KERNEL_VERSION */# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)/*  Note: I use cli here and spinlock in trace_queue.c as interrupts are    disabled for me when I come from user space */#  ifdef CONFIG_SMP#   define cli			local_irq_disable#   define save_flags		local_save_flags#   define restore_flags	local_irq_restore#  endif# else#  include <asm/system.h>	/* save_flags, cli, restore_flags */# endif# include <linux/trace_sys.h>	/* traceCircularQueuePut, struct s_traceEntry */extern struct s_traceControl	*traceControl_sp;extern int			*traceLevel_ip;extern int			 tracePMC[];struct s_traceEntry *traceCircularQueuePut( int, /*int, char*,*/ ... );# define TRACE_INIT_CHECK# define TRACE_TID		0# define TRACE_FUNCTION( tv_adr, tid, lvl, msg, params...) \         do\         {   unsigned long	__flags__;\             struct s_traceEntry *traceEntry_sp;\	     save_flags( __flags__ );\	     cli();\	     traceEntry_sp = traceCircularQueuePut( tid, lvl, msg , ## params );\             *tv_adr = traceEntry_sp->time;\	     restore_flags( __flags__ );\	 } while (0)# ifndef  TRACE_USER_FUNCTIONextern	void	(*(*trace_kernel_functions)[])( struct timeval*, int, int, char*, ... ); /* ptr to array of function ptrs */#  define TRACE_USER_FUNCTION( tv_adr, tid, lvl, msg, params... ) \    /* NOTE THE FUNCTION ARRAY IDX 0 LINES UP WITH MODE/LEVEL IDX 1 */\    do \    {       int	_ii_, lidx;\        lidx = TRACE_TID * traceControl_sp->numberOfFunctions;\        for (_ii_=1; _ii_<traceControl_sp->numberOfFunctions; _ii_++)\        {   if ((traceControl_sp->mode&(1<<_ii_)) && (traceLevel_ip[lidx+_ii_]&(1<<lvl)))\	    {\              if ((*trace_kernel_functions)[_ii_-1])\              {   char _tmp_buf_[traceControl_sp->messageSize_bytes+4];\                  int _jj_;\                  if ((tv_adr)->tv_sec == 0) do_gettimeofday( tv_adr );\                  for (_jj_=0; (_jj_<traceControl_sp->messageSize_bytes) && *((msg)+_jj_); _jj_++)\	          {   _tmp_buf_[_jj_] = *((msg)+_jj_);\	          }\	          _tmp_buf_[_jj_] = '\n'; _jj_++;\	          _tmp_buf_[_jj_] = '\0';\                  (*trace_kernel_functions)[_ii_-1]( tv_adr, tid, lvl, _tmp_buf_ , ## params );\              }\	    }\        }\    } while (0)# endif#define traceControl_Mode( new_mode )	\			({  int	old_mode;\			    old_mode = traceControl_sp->mode;\			    traceControl_sp->mode = new_mode;\			    old_mode;\			})#define traceControl_ModeGet()	\			({  traceControl_sp->mode;\			})#else	/* USER SPACE  -------------------------------------------------------*/static struct s_traceControl	*traceControl_sp=0;static int			*traceLevel_ip;static int			traceTID=0;                                     # define TRACE_INIT_CHECK	do\                                { if (!traceControl_sp)traceControl_Init("");\                                } while (0)# define TRACE_TID		traceTID# define TRACE_FUNCTION( tv_adr, tid, lvl, msg, params... ) \                                trace_function( tv_adr, tid\                                               ,lvl, msg , ## params )/*  For user space multi-module control: *  example:  extern void trace_print( struct timeval, int, int, char*, ...); *            #define TRACE_FUNCTIONS {trace_print} *            #define TRACE_NAME "simple" */# ifndef  TRACE_FUNCTIONS#  define TRACE_FUNCTIONS {0,0,trace_printf}static voidtrace_printf( struct timeval *tv_sp, int tid, int lvl, char *msg, ... ){	va_list		ap;	char		timbuf[100];	int		timlen;	char		*newbuf;	struct tm	tm_s;    localtime_r( (time_t *)&tv_sp->tv_sec, &tm_s );    timlen = strftime( timbuf, sizeof(timbuf), "%a %H:%M:%S", &tm_s );    sprintf( &timbuf[timlen], ".%06d: ", (int)tv_sp->tv_usec );    newbuf = (char *)alloca( timlen+strlen(&timbuf[timlen])+strlen(msg)+2/*room for "\n\0"*/ );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -