2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
9 /******************************************************************************
26 Prints a list of tasks with their stack usage.
44 ******************************************************************************/
46 #include <exec/exec.h>
47 #include <exec/execbase.h>
48 #include <exec/tasks.h>
49 #include <exec/rawfmt.h>
51 #include <proto/exec.h>
52 #include <proto/dos.h>
53 #include <proto/debug.h>
54 #include <proto/alib.h>
58 #define ARG_TEMPLATE "TASK/K,DEBUG/S"
64 static struct RDArgs
*MyArgs
;
65 static IPTR Args
[NUM_ARGS
];
68 static UBYTE outbuffer
[20000];
69 static LONG outbuffer_size
;
71 static void Cleanup(char *msg
)
74 Printf("stacksnoop: %s\n",msg
);
76 if (MyArgs
) FreeArgs(MyArgs
);
79 static ULONG
GetArguments(void)
81 if (!(MyArgs
= ReadArgs(ARG_TEMPLATE
,Args
,0)))
83 Fault(IoErr(),0,s
,255);
90 static int out (const UBYTE
* fmt
, ...)
97 VNewRawDoFmt(fmt
, RAWFMTFUNC_STRING
, &outbuffer
[outbuffer_size
], ap
);
98 result
= strlen(&outbuffer
[outbuffer_size
]);
101 KPutStr(&outbuffer
[outbuffer_size
]);
103 outbuffer_size
+= result
;
111 static void CheckTaskStack(struct Task
*task
)
113 UBYTE
*startcheck
, *endcheck
;
114 LONG stacksize
, stackinc
, unusedstack
= 0;
116 stacksize
= (LONG
)( ((UBYTE
*)task
->tc_SPUpper
) - ((UBYTE
*)task
->tc_SPLower
) );
118 #if AROS_STACK_GROWS_DOWNWARDS
119 startcheck
= (UBYTE
*)task
->tc_SPLower
;
120 endcheck
= ((UBYTE
*)task
->tc_SPUpper
) - 1;
123 startcheck
= ((UBYTE
*)task
->tc_SPUpper
) - 1;
124 endcheck
= (UBYTE
*)task
->tc_SPLower
;
128 for(; startcheck
!= endcheck
; startcheck
+= stackinc
)
130 if (*startcheck
!= 0xE1) break;
134 out("Task %x (%25s) Stack Size =%6d, Left =%6d, Used %s%6d%s\n",
136 task
->tc_Node
.ln_Name
?
137 (const char *)task
->tc_Node
.ln_Name
: "<NONAME>",
140 ((stacksize
- unusedstack
) < stacksize
) ? "=" : ">",
141 stacksize
- unusedstack
,
142 (unusedstack
< 512) ? ": Needs more stack!!!!!!!!!" : "");
145 static void Action(void)
152 out("\n------------------------------------------------------------------------------\n\n");
154 task
= (struct Task
*)SysBase
->TaskReady
.lh_Head
;
155 for(i
= 0; i
< 2;i
++)
157 while(task
->tc_Node
.ln_Succ
)
159 CheckTaskStack(task
);
161 task
= (struct Task
*)task
->tc_Node
.ln_Succ
;
162 } /* while(task->tc_Node.ln_Succ) */
164 task
= (struct Task
*)SysBase
->TaskWait
.lh_Head
;
166 } /* for(i = 0; i < 2;i++) */
168 CheckTaskStack(FindTask(NULL
));
169 out("\n------------------------------------------------------------------------------\n\n");
176 ULONG __nocommandline
= 1;