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

📄 spylib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (pTcb == NULL)	    continue;	pTcb->taskIncTicks = pTcb->taskTicks = 0;	}    if (sysAuxClkConnect ((FUNCPTR)spyClkInt, 0) != OK)	{	if (printRtn != NULL)	    (* printRtn) ("No auxiliary clock on CPU.\n");	return (ERROR);	}    auxClkTicksPerSecond = sysAuxClkRateGet ();    sysAuxClkRateSet (intsPerSec);    sysAuxClkEnable ();    spyClkRunning = TRUE;    return (OK);    }/********************************************************************************* spyClkStopCommon - stop collecting task activity data** This routine disables the auxiliary clock interrupts.* Data collected remains valid until the next spyClkStart() call.** RETURNS: N/A** SEE ALSO: spyClkStart()** NOMANUAL*/void spyClkStopCommon (void)    {    sysAuxClkRateSet (auxClkTicksPerSecond);    sysAuxClkDisable ();    spyClkRunning  = FALSE;    }/********************************************************************************* spyReportCommon - display task activity data** This routine reports on data gathered at interrupt level for the amount of* CPU time utilized by each task, the amount of time spent at interrupt level,* the amount of time spent in the kernel, and the amount of idle time.  Time* is displayed in ticks and as a percentage, and the data is shown since both* the last call to spyClkStart() and the last spyReport().  If no interrupts* have occurred since the last spyReport(), nothing is displayed.** RETURNS: N/A** SEE ALSO: spyClkStart()** NOMANUAL*/void spyReportCommon     (    FUNCPTR printRtn		/* routine to display result */    )    {    FAST WIND_TCB *pTcb;    FAST int 	   ix;    SYMBOL_ID      symId;    FUNCPTR 	   symbolAddress = 0;    char 	   *name;       /* pointer to symbol table copy of string */    int 	   taskPriority;    char	   demangled [MAX_SYS_SYM_LEN + 1];    char	   *nameToPrint;    int 	   idList [MAX_SPY_TASKS];	/* task specific statistics */    int 	   taskIncTicks [MAX_SPY_TASKS];    int 	   taskTotalTicks [MAX_SPY_TASKS];    FAST int 	   nTasks;    int 	   tmpIncTicks;			/* incremental snap shot */    int 	   tmpIdleIncTicks;    int 	   tmpKernelIncTicks;    int 	   tmpInterruptIncTicks;    int 	   totalPerCent;    int 	   incPerCent;    int 	   sumTotalPerCent = 0;    int 	   sumIncPerCent   = 0;    /* if there have been no ticks, there is nothing to report */    if (spyIncTicks == 0)	return;    /* snap shot and clear task statistics */    nTasks = taskIdListGet (idList, NELEMENTS (idList));    spyTaskIdListSort (idList, nTasks);    for (ix = 0; ix < nTasks; ++ix)	{	pTcb = taskTcb (idList [ix]);	/*	 * Need to make sure pTcb is a valid pointer	 */	if (pTcb == NULL)	    continue;	/* order is important: save and clear incremental, then update total */	taskIncTicks [ix]    = pTcb->taskIncTicks;	pTcb->taskIncTicks  = 0;	pTcb->taskTicks    += taskIncTicks [ix];	taskTotalTicks [ix]  = pTcb->taskTicks;	}    /* save and clear incremental counts and accumulate totals */    tmpIncTicks          = spyIncTicks;    tmpIdleIncTicks      = spyIdleIncTicks;    tmpKernelIncTicks    = spyKernelIncTicks;    tmpInterruptIncTicks = spyInterruptIncTicks;    spyIncTicks = spyIdleIncTicks = spyKernelIncTicks = spyInterruptIncTicks =0;    spyTotalTicks       += tmpIncTicks;    spyInterruptTicks   += tmpInterruptIncTicks;    spyKernelTicks      += tmpKernelIncTicks;    spyIdleTicks        += tmpIdleIncTicks;    if (printRtn == NULL)	/* for host browser don't display result */	return;    /* print info */    (* printRtn) ("\n");    (* printRtn) (    "NAME          ENTRY         TID   PRI   total %% (ticks)  delta %% (ticks)\n");    (* printRtn) (    "--------     --------      -----  ---   ---------------  ---------------\n");    for (ix = 0; ix < nTasks; ++ix)	{	/* find name in symbol table */	pTcb = taskTcb (idList [ix]);	/*	 * Need to make sure pTcb is a valid pointer	 */	if (pTcb == NULL)	    continue;        /* 	 * Only check one symLib function pointer (for performance's sake). All	 * symLib functions are provided by the same library, by convention.    	 */	if ((_func_symFindSymbol !=(FUNCPTR) NULL) &&	    (sysSymTbl != NULL))	    {	    if ((* _func_symFindSymbol) (sysSymTbl,  NULL, 					 (void *)pTcb->entry, 					 SYM_MASK_NONE, SYM_MASK_NONE, 					 &symId) == OK)	        {		(* _func_symNameGet) (symId, &name);		(* _func_symValueGet) (symId, (void **) &symbolAddress); 		}	    }	if (symbolAddress != pTcb->entry)	    name = "\0";	         /* no matching symbol */	            taskPriorityGet (idList [ix], &taskPriority);	/* print line for this task */	totalPerCent     = (taskTotalTicks [ix] * 100) / spyTotalTicks;	incPerCent       = (taskIncTicks [ix] * 100) / tmpIncTicks;	sumTotalPerCent += totalPerCent;	sumIncPerCent   += incPerCent;	nameToPrint = cplusDemangle (name, demangled, sizeof (demangled));	(* printRtn) (spyFmt1, pTcb->name, nameToPrint, idList [ix], 		      taskPriority, totalPerCent, taskTotalTicks [ix],		      incPerCent, taskIncTicks [ix]);	}    totalPerCent     = (spyKernelTicks * 100) / spyTotalTicks;    incPerCent       = (tmpKernelIncTicks * 100) / tmpIncTicks;    sumTotalPerCent += totalPerCent;    sumIncPerCent   += incPerCent;    (* printRtn) (spyFmt2, "KERNEL", "", "", "", totalPerCent, spyKernelTicks,				      incPerCent, tmpKernelIncTicks);    totalPerCent     = (spyInterruptTicks * 100) / spyTotalTicks;    incPerCent       = (tmpInterruptIncTicks * 100) / tmpIncTicks;    sumTotalPerCent += totalPerCent;    sumIncPerCent   += incPerCent;    (* printRtn) (spyFmt2, "INTERRUPT", "", "", "", totalPerCent, spyInterruptTicks,				      incPerCent, tmpInterruptIncTicks);    totalPerCent     = (spyIdleTicks * 100) / spyTotalTicks;    incPerCent       = (tmpIdleIncTicks * 100) / tmpIncTicks;    sumTotalPerCent += totalPerCent;    sumIncPerCent   += incPerCent;    (* printRtn) (spyFmt2, "IDLE", "", "", "", totalPerCent, spyIdleTicks,				 incPerCent, tmpIdleIncTicks);    (* printRtn) (spyFmt2, "TOTAL", "", "", "", sumTotalPerCent, spyTotalTicks,				  sumIncPerCent, tmpIncTicks);    (* printRtn) ("\n");    if (spyCreateCount > 0)	{	(* printRtn) ("%d task%s created.\n", spyCreateCount,		spyCreateCount == 1 ? " was" : "s were");	spyCreateCount = 0;	}    if (spyDeleteCount > 0)	{	(* printRtn) ("%d task%s deleted.\n", spyDeleteCount,		spyDeleteCount == 1 ? " was" : "s were");	spyDeleteCount = 0;	}    }/********************************************************************************* spyComTask - run periodic task activity reports** This routine is spawned as a task by spy() to provide periodic task* activity reports.  It prints a report, delays for the specified number of* seconds, and repeats.** RETURNS: N/A** SEE ALSO: spy()** NOMANUAL*/void spyComTask    (    int		freq,		/* reporting frequency, in seconds */    FUNCPTR	printRtn	/* routine to display results */    )    {    int delay = freq * sysClkRateGet ();    while (TRUE)	{	spyReportCommon (printRtn);	taskDelay (delay);	}    }/********************************************************************************* spyStopCommon - stop spying and reporting** This routine calls spyClkStop().  Any periodic reporting by spyTask()* is terminated.** RETURNS: N/A** SEE ALSO: spyClkStop(), spyTask()** NOMANUAL*/void spyStopCommon (void)    {    spyClkStopCommon ();    if (spyTaskId != ERROR)	{	taskDelete (spyTaskId);	spyTaskId = ERROR;	}    }/********************************************************************************* spyCommon - begin periodic task activity reports** This routine collects task activity data and periodically runs spyReport().* Data is gathered <ticksPerSec> times per second, and a report is made every* <freq> seconds.  If <freq> is zero, it defaults to 5 seconds.  If* <ticksPerSec> is omitted or zero, it defaults to 100.** This routine spawns spyTask() to do the actual reporting.** It is not necessary to call spyClkStart() before running spy().** RETURNS: N/A** SEE ALSO: spyClkStart(), spyTask()** NOMANUAL*/void spyCommon    (    int		freq,		/* reporting freq in sec, 0 = default of 5 */    int		ticksPerSec,	/* interrupt clock freq, 0 = default of 100 */    FUNCPTR	printRtn	/* routine to use to display results */    )    {    if (freq == 0)	freq = 5;	/* default frequency is 5 secs */    if (spyClkStartCommon (ticksPerSec, printRtn) == OK)	{	spyTaskId = taskSpawn ("tSpyTask", spyTaskPriority,			       spyTaskOptions, spyTaskStackSize,			       (FUNCPTR)spyComTask, freq, (int) printRtn, 			       0, 0, 0, 0, 0, 0, 0, 0);	if ((spyTaskId == ERROR)&& (printRtn != NULL))	    (* printRtn) ("Unable to spawn spyTask.\n");	}    }/********************************************************************************* spyTaskIdListSort - sort the ID list by priority** This routine sorts the task ID list <idList> by task priority.** RETURNS: N/A*/LOCAL void spyTaskIdListSort    (    int idList[],    int nTasks    )    {    FAST int temp;    int prevPri;    int curPri;    FAST int *pCurId;    BOOL change = TRUE;    FAST int *pEndId = &idList [nTasks];    if (nTasks == 0)        return;    while (change)        {        change = FALSE;        taskPriorityGet (idList[0], &prevPri);        for (pCurId = &idList[1]; pCurId < pEndId; ++pCurId, prevPri = curPri)            {            taskPriorityGet (*pCurId, &curPri);            if (prevPri > curPri)                {                temp = *pCurId;                *pCurId = *(pCurId - 1);                *(pCurId - 1) = temp;                change = TRUE;                }            }        }    }

⌨️ 快捷键说明

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