This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
RE: Re: listing all threads
- From: "Zimman, Chris" <czimman at bloomberg dot com>
- To: "Good Guy" <gooodguy at gmail dot com>
- Cc: "eCos Discussion" <ecos-discuss at ecos dot sourceware dot org>
- Date: Wed, 23 Nov 2005 15:29:28 -0500
- Subject: RE: [ECOS] Re: listing all threads
We wrote this little function you may find useful:
#include <cyg/infra/cyg_type.h>
#include <cyg/hal/var_ints.h>
#include <cyg/kernel/kapi.h>
static const unsigned char * const thread_state_str[] = {
"RUN", /* 0 - Running */
"SLEEP", /* 1 - Sleeping */
"CNTSLP", /* 2 - Counted sleep */
"SLPSET", /* 3 - Sleep set */
"SUSP", /* 4 - Suspended */
NULL, /* 5 - INVALID */
NULL, /* 6 - INVALID */
NULL, /* 7 - INVALID */
"CREAT", /* 8 - Creating */
NULL, /* 9 - INVALID */
NULL, /* 10 - INVALID */
NULL, /* 11 - INVALID */
NULL, /* 12 - INVALID */
NULL, /* 13 - INVALID */
NULL, /* 14 - INVALID */
NULL, /* 15 - INVALID */
"EXIT" /* 16 - Exiting */
};
/*
* This function produces a list of the threads
* that are currently scheduled. The output is roughly
* analagous to 'ps', with the exception of VSS for obvious
* reasons
*/
void get_thread_info()
{
cyg_handle_t thandle = 0, *thandleptr = &thandle;
cyg_uint16 tid;
cyg_thread_info tinfo;
/*
* Because we're running this on ourselves,
* it's basically guaranteed to be OK the first
* time through
*/
cyg_thread_get_next(thandleptr, &tid);
printf("%-8s %-2s %-6s %-15s %-2s %-2s %-10s %-10s %-10s\n",
"-------",
"--",
"------",
"----------------------",
"--",
"--",
"----------",
"----------",
"----------");
printf("%-8s %-2s %-6s %-22s %-2s %-2s %-10s %-10s %-10s\n",
"Handle",
"ID",
"State",
"Name",
"SP",
"CP",
"Stack Base",
"Stack Size",
"Stack Used");
printf("%-8s %-2s %-6s %-22s %-2s %-2s %-10s %-10s %-10s\n",
"-------",
"--",
"------",
"----------------------",
"--",
"--",
"----------",
"----------",
"----------");
do {
cyg_thread_get_info(*thandleptr, tid, &tinfo);
printf("%-8d %-2d %-6s %-22s %-2d %-2d 0x%08x 0x%08x 0x%08x\n",
tinfo.handle,
tinfo.id,
thread_state_str[tinfo.state],
tinfo.name,
tinfo.set_pri,
tinfo.cur_pri,
tinfo.stack_base,
tinfo.stack_size,
tinfo.stack_used);
} while(cyg_thread_get_next(thandleptr, &tid));
#if defined(THREADINFO_DEBUG)
printf("Here I am:\n");
printf("Handle-> %d\n", tinfo.handle);
printf("ID-> %d\n", tinfo.id);
printf("State-> 0x%08x\n", tinfo.state);
printf("Name-> '%s'\n", tinfo.name);
printf("Set Priority-> 0x%08x\n", tinfo.set_pri);
printf("Current Priority-> 0x%08x\n", tinfo.cur_pri);
printf("Stack base-> 0x%08x\n", tinfo.stack_base);
printf("Stack size-> 0x%08x\n", tinfo.stack_size);
printf("Stack used-> 0x%08x\n", tinfo.stack_used);
#endif /* defined(THREADINFO_DEBUG) */
}
--Chris
-----Original Message-----
From: ecos-discuss-owner@ecos.sourceware.org
[mailto:ecos-discuss-owner@ecos.sourceware.org] On Behalf Of Nick
Garnett
Sent: Wednesday, November 23, 2005 5:13 AM
To: Good Guy
Cc: eCos Discussion
Subject: Re: [ECOS] Re: listing all threads
Gary Thomas <gary@mlbassoc.com> writes:
> On Tue, 2005-11-22 at 15:12 -0800, Good Guy wrote:
> > I was looking for a utility function which will list all the threads
> > (and state associated with each thread) in a running system. Does
such
> > a function or some sample code to help write this function exist?
I'm
> > using ecos 1.3.1.
> ^^^^^^^^^^
> Now some 5+ years old, so you may have challenges ahead. Why not
> update?
>
> Any way, the basic code to do this is in the GDB stubs. Look at
> .../hal/common/<VERSION>/src
There's an API to do this from user code. Take a look at
cyg_thread_get_info() and friends. It is described in the
documentation. However, it is not present in 1.3.1.
--
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com The eCos and RedBoot experts
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss