[PATCH 1/2] capture: Move logging of task record to occur after filter check.

Jennifer Averett jennifer.averett at oarcorp.com
Tue Oct 7 18:43:22 UTC 2014


---
 cpukit/libmisc/capture/capture.c                | 39 +++++++++++++------
 cpukit/libmisc/capture/capture.h                | 24 +++++++++++-
 cpukit/libmisc/capture/capture_user_extension.c | 51 +++++++++++++------------
 3 files changed, 78 insertions(+), 36 deletions(-)

diff --git a/cpukit/libmisc/capture/capture.c b/cpukit/libmisc/capture/capture.c
index 8bece88..74b563d 100644
--- a/cpukit/libmisc/capture/capture.c
+++ b/cpukit/libmisc/capture/capture.c
@@ -313,26 +313,35 @@ rtems_capture_create_control (rtems_name name, rtems_id id)
   return control;
 }
 
-void rtems_capture_record_task( rtems_tcb* tcb )
+void rtems_capture_initialize_task( rtems_tcb* tcb )
 {
   rtems_capture_control_t*    control;
-  rtems_capture_task_record_t rec;
-  void*                       ptr;
+  rtems_name                  name;
 
-  rtems_object_get_classic_name( tcb->Object.id, &rec.name );
-   
   /*
    * We need to scan the default control list to initialise
    * this control if it is a new task.
    */
 
+  rtems_object_get_classic_name( tcb->Object.id, &name );
+
   if (tcb->Capture.control == NULL) {
     for (control = capture_controls; control != NULL; control = control->next)
       if (rtems_capture_match_name_id (control->name, control->id,
-                                       rec.name, tcb->Object.id))
+                                       name, tcb->Object.id))
         tcb->Capture.control = control;
   }
 
