[En-Nut-Discussion] Suggested Change: Support Thread Stack Monitoring

Brett Abbott Brett.Abbott at digital-telemetry.com
Mon Mar 7 05:16:53 CET 2005


Hi

Ive found it useful to be able closely monitor the amount of unused 
stack, especially when testing new applications or environments.  A 
number of others have also discussed this in this list over the years.  
Ive made the following minor change to avr_thread.c which I believe has 
a minor impact on NutOS but allows easy monitoring of the stack.  I also 
include example changes to the "threads" command found in many of the 
demo applications.

Is there a better way? Perhaps it or something similar could be 
considered for inclusion in NutOS.

Regards
Brett

avr_thread.c: (This would have to be done to the other os's as well)
// Only changed NutHeapAlloc to NutHeapAllocClear to ensure 
// cleaned memory as the memory cannot be guaranteed to be 
// clear after reset.  No other change.

 /*
     * Allocate stack and thread info structure in one block.
     */
    if ((threadMem = NutHeapAllocClear(stackSize + sizeof(NUTTHREADINFO))) == 0) {
        NutExitCritical();
        return 0;
    }

//---------------------------------------------------------
Change to demo application.  
1.Additional field in threads header line.
2.Additonal function call to count the free memory bytes
3.Addtional output of stack "ClearBytes" value

// 1.Additional field in threads header line.

prog_char thread_intro_P[] = "220 List of threads with name,state,prio,stack,mem,clearBytes,timeout follows\r\n";

//2.Additonal function call to count the free memory bytes
int CountZeroes(u_char *td_memory)
{
    int myInt=0;
	u_char *myPtr=td_memory;
	while(*(myPtr++)==0)
	    myInt++;
	
	return myInt;
}


//3.Addtional output of stack "ClearBytes" value

// Count the amount of untouched memory left in the stack for this thread
// This requires the patch to NutThreadCreate to clear allocated heap to be effective    
fprintf(stream, "\t%d\t", CountZeroes(tdp->td_memory+16));



-- 
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860  Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.egnite.de/pipermail/en-nut-discussion/attachments/20050307/f6a1872e/attachment.html>


More information about the En-Nut-Discussion mailing list