cpukit/capture: Update the capture engine.

The capture did not work due to changes in the workspace allocator.
The engine now scans all existing tasks when enabled and does any
allocations then.

Fixed a bug in the ctset commandi in the CLI.

Updated the capture engine to use 64bit nanosec timestamps.

Fixed the CLI showing the stack usage.
This commit is contained in:
Chris Johns
2013-12-19 19:01:23 +11:00
parent f466e567a1
commit db8a89e212
3 changed files with 195 additions and 233 deletions

View File

@@ -36,6 +36,8 @@
#include <rtems/capture-cli.h> #include <rtems/capture-cli.h>
#include <rtems/monitor.h> #include <rtems/monitor.h>
#define RC_UNUSED __attribute__((unused))
#define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (20) #define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (20)
/* /*
@@ -61,10 +63,10 @@ static volatile int cli_load_thread_active;
static const char* open_usage = "usage: copen [-i] size\n"; static const char* open_usage = "usage: copen [-i] size\n";
static void static void
rtems_capture_cli_open (int argc, rtems_capture_cli_open (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
uint32_t size = 0; uint32_t size = 0;
bool enable = false; bool enable = false;
@@ -132,10 +134,10 @@ rtems_capture_cli_open (int argc,
*/ */
static void static void
rtems_capture_cli_close (int argc __attribute__((unused)), rtems_capture_cli_close (int argc RC_UNUSED,
char** argv __attribute__((unused)), char** argv RC_UNUSED,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
@@ -160,10 +162,10 @@ rtems_capture_cli_close (int argc __attribute__((unused
*/ */
static void static void
rtems_capture_cli_enable (int argc __attribute__((unused)), rtems_capture_cli_enable (int argc RC_UNUSED,
char** argv __attribute__((unused)), char** argv RC_UNUSED,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
@@ -188,10 +190,10 @@ rtems_capture_cli_enable (int argc __attribute__((unuse
*/ */
static void static void
rtems_capture_cli_disable (int argc __attribute__((unused)), rtems_capture_cli_disable (int argc RC_UNUSED,
char** argv __attribute__((unused)), char** argv RC_UNUSED,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
@@ -216,44 +218,35 @@ rtems_capture_cli_disable (int argc __attribute__((unus
*/ */
static void static void
rtems_capture_cli_task_list (int argc __attribute__((unused)), rtems_capture_cli_task_list (int argc RC_UNUSED,
char** argv __attribute__((unused)), char** argv RC_UNUSED,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_task_priority ceiling = rtems_capture_watch_get_ceiling (); rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
rtems_task_priority floor = rtems_capture_watch_get_floor (); rtems_task_priority floor = rtems_capture_watch_get_floor ();
rtems_capture_task_t* task = rtems_capture_get_task_list (); rtems_capture_task_t* task = rtems_capture_get_task_list ();
uint32_t ticks; rtems_capture_time_t total_time;
uint32_t tick_offset;
unsigned long long total_time;
int count = rtems_capture_task_count (); int count = rtems_capture_task_count ();
if (capture_timestamp) rtems_capture_time (&total_time);
capture_timestamp (&ticks, &tick_offset);
else
{
ticks = rtems_clock_get_ticks_since_boot();
tick_offset = 0;
}
fprintf (stdout, "total %i\n", count); fprintf (stdout, "total %i time:%Lu\n", count, (uint64_t) total_time);
while (task) while (task)
{ {
rtems_task_priority priority; rtems_task_priority priority;
int32_t stack_used; int32_t stack_used;
int32_t time_used; int32_t time_used;
int length;
stack_used = rtems_capture_task_stack_usage (task); stack_used = rtems_capture_task_stack_usage (task);
if (stack_used) if (stack_used)
stack_used = (stack_used * 100) / stack_used; stack_used = (stack_used * 100) / rtems_capture_task_stack_size (task);
if (stack_used > 100) if (stack_used > 100)
stack_used = 100; stack_used = 100;
total_time = (ticks * rtems_capture_task_time (task)) + tick_offset;
time_used = (rtems_capture_task_time (task) * 100) / total_time; time_used = (rtems_capture_task_time (task) * 100) / total_time;
if (time_used > 100) if (time_used > 100)
@@ -264,7 +257,7 @@ rtems_capture_cli_task_list (int argc __attribute__((un
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_id (rtems_capture_task_id (task)); rtems_monitor_dump_id (rtems_capture_task_id (task));
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_name (rtems_capture_task_name (task)); rtems_monitor_dump_name (rtems_capture_task_id (task));
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_priority (rtems_capture_task_start_priority (task)); rtems_monitor_dump_priority (rtems_capture_task_start_priority (task));
fprintf (stdout, " "); fprintf (stdout, " ");
@@ -272,7 +265,8 @@ rtems_capture_cli_task_list (int argc __attribute__((un
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_priority (rtems_capture_task_curr_priority (task)); rtems_monitor_dump_priority (rtems_capture_task_curr_priority (task));
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_state (rtems_capture_task_state (task)); length = rtems_monitor_dump_state (rtems_capture_task_state (task));
fprintf (stdout, "%*c", 14 - length, ' ');
fprintf (stdout, " %c%c", fprintf (stdout, " %c%c",
rtems_capture_task_valid (task) ? 'a' : 'd', rtems_capture_task_valid (task) ? 'a' : 'd',
rtems_capture_task_flags (task) & RTEMS_CAPTURE_TRACED ? 't' : '-'); rtems_capture_task_flags (task) & RTEMS_CAPTURE_TRACED ? 't' : '-');
@@ -287,8 +281,8 @@ rtems_capture_cli_task_list (int argc __attribute__((un
(flags & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-', (flags & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
rtems_capture_watch_global_on () ? 'g' : '-'); rtems_capture_watch_global_on () ? 'g' : '-');
} }
fprintf (stdout, " %3" PRId32 "%% %3" PRId32 "%% (%" PRIu32 ")\n", fprintf (stdout, " %3" PRId32 "%% %3" PRId32 "%% (%" PRIu64 ")\n",
stack_used, time_used, rtems_capture_task_ticks (task)); stack_used, time_used, rtems_capture_task_time (task));
task = rtems_capture_next_task (task); task = rtems_capture_next_task (task);
} }
@@ -304,7 +298,7 @@ rtems_capture_cli_task_list (int argc __attribute__((un
*/ */
static void static void
rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unused))) rtems_capture_cli_task_load_thread (rtems_task_argument arg RC_UNUSED)
{ {
rtems_task_priority ceiling = rtems_capture_watch_get_ceiling (); rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
rtems_task_priority floor = rtems_capture_watch_get_floor (); rtems_task_priority floor = rtems_capture_watch_get_floor ();
@@ -315,7 +309,7 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
rtems_capture_task_t* tasks[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1]; rtems_capture_task_t* tasks[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
unsigned long long load[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1]; unsigned long long load[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
rtems_capture_task_t* task; rtems_capture_task_t* task;
unsigned long long total_time; rtems_capture_time_t total_time;
int count = 0; int count = 0;
int i; int i;
int j; int j;
@@ -339,7 +333,7 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
{ {
if (rtems_capture_task_valid (task)) if (rtems_capture_task_valid (task))
{ {
unsigned long long l = rtems_capture_task_delta_time (task); rtems_capture_time_t l = rtems_capture_task_delta_time (task);
count++; count++;
@@ -369,7 +363,7 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
fprintf (stdout, "\x1b[H\x1b[J Press ENTER to exit.\n\n"); fprintf (stdout, "\x1b[H\x1b[J Press ENTER to exit.\n\n");
fprintf (stdout, fprintf (stdout,
" PID NAME RPRI CPRI STATE %%CPU %%STK FLGS EXEC TIME\n"); " PID NAME RPRI CPRI STATE %%CPU %%STK FLGS EXEC TIME\n");
if (count > last_count) if (count > last_count)
j = count; j = count;
@@ -390,7 +384,7 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
stack_used = rtems_capture_task_stack_usage (tasks[i]); stack_used = rtems_capture_task_stack_usage (tasks[i]);
if (stack_used) if (stack_used)
stack_used = (stack_used * 100) / stack_used; stack_used = (stack_used * 100) / rtems_capture_task_stack_size (tasks[i]);
if (stack_used > 100) if (stack_used > 100)
stack_used = 100; stack_used = 100;
@@ -402,14 +396,14 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
fprintf (stdout, "\x1b[K"); fprintf (stdout, "\x1b[K");
rtems_monitor_dump_id (rtems_capture_task_id (tasks[i])); rtems_monitor_dump_id (rtems_capture_task_id (tasks[i]));
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_name (rtems_capture_task_name (tasks[i])); rtems_monitor_dump_name (rtems_capture_task_id (tasks[i]));
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_priority (priority); rtems_monitor_dump_priority (priority);
fprintf (stdout, " "); fprintf (stdout, " ");
rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tasks[i])); rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tasks[i]));
fprintf (stdout, " "); fprintf (stdout, " ");
k = rtems_monitor_dump_state (rtems_capture_task_state (tasks[i])); k = rtems_monitor_dump_state (rtems_capture_task_state (tasks[i]));
fprintf (stdout, "%*c %3i.%03i%% ", 6 - k, ' ', fprintf (stdout, "%*c %3i.%03i%% ", 14 - k, ' ',
task_load / 1000, task_load % 1000); task_load / 1000, task_load % 1000);
fprintf (stdout, "%3i%% %c%c", stack_used, fprintf (stdout, "%3i%% %c%c", stack_used,
rtems_capture_task_valid (tasks[i]) ? 'a' : 'd', rtems_capture_task_valid (tasks[i]) ? 'a' : 'd',
@@ -424,7 +418,8 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-', RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
rtems_capture_watch_global_on () ? 'g' : '-'); rtems_capture_watch_global_on () ? 'g' : '-');
fprintf (stdout, " %qi\n", rtems_capture_task_time (tasks[i])); fprintf (stdout, " %qi\n",
rtems_capture_task_time (tasks[i]));
} }
if (count < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS) if (count < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS)
@@ -455,10 +450,10 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
*/ */
static void static void
rtems_capture_cli_task_load (int argc __attribute__((unused)), rtems_capture_cli_task_load (int argc RC_UNUSED,
char** argv __attribute__((unused)), char** argv RC_UNUSED,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
rtems_task_priority priority; rtems_task_priority priority;
@@ -528,10 +523,10 @@ rtems_capture_cli_task_load (int argc __attribute__((un
*/ */
static void static void
rtems_capture_cli_watch_list (int argc __attribute__((unused)), rtems_capture_cli_watch_list (int argc RC_UNUSED,
char** argv __attribute__((unused)), char** argv RC_UNUSED,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_capture_control_t* control = rtems_capture_get_control_list (); rtems_capture_control_t* control = rtems_capture_get_control_list ();
rtems_task_priority ceiling = rtems_capture_watch_get_ceiling (); rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
@@ -618,11 +613,11 @@ rtems_capture_cli_watch_list (int argc __attribute__((u
*/ */
static bool static bool
rtems_capture_cli_get_name_id (char* arg, rtems_capture_cli_get_name_id (char* arg,
bool* valid_name, bool* valid_name,
bool* valid_id, bool* valid_id,
rtems_name* name, rtems_name* name,
rtems_id* id) rtems_id* id)
{ {
size_t l; size_t l;
size_t i; size_t i;
@@ -680,10 +675,10 @@ rtems_capture_cli_get_name_id (char* arg,
static char const * watch_add_usage = "usage: cwadd [task name] [id]\n"; static char const * watch_add_usage = "usage: cwadd [task name] [id]\n";
static void static void
rtems_capture_cli_watch_add (int argc, rtems_capture_cli_watch_add (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
int arg; int arg;
@@ -743,10 +738,10 @@ rtems_capture_cli_watch_add (int argc,
static char const * watch_del_usage = "usage: cwdel [task name] [id]\n"; static char const * watch_del_usage = "usage: cwdel [task name] [id]\n";
static void static void
rtems_capture_cli_watch_del (int argc, rtems_capture_cli_watch_del (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
int arg; int arg;
@@ -805,10 +800,10 @@ rtems_capture_cli_watch_del (int argc,
static char const * watch_control_usage = "usage: cwctl [task name] [id] on/off\n"; static char const * watch_control_usage = "usage: cwctl [task name] [id] on/off\n";
static void static void
rtems_capture_cli_watch_control (int argc, rtems_capture_cli_watch_control (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
int arg; int arg;
@@ -872,10 +867,10 @@ rtems_capture_cli_watch_control (int argc,
static char const * watch_global_usage = "usage: cwglob on/off\n"; static char const * watch_global_usage = "usage: cwglob on/off\n";
static void static void
rtems_capture_cli_watch_global (int argc, rtems_capture_cli_watch_global (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
int arg; int arg;
@@ -926,10 +921,10 @@ rtems_capture_cli_watch_global (int argc,
static char const * watch_ceiling_usage = "usage: cwceil priority\n"; static char const * watch_ceiling_usage = "usage: cwceil priority\n";
static void static void
rtems_capture_cli_watch_ceiling (int argc, rtems_capture_cli_watch_ceiling (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
int arg; int arg;
@@ -977,10 +972,10 @@ rtems_capture_cli_watch_ceiling (int argc,
static char const * watch_floor_usage = "usage: cwfloor priority\n"; static char const * watch_floor_usage = "usage: cwfloor priority\n";
static void static void
rtems_capture_cli_watch_floor (int argc, rtems_capture_cli_watch_floor (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
int arg; int arg;
@@ -1082,6 +1077,7 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
rtems_capture_trigger_mode_t trigger_mode = rtems_capture_from_any; rtems_capture_trigger_mode_t trigger_mode = rtems_capture_from_any;
bool trigger_set = false; bool trigger_set = false;
bool is_from = false; bool is_from = false;
bool is_to = false;
rtems_name name = 0; rtems_name name = 0;
rtems_id id = 0; rtems_id id = 0;
bool valid_name = false; bool valid_name = false;
@@ -1137,10 +1133,19 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
if (strcmp (arg[argv], "from") == 0) if (strcmp (arg[argv], "from") == 0)
{ {
if (is_from) if (from_valid_name || from_valid_id)
fprintf (stdout, "warning: extra 'from' ignored\n"); fprintf (stdout, "warning: extra 'from' ignored\n");
is_from = 1; is_from = true;
continue;
}
if (strcmp (arg[argv], "to") == 0)
{
if (to_valid_name || from_valid_id)
fprintf (stdout, "warning: extra 'to' ignored\n");
is_to = true;
continue; continue;
} }
@@ -1150,6 +1155,9 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
if (valid_name) if (valid_name)
{ {
if (!is_from && !is_to)
is_to = true;
if (is_from) if (is_from)
{ {
if (!from_valid_name && !from_valid_id) if (!from_valid_name && !from_valid_id)
@@ -1158,7 +1166,7 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
from_name = name; from_name = name;
} }
else else
fprintf (stdout, "warning: extra arguments ignored\n"); fprintf (stdout, "warning: extra name arguments ignored\n");
} }
else if (!to_valid_name && !to_valid_id) else if (!to_valid_name && !to_valid_id)
{ {
@@ -1166,11 +1174,14 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
to_name = name; to_name = name;
} }
else else
fprintf (stdout, "warning: extra arguments ignored\n"); fprintf (stdout, "warning: extra name arguments ignored\n");
} }
if (valid_id) if (valid_id)
{ {
if (!is_from && !is_to)
is_to = true;
if (is_from) if (is_from)
{ {
if (!from_valid_name && !from_valid_id) if (!from_valid_name && !from_valid_id)
@@ -1179,7 +1190,7 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
from_id = id; from_id = id;
} }
else else
fprintf (stdout, "warning: extra arguments ignored\n"); fprintf (stdout, "warning: extra id arguments ignored\n");
} }
else if (!to_valid_name && !to_valid_id) else if (!to_valid_name && !to_valid_id)
{ {
@@ -1187,7 +1198,7 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
to_id = id; to_id = id;
} }
else else
fprintf (stdout, "warning: extra arguments ignored\n"); fprintf (stdout, "warning: extra id arguments ignored\n");
} }
} }
} }
@@ -1201,7 +1212,7 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
if (!to_valid_name && !to_valid_id && !from_valid_name && !from_valid_id) if (!to_valid_name && !to_valid_id && !from_valid_name && !from_valid_id)
{ {
fprintf (stdout, trigger_set_usage); fprintf (stdout, trigger_set_usage, set ? "ctset" : "ctclear");
return; return;
} }
@@ -1255,10 +1266,10 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
*/ */
static void static void
rtems_capture_cli_trigger_set (int argc, rtems_capture_cli_trigger_set (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_capture_cli_trigger_worker (1, argc, argv); rtems_capture_cli_trigger_worker (1, argc, argv);
} }
@@ -1273,10 +1284,10 @@ rtems_capture_cli_trigger_set (int argc,
*/ */
static void static void
rtems_capture_cli_trigger_clear (int argc, rtems_capture_cli_trigger_clear (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_capture_cli_trigger_worker (0, argc, argv); rtems_capture_cli_trigger_worker (0, argc, argv);
} }
@@ -1291,10 +1302,10 @@ rtems_capture_cli_trigger_clear (int argc,
*/ */
static void static void
rtems_capture_cli_trace_records (int argc, rtems_capture_cli_trace_records (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
bool csv = false; bool csv = false;
@@ -1362,33 +1373,35 @@ rtems_capture_cli_trace_records (int argc,
{ {
if (csv) if (csv)
fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32 fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32
",%03" PRIu32 ",%04" PRIx32 ",%" PRId32 ",%" PRId32 "\n", ",%03" PRIu32 ",%04" PRIx32 ",%" PRId64 "\n",
(uintptr_t) rec->task, (uintptr_t) rec->task,
(rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff, (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
(rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff, (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
(rec->events >> RTEMS_CAPTURE_EVENT_START), (rec->events >> RTEMS_CAPTURE_EVENT_START),
rec->ticks, rec->tick_offset); (uint64_t) rec->time);
else else
{ {
unsigned long long t; rtems_capture_time_t t;
uint32_t event; uint32_t event;
int e; int e;
event = rec->events >> RTEMS_CAPTURE_EVENT_START; event = rec->events >> RTEMS_CAPTURE_EVENT_START;
t = rec->ticks; t = rec->time;
t *= rtems_capture_tick_time ();
t += rec->tick_offset;
for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++) for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++)
{ {
if (event & 1) if (event & 1)
{ {
fprintf (stdout, "%9li.%06li ", (unsigned long) (t / 1000000), fprintf (stdout, "%9li.%06li ",
(unsigned long) (t % 1000000)); (unsigned long) (t / 1000000000ULL),
(unsigned long) (t % 1000000000ULL));
rtems_monitor_dump_id (rtems_capture_task_id (rec->task)); rtems_monitor_dump_id (rtems_capture_task_id (rec->task));
fprintf (stdout, " "); fprintf (stdout, " %c%c%c%c",
rtems_monitor_dump_name (rtems_capture_task_name (rec->task)); (char) (rec->task->name >> 24) & 0xff,
(char) (rec->task->name >> 16) & 0xff,
(char) (rec->task->name >> 8) & 0xff,
(char) (rec->task->name >> 0) & 0xff);
fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n", fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n",
(rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff, (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
(rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff, (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
@@ -1422,10 +1435,10 @@ rtems_capture_cli_trace_records (int argc,
*/ */
static void static void
rtems_capture_cli_flush (int argc, rtems_capture_cli_flush (int argc,
char** argv, char** argv,
const rtems_monitor_command_arg_t* command_arg __attribute__((unused)), const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
bool verbose __attribute__((unused))) bool verbose RC_UNUSED)
{ {
rtems_status_code sc; rtems_status_code sc;
bool prime = true; bool prime = true;

View File

@@ -29,7 +29,9 @@
#include <string.h> #include <string.h>
#include "capture.h" #include "capture.h"
#include <rtems/score/statesimpl.h> #include <rtems/score/statesimpl.h>
#include <rtems/score/todimpl.h>
/* /*
* These events are always recorded and are not part of the * These events are always recorded and are not part of the
@@ -81,7 +83,6 @@ static rtems_id capture_id;
static rtems_capture_timestamp capture_timestamp; static rtems_capture_timestamp capture_timestamp;
static rtems_task_priority capture_ceiling; static rtems_task_priority capture_ceiling;
static rtems_task_priority capture_floor; static rtems_task_priority capture_floor;
static uint32_t capture_tick_period;
static rtems_id capture_reader; static rtems_id capture_reader;
/* /*
@@ -112,15 +113,14 @@ static const char* capture_event_text[] =
* This function returns the current time. If a handler is provided * This function returns the current time. If a handler is provided
* by the user get the time from that. * by the user get the time from that.
*/ */
static inline void rtems_capture_get_time (uint32_t* ticks, static inline void
uint32_t* tick_offset) rtems_capture_get_time (rtems_capture_time_t* time)
{ {
if (capture_timestamp) if (capture_timestamp)
capture_timestamp (ticks, tick_offset); capture_timestamp (time);
else else
{ {
*ticks = rtems_clock_get_ticks_since_boot(); _TOD_Get_uptime(time);
*tick_offset = 0;
} }
} }
@@ -396,6 +396,7 @@ rtems_capture_create_capture_task (rtems_tcb* new_task)
rtems_capture_task_t* task; rtems_capture_task_t* task;
rtems_capture_control_t* control; rtems_capture_control_t* control;
rtems_name name; rtems_name name;
rtems_capture_time_t time;
bool ok; bool ok;
ok = rtems_workspace_allocate (sizeof (*task), (void **) &task); ok = rtems_workspace_allocate (sizeof (*task), (void **) &task);
@@ -406,6 +407,11 @@ rtems_capture_create_capture_task (rtems_tcb* new_task)
return NULL; return NULL;
} }
/*
* Get the current time.
*/
rtems_capture_get_time (&time);
/* /*
* Check the type of name the object has. * Check the type of name the object has.
*/ */
@@ -420,13 +426,10 @@ rtems_capture_create_capture_task (rtems_tcb* new_task)
task->refcount = 0; task->refcount = 0;
task->out = 0; task->out = 0;
task->tcb = new_task; task->tcb = new_task;
task->ticks = 0; task->time = 0;
task->tick_offset = 0; task->time_in = time;
task->ticks_in = 0;
task->tick_offset_in = 0;
task->control = 0; task->control = 0;
task->last_ticks = 0; task->last_time = 0;
task->last_tick_offset = 0;
task->tcb->extensions[capture_extension_index] = task; task->tcb->extensions[capture_extension_index] = task;
@@ -547,7 +550,7 @@ rtems_capture_record (rtems_capture_task_t* task,
if ((events & RTEMS_CAPTURE_RECORD_EVENTS) == 0) if ((events & RTEMS_CAPTURE_RECORD_EVENTS) == 0)
task->flags |= RTEMS_CAPTURE_TRACED; task->flags |= RTEMS_CAPTURE_TRACED;
rtems_capture_get_time (&capture_in->ticks, &capture_in->tick_offset); rtems_capture_get_time (&capture_in->time);
if (capture_in == &capture_records[capture_size - 1]) if (capture_in == &capture_records[capture_size - 1])
capture_in = capture_records; capture_in = capture_records;
@@ -893,8 +896,7 @@ rtems_capture_switch_task (rtems_tcb* current_task,
*/ */
if (capture_flags & RTEMS_CAPTURE_ON) if (capture_flags & RTEMS_CAPTURE_ON)
{ {
uint32_t ticks; rtems_capture_time_t time;
uint32_t tick_offset;
/* /*
* Get the cpature task control block so we can update the * Get the cpature task control block so we can update the
@@ -929,10 +931,10 @@ rtems_capture_switch_task (rtems_tcb* current_task,
ht = rtems_capture_create_capture_task (heir_task); ht = rtems_capture_create_capture_task (heir_task);
/* /*
* Update the execution time. Assume the tick will not overflow * Update the execution time. Assume the time will not overflow
* for now. This may need to change. * for now. This may need to change.
*/ */
rtems_capture_get_time (&ticks, &tick_offset); rtems_capture_get_time (&time);
/* /*
* We could end up with null pointers for both the current task * We could end up with null pointers for both the current task
@@ -942,31 +944,13 @@ rtems_capture_switch_task (rtems_tcb* current_task,
if (ht) if (ht)
{ {
ht->in++; ht->in++;
ht->ticks_in = ticks; ht->time_in = time;
ht->tick_offset_in = tick_offset;
} }
if (ct) if (ct)
{ {
ct->out++; ct->out++;
ct->ticks += ticks - ct->ticks_in; ct->time += time - ct->time_in;
if (capture_timestamp)
{
tick_offset += capture_tick_period - ct->tick_offset_in;
if (tick_offset < capture_tick_period)
ct->tick_offset = tick_offset;
else
{
ct->ticks++;
ct->tick_offset = tick_offset - capture_tick_period;
}
}
else
{
ct->tick_offset += 100;
}
} }
if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH)) if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH))
@@ -1027,11 +1011,6 @@ rtems_capture_open (uint32_t size, rtems_capture_timestamp timestamp __attribu
capture_extensions.thread_exitted = rtems_capture_exitted_task; capture_extensions.thread_exitted = rtems_capture_exitted_task;
capture_extensions.fatal = NULL; capture_extensions.fatal = NULL;
/*
* Get the tick period from the BSP Configuration Table.
*/
capture_tick_period = rtems_configuration_get_microseconds_per_tick();
/* /*
* Register the user extension handlers for the CAPture Engine. * Register the user extension handlers for the CAPture Engine.
*/ */
@@ -1070,7 +1049,6 @@ rtems_capture_close (void)
rtems_interrupt_level level; rtems_interrupt_level level;
rtems_capture_task_t* task; rtems_capture_task_t* task;
rtems_capture_control_t* control; rtems_capture_control_t* control;
rtems_capture_record_t* records;
rtems_status_code sc; rtems_status_code sc;
rtems_interrupt_disable (level); rtems_interrupt_disable (level);
@@ -1083,7 +1061,6 @@ rtems_capture_close (void)
capture_flags &= ~(RTEMS_CAPTURE_ON | RTEMS_CAPTURE_ONLY_MONITOR); capture_flags &= ~(RTEMS_CAPTURE_ON | RTEMS_CAPTURE_ONLY_MONITOR);
records = capture_records;
capture_records = NULL; capture_records = NULL;
rtems_interrupt_enable (level); rtems_interrupt_enable (level);
@@ -1136,6 +1113,12 @@ rtems_capture_close (void)
* *
* This function allows control of tracing at a global level. * This function allows control of tracing at a global level.
*/ */
static void
rtems_capture_task_setup (Thread_Control *tcb)
{
rtems_capture_create_capture_task (tcb);
}
rtems_status_code rtems_status_code
rtems_capture_control (bool enable) rtems_capture_control (bool enable)
{ {
@@ -1154,6 +1137,8 @@ rtems_capture_control (bool enable)
else else
capture_flags &= ~RTEMS_CAPTURE_ON; capture_flags &= ~RTEMS_CAPTURE_ON;
rtems_iterate_over_all_threads (rtems_capture_task_setup);
rtems_interrupt_enable (level); rtems_interrupt_enable (level);
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;
@@ -1841,16 +1826,17 @@ rtems_capture_release (uint32_t count)
} }
/* /*
* rtems_capture_tick_time * rtems_capture_time
* *
* DESCRIPTION: * DESCRIPTION:
* *
* This function returns the tick period in nano-seconds. * This function returns the current time. If a handler is provided
* by the user get the time from that.
*/ */
uint32_t void
rtems_capture_tick_time (void) rtems_capture_time (rtems_capture_time_t* uptime)
{ {
return capture_tick_period; rtems_capture_get_time(uptime);
} }
/* /*

View File

@@ -44,6 +44,15 @@ extern "C" {
*/ */
#define RTEMS_CAPTURE_TRIGGER_TASKS (32) #define RTEMS_CAPTURE_TRIGGER_TASKS (32)
/**
* rtems_capture_time_t
*
* DESCRIPTION:
*
* A capture timestamp.
*/
typedef Timestamp_Control rtems_capture_time_t;
/** /**
* rtems_capture_from_t * rtems_capture_from_t
* *
@@ -156,12 +165,9 @@ typedef struct rtems_capture_task_s
rtems_task_priority start_priority; rtems_task_priority start_priority;
uint32_t stack_size; uint32_t stack_size;
uint32_t stack_clean; uint32_t stack_clean;
uint32_t ticks; rtems_capture_time_t time;
uint32_t tick_offset; rtems_capture_time_t time_in;
uint32_t ticks_in; rtems_capture_time_t last_time;
uint32_t tick_offset_in;
uint32_t last_ticks;
uint32_t last_tick_offset;
rtems_capture_control_t* control; rtems_capture_control_t* control;
struct rtems_capture_task_s* forw; struct rtems_capture_task_s* forw;
struct rtems_capture_task_s* back; struct rtems_capture_task_s* back;
@@ -185,8 +191,7 @@ typedef struct rtems_capture_record_s
{ {
rtems_capture_task_t* task; rtems_capture_task_t* task;
uint32_t events; uint32_t events;
uint32_t ticks; rtems_capture_time_t time;
uint32_t tick_offset;
} rtems_capture_record_t; } rtems_capture_record_t;
/** /**
@@ -254,8 +259,7 @@ typedef enum rtems_capture_trigger_e
* *
*/ */
typedef void (*rtems_capture_timestamp) typedef void (*rtems_capture_timestamp)(rtems_capture_time_t* time);
(uint32_t* ticks, uint32_t* micro);
/** /**
* rtems_capture_open * rtems_capture_open
@@ -509,25 +513,15 @@ rtems_capture_read (uint32_t threshold,
rtems_status_code rtems_status_code
rtems_capture_release (uint32_t count); rtems_capture_release (uint32_t count);
/**
* rtems_capture_tick_time
*
* DESCRIPTION:
*
* This function returns the tick period in micro-seconds.
*/
uint32_t
rtems_capture_tick_time (void);
/* /*
* rtems_capture_tick_time * rtems_capture_time
* *
* DESCRIPTION: * DESCRIPTION:
* *
* This function returns the tick period in micro-seconds. * This function returns the time period in nano-seconds.
*/ */
uint32_t void
rtems_capture_tick_time (void); rtems_capture_time (rtems_capture_time_t* uptime);
/** /**
* rtems_capture_event_text * rtems_capture_event_text
@@ -771,32 +765,6 @@ rtems_capture_task_stack_used (rtems_capture_task_t* task)
return task->stack_size - task->stack_clean; return task->stack_size - task->stack_clean;
} }
/**
* rtems_capture_task_ticks
*
* DESCRIPTION:
*
* This function returns the current execution time as ticks.
*/
static inline uint32_t
rtems_capture_task_ticks (rtems_capture_task_t* task)
{
return task->ticks;
}
/**
* rtems_capture_task_tick_offset
*
* DESCRIPTION:
*
* This function returns the current execution time tick offset.
*/
static inline uint32_t
rtems_capture_task_tick_offset (rtems_capture_task_t* task)
{
return task->tick_offset;
}
/** /**
* rtems_capture_task_time * rtems_capture_task_time
* *
@@ -804,11 +772,10 @@ rtems_capture_task_tick_offset (rtems_capture_task_t* task)
* *
* This function returns the current execution time. * This function returns the current execution time.
*/ */
static inline unsigned long long static inline uint64_t
rtems_capture_task_time (rtems_capture_task_t* task) rtems_capture_task_time (rtems_capture_task_t* task)
{ {
unsigned long long t = task->ticks; return task->time;
return (t * rtems_capture_tick_time ()) + task->tick_offset;;
} }
/** /**
@@ -819,16 +786,12 @@ rtems_capture_task_time (rtems_capture_task_t* task)
* This function returns the execution time as a different between the * This function returns the execution time as a different between the
* last time the detla time was and now. * last time the detla time was and now.
*/ */
static inline unsigned long long static inline uint64_t
rtems_capture_task_delta_time (rtems_capture_task_t* task) rtems_capture_task_delta_time (rtems_capture_task_t* task)
{ {
unsigned long long t = task->ticks - task->last_ticks; uint64_t t = task->time - task->last_time;
uint32_t o = task->tick_offset - task->last_tick_offset; task->last_time = task->time;
return t;
task->last_ticks = task->ticks;
task->last_tick_offset = task->tick_offset;
return (t * rtems_capture_tick_time ()) + o;
} }
/** /**
@@ -843,7 +806,7 @@ static inline uint32_t
rtems_capture_task_count (void) rtems_capture_task_count (void)
{ {
rtems_capture_task_t* task = rtems_capture_get_task_list (); rtems_capture_task_t* task = rtems_capture_get_task_list ();
uint32_t count = 0; uint32_t count = 0;
while (task) while (task)
{ {