+  tcb->Capture.flags |= RTEMS_CAPTURE_INIT_TASK;
+}
+
+void rtems_capture_record_task( rtems_tcb* tcb )
+{
+  rtems_capture_task_record_t rec;
+  void*                       ptr;
+
+  rtems_object_get_classic_name( tcb->Object.id, &rec.name );
+   
   rec.stack_size = tcb->Start.Initial_stack.size;
   rec.start_priority = _RTEMS_tasks_Priority_from_Core(
     tcb->Start.initial_priority
@@ -1224,6 +1233,8 @@ rtems_capture_release (uint32_t count)
   rtems_capture_record_t*      rec;
   uint32_t                     counted;
   size_t                       ptr_size = 0;
+  size_t                       rel_size = 0;
+  rtems_status_code            ret_val = RTEMS_SUCCESSFUL;
 
   rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
 
@@ -1237,26 +1248,32 @@ rtems_capture_release (uint32_t count)
   ptr = rtems_capture_buffer_peek( &capture_records, &ptr_size );
   _Assert(ptr_size >= (count * sizeof(*rec) ));
 
-  ptr_size = 0;
+  rel_size = 0;
   while (counted--)
-  { 
+  {
     rec = (rtems_capture_record_t*) ptr;
-    ptr_size += rec->size;
+    rel_size += rec->size;
+    _Assert( rel_size <= ptr_size );
     ptr += rec->size;
   }
 
   rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
 
+  if (rel_size > ptr_size ) {
+    ret_val = RTEMS_INVALID_NUMBER;
+    rel_size = ptr_size;
+  }
+
   capture_count -= count;
 
   if (count) 
-    rtems_capture_buffer_free( &capture_records, ptr_size );
+    rtems_capture_buffer_free( &capture_records, rel_size );
 
   capture_flags &= ~RTEMS_CAPTURE_READER_ACTIVE;
 
   rtems_interrupt_lock_release (&capture_lock, &lock_context);
 
-  return RTEMS_SUCCESSFUL;
+  return ret_val;
 }
 
 /*
diff --git a/cpukit/libmisc/capture/capture.h b/cpukit/libmisc/capture/capture.h
index c4edc16..8e0bd1a 100644
--- a/cpukit/libmisc/capture/capture.h
+++ b/cpukit/libmisc/capture/capture.h
@@ -141,7 +141,8 @@ typedef struct rtems_capture_control_s
  * Task flags.
  */
 #define RTEMS_CAPTURE_TRACED      (1U << 0)
-#define RTEMS_CAPTURE_RECORD_TASK (1U << 1)
+#define RTEMS_CAPTURE_INIT_TASK   (1U << 1)
+#define RTEMS_CAPTURE_RECORD_TASK (1U << 2)
 
 /*
  * @brief Capture record.
@@ -598,6 +599,15 @@ const char*
 rtems_capture_event_text (int event);
 
 /**
+ * @brief Capture initialize task
+ *
+ * This function initializes capture control in the tcb.
+ *
+ * @param[in] tcb is the task control block for the task
+ */
+void rtems_capture_initialize_task( rtems_tcb* tcb );
+
+/**
  * @brief Capture record task.
  * 
  * This function records a new capture task record.
@@ -619,6 +629,18 @@ static inline bool rtems_capture_task_recorded( rtems_tcb* tcb ) {
 }
 
 /**
+ * @brief Capture task initialized
+ *
+ * This function returns true if this task information has been 
+ * initialized.
+ *
+ * @param[in] tcb is the task control block for the task
+ */
+static inline bool rtems_capture_task_initialized( rtems_tcb* tcb ) {
+  return ( (tcb->Capture.flags & RTEMS_CAPTURE_INIT_TASK) != 0 );
+}
+
+/**
  * @brief Capture get task id.
  * 
  * This function returns the task id.
diff --git a/cpukit/libmisc/capture/capture_user_extension.c b/cpukit/libmisc/capture/capture_user_extension.c
index 4c7bc1d..69b8d48 100644
--- a/cpukit/libmisc/capture/capture_user_extension.c
+++ b/cpukit/libmisc/capture/capture_user_extension.c
@@ -95,6 +95,9 @@ static inline void rtems_capture_record (
 
   if (rtems_capture_filter( tcb, events) )
     return;
+  
+  if (!rtems_capture_task_recorded (tcb))
+    rtems_capture_record_task (tcb);
 
   rtems_capture_begin_add_record (tcb, events, size, &ptr);
   rtems_capture_end_add_record ( ptr );
@@ -141,13 +144,13 @@ rtems_capture_create_task (rtems_tcb* ct,
    * been created before the capture engine was open. Add them.
    */
 
-  if (!rtems_capture_task_recorded (ct))
-    rtems_capture_record_task (ct);
+  if (!rtems_capture_task_initialized (ct))
+    rtems_capture_initialize_task (ct);
 
   /*
    * Create the new task's capture control block.
    */
-  rtems_capture_record_task (nt);
+  rtems_capture_initialize_task (nt);
 
   if (rtems_capture_trigger (ct, nt, RTEMS_CAPTURE_CREATE))
   {
@@ -170,11 +173,11 @@ rtems_capture_start_task (rtems_tcb* ct,
    * been created before the capture engine was open. Add them.
    */
 
-  if (!rtems_capture_task_recorded (ct))
-    rtems_capture_record_task (ct);
+  if (!rtems_capture_task_initialized (ct))
+    rtems_capture_initialize_task (ct);
 
   if (st == NULL)
-    rtems_capture_record_task (st);
+    rtems_capture_initialize_task (st);
 
   if (rtems_capture_trigger (ct, st, RTEMS_CAPTURE_START))
   {
@@ -195,11 +198,11 @@ rtems_capture_restart_task (rtems_tcb* ct,
    * been created before the capture engine was open. Add them.
    */
 
-  if (!rtems_capture_task_recorded (ct))
-    rtems_capture_record_task (ct);
+  if (!rtems_capture_task_initialized (ct))
+    rtems_capture_initialize_task (ct);
 
-  if (!rtems_capture_task_recorded (rt))
-    rtems_capture_record_task (rt);
+  if (!rtems_capture_task_initialized (rt))
+    rtems_capture_initialize_task (rt);
 
   if (rtems_capture_trigger (ct, rt, RTEMS_CAPTURE_RESTART))
   {
@@ -215,11 +218,11 @@ static void
 rtems_capture_delete_task (rtems_tcb* ct,
                            rtems_tcb* dt)
 {
-  if (!rtems_capture_task_recorded (ct))
-    rtems_capture_record_task (ct);
+  if (!rtems_capture_task_initialized (ct))
+    rtems_capture_initialize_task (ct);
 
-  if (!rtems_capture_task_recorded (dt))
-    rtems_capture_record_task (dt);
+  if (!rtems_capture_task_initialized (dt))
+    rtems_capture_initialize_task (dt);
 
   if (rtems_capture_trigger (ct, dt, RTEMS_CAPTURE_DELETE))
   {
@@ -239,8 +242,8 @@ rtems_capture_begin_task (rtems_tcb* bt)
    * been created before the capture engine was open. Add them.
    */
 
-  if (!rtems_capture_task_recorded (bt))
-    rtems_capture_record_task (bt);
+  if (!rtems_capture_task_initialized (bt))
+    rtems_capture_initialize_task (bt);
 
   if (rtems_capture_trigger (NULL, bt, RTEMS_CAPTURE_BEGIN))
     rtems_capture_record (bt, RTEMS_CAPTURE_BEGIN_EVENT);
@@ -258,8 +261,8 @@ rtems_capture_exitted_task (rtems_tcb* et)
    * been created before the capture engine was open. Add them.
    */
 
-  if (!rtems_capture_task_recorded (et))
-    rtems_capture_record_task (et);
+  if (!rtems_capture_task_initialized (et))
+    rtems_capture_initialize_task (et);
 
   if (rtems_capture_trigger (NULL, et, RTEMS_CAPTURE_EXITTED))
     rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);
@@ -276,8 +279,8 @@ rtems_capture_terminated_task (rtems_tcb* tt)
    * been created before the capture engine was open. Add them.
    */
 
-  if (!rtems_capture_task_recorded (tt))
-    rtems_capture_record_task (tt);
+  if (!rtems_capture_task_initialized (tt))
+    rtems_capture_initialize_task (tt);
 
   if (rtems_capture_trigger (NULL, tt, RTEMS_CAPTURE_TERMINATED))
     rtems_capture_record (tt, RTEMS_CAPTURE_TERMINATED_EVENT);
@@ -300,11 +303,11 @@ rtems_capture_switch_task (rtems_tcb* ct,
   {
     rtems_capture_time_t time;
 
-    if (!rtems_capture_task_recorded (ct))
-      rtems_capture_record_task (ct);
+    if (!rtems_capture_task_initialized (ct))
+      rtems_capture_initialize_task (ct);
 
-    if (!rtems_capture_task_recorded (ht))
-      rtems_capture_record_task (ht);
+    if (!rtems_capture_task_initialized (ht))
+      rtems_capture_initialize_task (ht);
 
     /*
      * Update the execution time. Assume the time will not overflow
-- 
1.8.1.4



More information about the devel mailing list