----- Am 26. Jul 2019 um 14:56 schrieb Ravindra Kumar Meena rmeena...@gmail.com:

>>
>> Ok, very good. This look all right. It is amazing how much information
>> Trace Compass can display with only sched_switch events.
>>
> Great!! We have something working very useful. :) :)
> 
>>
>> Please figure out how the state member values are defined. I think this
>> is important to improve the diagrams.
>>
> Here is the response from lltng:
> https://lists.lttng.org/pipermail/lttng-dev/2019-July/029121.html
> 
> What I understand from here is that _prev_state is the previous state of
> the thread(TID)).

Yes, but what is the meaning of these state values? We have to figure this out 
since we need a mapping from RTEMS thread states to these Linux thread states. 
Could you use an example trace from Linux to check if the information 
referenced in this email answer makes sense?

> 
> 
>> It would be good to get task names for the IDs. Do you have an idea how
>> we can do this?
>>
> With task name do you mean RTEMS_RECORD_THREAD_SWITCH_IN
> and RTEMS_RECORD_THREAD_SWITCH_OUT?
> 
> if so this can be done by calling:
> rtems_record_event_text( item->event )

Attached is a patch for RTEMS. The record server sends all thread names to the 
client after the header.

For thread name changes and new threads we have to think about.
From 05b66668722d2db2dbc316b2b4d77a7f42399e68 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <sebastian.hu...@embedded-brains.de>
Date: Fri, 26 Jul 2019 16:36:10 +0200
Subject: [PATCH] record: Add support for thread names

---
 cpukit/include/rtems/recorddata.h      |  4 +-
 cpukit/libtrace/record/record-server.c | 70 ++++++++++++++++++++++++++++++++++
 cpukit/libtrace/record/record-text.c   |  2 +-
 testsuites/libtests/record01/init.c    | 30 +++++++++++++++
 4 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/cpukit/include/rtems/recorddata.h b/cpukit/include/rtems/recorddata.h
index 61a6311735..607955c596 100644
--- a/cpukit/include/rtems/recorddata.h
+++ b/cpukit/include/rtems/recorddata.h
@@ -55,7 +55,7 @@ extern "C" {
  * The record version reflects the record event definitions.  It is reported by
  * the RTEMS_RECORD_VERSION event.
  */
-#define RTEMS_RECORD_THE_VERSION 4
+#define RTEMS_RECORD_THE_VERSION 5
 
 /**
  * @brief The items are in 32-bit little-endian format.
@@ -291,6 +291,7 @@ typedef enum {
   RTEMS_RECORD_THREAD_EXIT,
   RTEMS_RECORD_THREAD_EXITTED,
   RTEMS_RECORD_THREAD_ID,
+  RTEMS_RECORD_THREAD_NAME,
   RTEMS_RECORD_THREAD_PRIO_CURRENT_HIGH,
   RTEMS_RECORD_THREAD_PRIO_CURRENT_LOW,
   RTEMS_RECORD_THREAD_PRIO_REAL_HIGH,
@@ -607,7 +608,6 @@ typedef enum {
   RTEMS_RECORD_SYSTEM_508,
   RTEMS_RECORD_SYSTEM_509,
   RTEMS_RECORD_SYSTEM_510,
-  RTEMS_RECORD_SYSTEM_511,
 
   /* There are 512 events reserved for the user */
   RTEMS_RECORD_USER_0,
diff --git a/cpukit/libtrace/record/record-server.c b/cpukit/libtrace/record/record-server.c
index 840924a24a..f84852d226 100644
--- a/cpukit/libtrace/record/record-server.c
+++ b/cpukit/libtrace/record/record-server.c
@@ -30,6 +30,7 @@
 #endif
 
 #include <rtems/record.h>
+#include <rtems/score/threadimpl.h>
 #include <rtems.h>
 
 #include <sys/endian.h>
@@ -165,6 +166,74 @@ static void send_header( int fd )
   (void) write( fd, &header, sizeof( header ) );
 }
 
