[rtems commit] cpukit/capture: Update the capture engine.
Chris Johns
chrisj at rtems.org
Thu Dec 19 07:56:37 UTC 2013
Module: rtems
Branch: master
Commit: db8a89e21254b0756a053709e56e5119fa75c2f1
Changeset: http://git.rtems.org/rtems/commit/?id=db8a89e21254b0756a053709e56e5119fa75c2f1
Author: Chris Johns <chrisj at rtems.org>
Date: Thu Dec 19 19:01:23 2013 +1100
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.
---
cpukit/libmisc/capture/capture-cli.c | 257 ++++++++++++++++++----------------
cpukit/libmisc/capture/capture.c | 84 +++++-------
cpukit/libmisc/capture/capture.h | 87 ++++--------
3 files changed, 195 insertions(+), 233 deletions(-)
diff --git a/cpukit/libmisc/capture/capture-cli.c b/cpukit/libmisc/capture/capture-cli.c
index 4cf9b6b..32aa0cb 100644
--- a/cpukit/libmisc/capture/capture-cli.c
+++ b/cpukit/libmisc/capture/capture-cli.c
@@ -36,6 +36,8 @@
#include <rtems/capture-cli.h>
#include <rtems/monitor.h>
+#define RC_UNUSED __attribute__((unused))
+
#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 void
-rtems_capture_cli_open (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_open (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
uint32_t size = 0;
bool enable = false;
@@ -132,10 +134,10 @@ rtems_capture_cli_open (int argc,
*/
static void
-rtems_capture_cli_close (int argc __attribute__((unused)),
- char** argv __attribute__((unused)),
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_close (int argc RC_UNUSED,
+ char** argv RC_UNUSED,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
@@ -160,10 +162,10 @@ rtems_capture_cli_close (int argc __attribute__((unused
*/
static void
-rtems_capture_cli_enable (int argc __attribute__((unused)),
- char** argv __attribute__((unused)),
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_enable (int argc RC_UNUSED,
+ char** argv RC_UNUSED,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
@@ -188,10 +190,10 @@ rtems_capture_cli_enable (int argc __attribute__((unuse
*/
static void
-rtems_capture_cli_disable (int argc __attribute__((unused)),
- char** argv __attribute__((unused)),
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_disable (int argc RC_UNUSED,
+ char** argv RC_UNUSED,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
@@ -216,44 +218,35 @@ rtems_capture_cli_disable (int argc __attribute__((unus
*/
static void
-rtems_capture_cli_task_list (int argc __attribute__((unused)),
- char** argv __attribute__((unused)),
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_task_list (int argc RC_UNUSED,
+ char** argv RC_UNUSED,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
rtems_task_priority floor = rtems_capture_watch_get_floor ();
rtems_capture_task_t* task = rtems_capture_get_task_list ();
- uint32_t ticks;
- uint32_t tick_offset;
- unsigned long long total_time;
+ rtems_capture_time_t total_time;
int count = rtems_capture_task_count ();
- if (capture_timestamp)
- capture_timestamp (&ticks, &tick_offset);
- else
- {
- ticks = rtems_clock_get_ticks_since_boot();
- tick_offset = 0;
- }
+ rtems_capture_time (&total_time);
- fprintf (stdout, "total %i\n", count);
+ fprintf (stdout, "total %i time:%Lu\n", count, (uint64_t) total_time);
while (task)
{
rtems_task_priority priority;
int32_t stack_used;
int32_t time_used;
+ int length;
stack_used = rtems_capture_task_stack_usage (task);
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)
stack_used = 100;
- total_time = (ticks * rtems_capture_task_time (task)) + tick_offset;
-
time_used = (rtems_capture_task_time (task) * 100) / total_time;
if (time_used > 100)
@@ -264,7 +257,7 @@ rtems_capture_cli_task_list (int argc __attribute__((un
fprintf (stdout, " ");
rtems_monitor_dump_id (rtems_capture_task_id (task));
fprintf (stdout, " ");
- rtems_monitor_dump_name (rtems_capture_task_name (task));
+ rtems_monitor_dump_name (rtems_capture_task_id (task));
fprintf (stdout, " ");
rtems_monitor_dump_priority (rtems_capture_task_start_priority (task));
fprintf (stdout, " ");
@@ -272,7 +265,8 @@ rtems_capture_cli_task_list (int argc __attribute__((un
fprintf (stdout, " ");
rtems_monitor_dump_priority (rtems_capture_task_curr_priority (task));
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",
rtems_capture_task_valid (task) ? 'a' : 'd',
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' : '+') : '-',
rtems_capture_watch_global_on () ? 'g' : '-');
}
- fprintf (stdout, " %3" PRId32 "%% %3" PRId32 "%% (%" PRIu32 ")\n",
- stack_used, time_used, rtems_capture_task_ticks (task));
+ fprintf (stdout, " %3" PRId32 "%% %3" PRId32 "%% (%" PRIu64 ")\n",
+ stack_used, time_used, rtems_capture_task_time (task));
task = rtems_capture_next_task (task);
}
@@ -304,7 +298,7 @@ rtems_capture_cli_task_list (int argc __attribute__((un
*/
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 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];
unsigned long long load[RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS + 1];
rtems_capture_task_t* task;
- unsigned long long total_time;
+ rtems_capture_time_t total_time;
int count = 0;
int i;
int j;
@@ -339,7 +333,7 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
{
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++;
@@ -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,
- " 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)
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]);
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)
stack_used = 100;
@@ -402,14 +396,14 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
fprintf (stdout, "\x1b[K");
rtems_monitor_dump_id (rtems_capture_task_id (tasks[i]));
fprintf (stdout, " ");
- rtems_monitor_dump_name (rtems_capture_task_name (tasks[i]));
+ rtems_monitor_dump_name (rtems_capture_task_id (tasks[i]));
fprintf (stdout, " ");
rtems_monitor_dump_priority (priority);
fprintf (stdout, " ");
rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tasks[i]));
fprintf (stdout, " ");
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);
fprintf (stdout, "%3i%% %c%c", stack_used,
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_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)
@@ -455,10 +450,10 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg __attribute__((unuse
*/
static void
-rtems_capture_cli_task_load (int argc __attribute__((unused)),
- char** argv __attribute__((unused)),
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_task_load (int argc RC_UNUSED,
+ char** argv RC_UNUSED,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
rtems_task_priority priority;
@@ -528,10 +523,10 @@ rtems_capture_cli_task_load (int argc __attribute__((un
*/
static void
-rtems_capture_cli_watch_list (int argc __attribute__((unused)),
- char** argv __attribute__((unused)),
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_watch_list (int argc RC_UNUSED,
+ char** argv RC_UNUSED,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_capture_control_t* control = rtems_capture_get_control_list ();
rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
@@ -618,11 +613,11 @@ rtems_capture_cli_watch_list (int argc __attribute__((u
*/
static bool
-rtems_capture_cli_get_name_id (char* arg,
- bool* valid_name,
- bool* valid_id,
- rtems_name* name,
- rtems_id* id)
+rtems_capture_cli_get_name_id (char* arg,
+ bool* valid_name,
+ bool* valid_id,
+ rtems_name* name,
+ rtems_id* id)
{
size_t l;
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 void
-rtems_capture_cli_watch_add (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_watch_add (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
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 void
-rtems_capture_cli_watch_del (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_watch_del (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
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 void
-rtems_capture_cli_watch_control (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_watch_control (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
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 void
-rtems_capture_cli_watch_global (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_watch_global (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
int arg;
@@ -926,10 +921,10 @@ rtems_capture_cli_watch_global (int argc,
static char const * watch_ceiling_usage = "usage: cwceil priority\n";
static void
-rtems_capture_cli_watch_ceiling (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_watch_ceiling (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
int arg;
@@ -977,10 +972,10 @@ rtems_capture_cli_watch_ceiling (int argc,
static char const * watch_floor_usage = "usage: cwfloor priority\n";
static void
-rtems_capture_cli_watch_floor (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_watch_floor (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
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;
bool trigger_set = false;
bool is_from = false;
+ bool is_to = false;
rtems_name name = 0;
rtems_id id = 0;
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 (is_from)
+ if (from_valid_name || from_valid_id)
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;
}
@@ -1150,6 +1155,9 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
if (valid_name)
{
+ if (!is_from && !is_to)
+ is_to = true;
+
if (is_from)
{
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;
}
else
- fprintf (stdout, "warning: extra arguments ignored\n");
+ fprintf (stdout, "warning: extra name arguments ignored\n");
}
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;
}
else
- fprintf (stdout, "warning: extra arguments ignored\n");
+ fprintf (stdout, "warning: extra name arguments ignored\n");
}
if (valid_id)
{
+ if (!is_from && !is_to)
+ is_to = true;
+
if (is_from)
{
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;
}
else
- fprintf (stdout, "warning: extra arguments ignored\n");
+ fprintf (stdout, "warning: extra id arguments ignored\n");
}
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;
}
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)
{
- fprintf (stdout, trigger_set_usage);
+ fprintf (stdout, trigger_set_usage, set ? "ctset" : "ctclear");
return;
}
@@ -1255,10 +1266,10 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
*/
static void
-rtems_capture_cli_trigger_set (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_trigger_set (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_capture_cli_trigger_worker (1, argc, argv);
}
@@ -1273,10 +1284,10 @@ rtems_capture_cli_trigger_set (int argc,
*/
static void
-rtems_capture_cli_trigger_clear (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_trigger_clear (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_capture_cli_trigger_worker (0, argc, argv);
}
@@ -1291,10 +1302,10 @@ rtems_capture_cli_trigger_clear (int argc,
*/
static void
-rtems_capture_cli_trace_records (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_trace_records (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
bool csv = false;
@@ -1362,33 +1373,35 @@ rtems_capture_cli_trace_records (int argc,
{
if (csv)
fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32
- ",%03" PRIu32 ",%04" PRIx32 ",%" PRId32 ",%" PRId32 "\n",
- (uintptr_t) rec->task,
- (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
- (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
- (rec->events >> RTEMS_CAPTURE_EVENT_START),
- rec->ticks, rec->tick_offset);
+ ",%03" PRIu32 ",%04" PRIx32 ",%" PRId64 "\n",
+ (uintptr_t) rec->task,
+ (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
+ (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
+ (rec->events >> RTEMS_CAPTURE_EVENT_START),
+ (uint64_t) rec->time);
else
{
- unsigned long long t;
- uint32_t event;
- int e;
+ rtems_capture_time_t t;
+ uint32_t event;
+ int e;
event = rec->events >> RTEMS_CAPTURE_EVENT_START;
- t = rec->ticks;
- t *= rtems_capture_tick_time ();
- t += rec->tick_offset;
+ t = rec->time;
for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++)
{
if (event & 1)
{
- fprintf (stdout, "%9li.%06li ", (unsigned long) (t / 1000000),
- (unsigned long) (t % 1000000));
+ fprintf (stdout, "%9li.%06li ",
+ (unsigned long) (t / 1000000000ULL),
+ (unsigned long) (t % 1000000000ULL));
rtems_monitor_dump_id (rtems_capture_task_id (rec->task));
- fprintf (stdout, " ");
- rtems_monitor_dump_name (rtems_capture_task_name (rec->task));
+ fprintf (stdout, " %c%c%c%c",
+ (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",
(rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
(rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
@@ -1422,10 +1435,10 @@ rtems_capture_cli_trace_records (int argc,
*/
static void
-rtems_capture_cli_flush (int argc,
- char** argv,
- const rtems_monitor_command_arg_t* command_arg __attribute__((unused)),
- bool verbose __attribute__((unused)))
+rtems_capture_cli_flush (int argc,
+ char** argv,
+ const rtems_monitor_command_arg_t* command_arg RC_UNUSED,
+ bool verbose RC_UNUSED)
{
rtems_status_code sc;
bool prime = true;
diff --git a/cpukit/libmisc/capture/capture.c b/cpukit/libmisc/capture/capture.c
index 050a92c..5ebc967 100644
--- a/cpukit/libmisc/capture/capture.c
+++ b/cpukit/libmisc/capture/capture.c
@@ -29,7 +29,9 @@
#include <string.h>
#include "capture.h"
+
#include <rtems/score/statesimpl.h>
+#include <rtems/score/todimpl.h>
/*
* 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_task_priority capture_ceiling;
static rtems_task_priority capture_floor;
-static uint32_t capture_tick_period;
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
* by the user get the time from that.
*/
-static inline void rtems_capture_get_time (uint32_t* ticks,
- uint32_t* tick_offset)
+static inline void
+rtems_capture_get_time (rtems_capture_time_t* time)
{
if (capture_timestamp)
- capture_timestamp (ticks, tick_offset);
+ capture_timestamp (time);
else
{
- *ticks = rtems_clock_get_ticks_since_boot();
- *tick_offset = 0;
+ _TOD_Get_uptime(time);
}
}
@@ -396,6 +396,7 @@ rtems_capture_create_capture_task (rtems_tcb* new_task)
rtems_capture_task_t* task;
rtems_capture_control_t* control;
rtems_name name;
+ rtems_capture_time_t time;
bool ok;
ok = rtems_workspace_allocate (sizeof (*task), (void **) &task);
@@ -407,6 +408,11 @@ rtems_capture_create_capture_task (rtems_tcb* new_task)
}
/*
+ * Get the current time.
+ */
+ rtems_capture_get_time (&time);
+
+ /*
* 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->out = 0;
task->tcb = new_task;
- task->ticks = 0;
- task->tick_offset = 0;
- task->ticks_in = 0;
- task->tick_offset_in = 0;
+ task->time = 0;
+ task->time_in = time;
task->control = 0;
- task->last_ticks = 0;
- task->last_tick_offset = 0;
+ task->last_time = 0;
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)
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])
capture_in = capture_records;
@@ -893,8 +896,7 @@ rtems_capture_switch_task (rtems_tcb* current_task,
*/
if (capture_flags & RTEMS_CAPTURE_ON)
{
- uint32_t ticks;
- uint32_t tick_offset;
+ rtems_capture_time_t time;
/*
* 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);
/*
- * 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.
*/
- rtems_capture_get_time (&ticks, &tick_offset);
+ rtems_capture_get_time (&time);
/*
* 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)
{
ht->in++;
- ht->ticks_in = ticks;
- ht->tick_offset_in = tick_offset;
+ ht->time_in = time;
}
if (ct)
{
ct->out++;
- ct->ticks += ticks - ct->ticks_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;
- }
+ ct->time += time - ct->time_in;
}
if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH))
@@ -1028,11 +1012,6 @@ rtems_capture_open (uint32_t size, rtems_capture_timestamp timestamp __attribu
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.
*/
name = rtems_build_name ('C', 'A', 'P', 'E');
@@ -1070,7 +1049,6 @@ rtems_capture_close (void)
rtems_interrupt_level level;
rtems_capture_task_t* task;
rtems_capture_control_t* control;
- rtems_capture_record_t* records;
rtems_status_code sc;
rtems_interrupt_disable (level);
@@ -1083,7 +1061,6 @@ rtems_capture_close (void)
capture_flags &= ~(RTEMS_CAPTURE_ON | RTEMS_CAPTURE_ONLY_MONITOR);
- records = capture_records;
capture_records = NULL;
rtems_interrupt_enable (level);
@@ -1136,6 +1113,12 @@ rtems_capture_close (void)
*
* 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_capture_control (bool enable)
{
@@ -1154,6 +1137,8 @@ rtems_capture_control (bool enable)
else
capture_flags &= ~RTEMS_CAPTURE_ON;
+ rtems_iterate_over_all_threads (rtems_capture_task_setup);
+
rtems_interrupt_enable (level);
return RTEMS_SUCCESSFUL;
@@ -1841,16 +1826,17 @@ rtems_capture_release (uint32_t count)
}
/*
- * rtems_capture_tick_time
+ * rtems_capture_time
*
* 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
-rtems_capture_tick_time (void)
+void
+rtems_capture_time (rtems_capture_time_t* uptime)
{
- return capture_tick_period;
+ rtems_capture_get_time(uptime);
}
/*
diff --git a/cpukit/libmisc/capture/capture.h b/cpukit/libmisc/capture/capture.h
index d75f675..e990286 100644
--- a/cpukit/libmisc/capture/capture.h
+++ b/cpukit/libmisc/capture/capture.h
@@ -45,6 +45,15 @@ extern "C" {
#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
*
* DESCRIPTION:
@@ -156,12 +165,9 @@ typedef struct rtems_capture_task_s
rtems_task_priority start_priority;
uint32_t stack_size;
uint32_t stack_clean;
- uint32_t ticks;
- uint32_t tick_offset;
- uint32_t ticks_in;
- uint32_t tick_offset_in;
- uint32_t last_ticks;
- uint32_t last_tick_offset;
+ rtems_capture_time_t time;
+ rtems_capture_time_t time_in;
+ rtems_capture_time_t last_time;
rtems_capture_control_t* control;
struct rtems_capture_task_s* forw;
struct rtems_capture_task_s* back;
@@ -185,8 +191,7 @@ typedef struct rtems_capture_record_s
{
rtems_capture_task_t* task;
uint32_t events;
- uint32_t ticks;
- uint32_t tick_offset;
+ rtems_capture_time_t time;
} rtems_capture_record_t;
/**
@@ -254,8 +259,7 @@ typedef enum rtems_capture_trigger_e
*
*/
-typedef void (*rtems_capture_timestamp)
- (uint32_t* ticks, uint32_t* micro);
+typedef void (*rtems_capture_timestamp)(rtems_capture_time_t* time);
/**
* rtems_capture_open
@@ -509,25 +513,15 @@ rtems_capture_read (uint32_t threshold,
rtems_status_code
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:
*
- * This function returns the tick period in micro-seconds.
+ * This function returns the time period in nano-seconds.
*/
-uint32_t
-rtems_capture_tick_time (void);
+void
+rtems_capture_time (rtems_capture_time_t* uptime);
/**
* rtems_capture_event_text
@@ -772,43 +766,16 @@ rtems_capture_task_stack_used (rtems_capture_task_t* task)
}
/**
- * 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
*
* DESCRIPTION:
*
* 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)
{
- unsigned long long t = task->ticks;
- return (t * rtems_capture_tick_time ()) + task->tick_offset;;
+ return task->time;
}
/**
@@ -819,16 +786,12 @@ rtems_capture_task_time (rtems_capture_task_t* task)
* This function returns the execution time as a different between the
* 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)
{
- unsigned long long t = task->ticks - task->last_ticks;
- uint32_t o = task->tick_offset - task->last_tick_offset;
-
- task->last_ticks = task->ticks;
- task->last_tick_offset = task->tick_offset;
-
- return (t * rtems_capture_tick_time ()) + o;
+ uint64_t t = task->time - task->last_time;
+ task->last_time = task->time;
+ return t;
}
/**
@@ -843,7 +806,7 @@ static inline uint32_t
rtems_capture_task_count (void)
{
rtems_capture_task_t* task = rtems_capture_get_task_list ();
- uint32_t count = 0;
+ uint32_t count = 0;
while (task)
{
More information about the vc
mailing list