markwrichardson wrote on Tuesday, December 09, 2014:
I did the following . . .
The current running job info is application specific, but you should get
the idea
//======================================================================
//
// notes for below
//======================================================================
/*
-- TaskStatus_t type
TaskHandle_t xHandle - The handle of the task
const signed char * pcTaskName - A pointer to the task's name
unsigned BaseType_t xTaskNumber - A number unique to the task
eTaskState eCurrentState - Task state
unsigned BaseType_t uxCurrentPriority - task Priority
unsigned BaseType_t uxBasePriority - Normal Priority
unsigned long ulRunTimeCounter - Total Run time
unsigned short usStackHighWaterMark - smallest stack remaining so far
eTaskState
'G' eRunning = 0, A task is querying the state of itself, so must be running.
'R' eReady, The task being queried is in a read or pending ready list.
'B' eBlocked, The task being queried is in the Blocked state.
'S' eSuspended, The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out.
'D' eDeleted The task being queried has been deleted, but its TCB has not yet been freed.
*/
// put here instead of altering the distro
void * xTimerGetTimerDaemonTaskHandle( void );
//{ "TASKLIST", "Show all tasks and stats", 0,0, "", { 0 }, 0, 'N', ' ', 's', '=', &cmd_TASKLIST },
//======================================================================
//
// report task statistics to the console
//======================================================================
int cmd_TASKLIST( CMDARG *args )
{
TaskStatus_t TaskInfo[1 + TC_BASICTASKS + TC_MAXJOBTASKS + 1];
unsigned portCHAR TaskCnt;
unsigned portLONG TotalRunTime;
unsigned portCHAR TaskIdx;
portCHAR st;
size_t FreeHeap;
TASKCTLITEM *pTCI;
char CmdString[41];
char Jobstate;
CMDJOBNO JobNumber;
uint16_t StackSize;
char LockListBuffer[100];
vTaskSuspendAll();
TaskCnt = uxTaskGetSystemState( TaskInfo, (1 + TC_BASICTASKS + TC_MAXJOBTASKS + 1), &TotalRunTime);
CIOCommandOutLine("Name Tn S P p RunTime StkRmn/StkSiz St JobNum CmdString");
for(TaskIdx = 0; TaskIdx < TaskCnt; TaskIdx ++)
{
switch (TaskInfo[TaskIdx].eCurrentState)
{
case eRunning:
st = 'G';
break;
case eReady:
st = 'r';
break;
case eBlocked:
st = 'b';
break;
case eSuspended:
st = 's';
break;
case eDeleted:
st = 'd';
break;
default:
st = '?';
break;
};
pTCI = (TASKCTLITEM *) xTaskGetApplicationTaskTag( TaskInfo[TaskIdx].xHandle );
if (pTCI)
{
if (pTCI->Job ) // JobInfo gets set to zero after Jobstate;
{
strncpy(CmdString, pTCI->Job->Args.cmdinput, 40);
}
JobNumber = pTCI->Job->JobNo;
Jobstate = pTCI->JobState; // get Jobstate after and test in case job ends
StackSize = pTCI->StackSize;
if (Jobstate != TC_NOJOB)
{
CmdString[40] = 0;
LockListBuffer[0] = 0;
RSLMakeListAllDomainLocksForTaskId( pTCI, LockListBuffer );
}
else
{
// if no job, don't trust job info
CmdString[0] = 0;
JobNumber = 0;
Jobstate = ' ';
LockListBuffer[0] = 0;
}
}
else
{
if (TaskInfo[TaskIdx].xHandle == xTaskGetIdleTaskHandle())
{
Jobstate = ' ';
CmdString[0] = 0;
JobNumber = 0;
StackSize = configMINIMAL_STACK_SIZE;
}
else if (TaskInfo[TaskIdx].xHandle == xTimerGetTimerDaemonTaskHandle())
{
Jobstate = ' ';
CmdString[0] = 0;
JobNumber = 0;
StackSize = configTIMER_TASK_STACK_DEPTH;
}
else
{
Jobstate = ' ';
CmdString[0] = 0;
JobNumber = 0;
StackSize = 0;
}
}
CIOCommandOutLine("%-*.*s %2d %c %2d %2d %7ld %6d/%6d %c %6d %-40.40s",
14,
configMAX_TASK_NAME_LEN-1,
TaskInfo[TaskIdx].pcTaskName,
TaskInfo[TaskIdx].xTaskNumber,
st,
TaskInfo[TaskIdx].uxCurrentPriority,
TaskInfo[TaskIdx].uxBasePriority,
TaskInfo[TaskIdx].ulRunTimeCounter,
TaskInfo[TaskIdx].usStackHighWaterMark,
StackSize,
Jobstate,
JobNumber,
CmdString );
if ( LockListBuffer[0] != 0 )
CIOCommandOutLine( " - Locks held: %s", LockListBuffer );
}
FreeHeap = xPortGetFreeHeapSize();
CIOCommandOutLine( "Heap Remaining = %u of %u", FreeHeap, configTOTAL_HEAP_SIZE);
CIOCommandOutLine( "Active Job Count = %u", UCL_GetActiveJobCount() );
xTaskResumeAll();
return 0;
}