1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

* added thread stat printing function (ps)

This commit is contained in:
Kaspar Schleiser 2010-09-24 16:50:14 +02:00
parent 948e430148
commit 7108f791fa
3 changed files with 64 additions and 0 deletions

View File

@ -30,6 +30,7 @@ SubDir TOP sys ;
Module swtimer : swtimer.c : hwtimer ;
Module posix_io : posix_io.c ;
Module shell : shell.c : hashtable hash_string ;
Module ps : ps ;
Module auto_init : auto_init.c ;

7
sys/include/ps.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef __PS_H
#define __PS_H
void thread_print_all();
void _ps_handler(char*);
#endif /* __PS_H */

56
sys/ps.c Normal file
View File

@ -0,0 +1,56 @@
#include <thread.h>
#include <hwtimer.h>
#include <scheduler.h>
#include <stdio.h>
/* list of states copied from tcb.h */
const char *state_names[] = {
"running",
"pending",
"stopped",
"sleeping",
"bl mutex",
"bl rx",
"bl send",
"bl reply"
};
/**
* @brief Prints a list of running threads including stack usage to stdout.
*/
void thread_print_all(void)
{
extern unsigned long hwtimer_now(void);
const char queued_name[] = {'_', 'Q'};
int i;
int overall_stacksz = 0;
printf("\tpid | %-21s| %-9sQ | pri | stack ( used) location | runtime | switches \n", "name", "state");
for( i = 0; i < MAXTHREADS; i++ ) {
tcb* p = (tcb*)fk_threads[i];
if( p != NULL ) {
int state = p->status; // copy state
int statebit = number_of_highest_bit(state >> 1); // get state index
const char* sname = state_names[statebit]; // get state name
const char* queued = queued_name + (state & BIT0); // get queued flag
int stacksz = p->stack_size; // get max used stack
double runtime = 0/0.0;
int switches = -1;
#if SCHEDSTATISTICS
runtime = pidlist[i].runtime / (double) hwtimer_now() * 100;
switches = pidlist[i].schedules;
#endif
overall_stacksz += stacksz;
stacksz -= fk_measure_stack_free(p->stack_start);
printf("\t%3u | %-21s| %-8s %.1s | %3i | %5i (%5i) %p | %6.3f%% | %8i\n",
p->pid, p->name, sname, queued, p->priority, p->stack_size, stacksz, p->stack_start, runtime, switches);
}
}
printf("\t%5s %-21s|%13s%6s %5i\n", "|", "SUM", "|", "|", overall_stacksz);
}
void _ps_handler(char* unnused) {
thread_print_all();
}