+typedef struct {
+  int fd;
+  size_t index;
+  rtems_record_item items[ 128 ];
+} thread_names_context;
+
+static void thread_names_produce(
+  thread_names_context *ctx,
+  rtems_record_event    event,
+  rtems_record_data     data
+)
+{
+  size_t i;
+
+  i = ctx->index;
+  ctx->items[ i ].event = RTEMS_RECORD_TIME_EVENT( 0, event );
+  ctx->items[ i ].data = data;
+
+  if (i == RTEMS_ARRAY_SIZE(ctx->items) - 2) {
+    ctx->index = 0;
+    (void) write( ctx->fd, ctx->items, sizeof( ctx->items ) );
+  } else {
+    ctx->index = i + 1;
+  }
+}
+
+static bool thread_names_visitor( rtems_tcb *tcb, void *arg )
+{
+  thread_names_context *ctx;
+  char                  buf[ 16 ];
+  size_t                n;
+  size_t                i;
+  rtems_record_data     data;
+
+  ctx = arg;
+  thread_names_produce( ctx, RTEMS_RECORD_THREAD_ID, tcb->Object.id );
+  n = _Thread_Get_name( tcb, buf, sizeof( buf ) );
+  i = 0;
+
+  while ( i < n ) {
+    size_t j;
+
+    data = 0;
+
+    for ( j = 0; i < n && j < sizeof( data ); ++j ) {
+      data = ( data << 8 ) | buf[ i ];
+      ++i;
+    }
+
+    thread_names_produce( ctx, RTEMS_RECORD_THREAD_NAME, data );
+  }
+
+  return false;
+}
+
+static void send_thread_names( int fd )
+{
+  thread_names_context ctx;
+
+  ctx.fd = fd;
+  ctx.index = 0;
+  rtems_task_iterate( thread_names_visitor, &ctx );
+
+  if ( ctx.index > 0 ) {
+    (void) write( ctx.fd, ctx.items, ctx.index * sizeof( ctx.items[ 0 ] ) );
+  }
+}
+
 void rtems_record_server( uint16_t port, rtems_interval period )
 {
   rtems_status_code sc;
@@ -216,6 +285,7 @@ void rtems_record_server( uint16_t port, rtems_interval period )
     wait( RTEMS_NO_WAIT );
     (void) rtems_timer_fire_after( timer, period, wakeup_timer, &self );
     send_header( cd );
+    send_thread_names( cd );
 
     while ( true ) {
       n = rtems_record_writev( cd, &written );
diff --git a/cpukit/libtrace/record/record-text.c b/cpukit/libtrace/record/record-text.c
index cbc623aa1f..5652ab051c 100644
--- a/cpukit/libtrace/record/record-text.c
+++ b/cpukit/libtrace/record/record-text.c
@@ -236,6 +236,7 @@ static const char * const event_text[] = {
   [ RTEMS_RECORD_THREAD_EXIT ] = "THREAD_EXIT",
   [ RTEMS_RECORD_THREAD_EXITTED ] = "THREAD_EXITTED",
   [ RTEMS_RECORD_THREAD_ID ] = "THREAD_ID",
+  [ RTEMS_RECORD_THREAD_NAME ] = "THREAD_NAME",
   [ RTEMS_RECORD_THREAD_PRIO_CURRENT_HIGH ] = "THREAD_PRIO_CURRENT_HIGH",
   [ RTEMS_RECORD_THREAD_PRIO_CURRENT_LOW ] = "THREAD_PRIO_CURRENT_LOW",
   [ RTEMS_RECORD_THREAD_PRIO_REAL_HIGH ] = "THREAD_PRIO_REAL_HIGH",
@@ -550,7 +551,6 @@ static const char * const event_text[] = {
   [ RTEMS_RECORD_SYSTEM_508 ] = "SYSTEM_508",
   [ RTEMS_RECORD_SYSTEM_509 ] = "SYSTEM_509",
   [ RTEMS_RECORD_SYSTEM_510 ] = "SYSTEM_510",
-  [ RTEMS_RECORD_SYSTEM_511 ] = "SYSTEM_511",
   [ RTEMS_RECORD_USER_0 ] = "USER_0",
   [ RTEMS_RECORD_USER_1 ] = "USER_1",
   [ RTEMS_RECORD_USER_2 ] = "USER_2",
diff --git a/testsuites/libtests/record01/init.c b/testsuites/libtests/record01/init.c
index 3a3680c292..d0e933ebd8 100644
--- a/testsuites/libtests/record01/init.c
+++ b/testsuites/libtests/record01/init.c
@@ -151,6 +151,29 @@ static const rtems_record_item expected_items_12[] = {
   { .event = TE(44, UE(43)), .data = 45 }
 };
 
+static const rtems_record_item expected_items_13[] = {
+  { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0x9010001 },
+  {
+    .event = TE(0, RTEMS_RECORD_THREAD_NAME),
+    .data = rtems_build_name('I', 'D', 'L', 'E')
+  },
+  { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0xa010001 },
+  {
+    .event = TE(0, RTEMS_RECORD_THREAD_NAME),
+    .data = rtems_build_name('U', 'I', '1', ' ')
+  },
+  { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0xa010002 },
+  {
+    .event = TE(0, RTEMS_RECORD_THREAD_NAME),
+    .data = rtems_build_name('n', 't', 'w', 'k')
+  },
+  { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0xa010003 },
+  {
+    .event = TE(0, RTEMS_RECORD_THREAD_NAME),
+    .data = rtems_build_name('R', 'C', 'R', 'D')
+  }
+};
+
 static void init_context(test_context *ctx)
 {
   memset(ctx, 0, sizeof(*ctx));
@@ -521,6 +544,7 @@ static int connect_client(void)
   ssize_t n;
   uint32_t v;
   rtems_record_item item;
+  rtems_record_item items[8];
 
   fd = socket(PF_INET, SOCK_STREAM, 0);
   rtems_test_assert(fd >= 0);
@@ -560,6 +584,12 @@ static int connect_client(void)
   rtems_test_assert(item.event == TE(0, RTEMS_RECORD_FREQUENCY));
   rtems_test_assert(item.data == rtems_counter_frequency());
 
+  n = read(fd, items, sizeof(expected_items_13));
+  rtems_test_assert(n == (ssize_t) sizeof(expected_items_13));
+  rtems_test_assert(
+    memcmp(items, expected_items_13, sizeof(expected_items_13)) == 0
+  );
+
   return fd;
 }
 
-- 
2.16.4

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to