[PATCH] Write event stream in file

Ravindra Meena rmeena840 at gmail.com
Tue Jun 25 04:50:42 UTC 2019


---
 misc/record/record-main.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/misc/record/record-main.c b/misc/record/record-main.c
index 742428b..61cbb4e 100644
--- a/misc/record/record-main.c
+++ b/misc/record/record-main.c
@@ -67,6 +67,15 @@ typedef struct client_item {
   uint64_t                     counter;
 } client_item;
 
+typedef struct ctf_event {
+  uint32_t                     event_id;
+  uint64_t                     ns;
+  uint32_t                     cpu;
+  rtems_record_event           event;
+  uint64_t                     data;
+} ctf_event;
+
+
 typedef struct client_context {
   uint64_t                       ns_threshold;
   uint64_t                       last_ns;
@@ -76,6 +85,7 @@ typedef struct client_context {
   uint64_t                       counter;
   SLIST_HEAD( , client_item )    free_items;
   RB_HEAD( active, client_item ) active_items;
+  FILE                           *event_stream;
 } client_context;
 
 static inline int item_cmp( const void *pa, const void *pb )
@@ -135,24 +145,26 @@ static int connect_client( const char *host, uint16_t port )
 
 static void print_item( FILE *f, const client_item *item )
 {
+  ctf_event ctf_item;
+  uint32_t ns;
+
   if ( item->ns != 0 ) {
     uint32_t seconds;
     uint32_t nanoseconds;
 
     seconds = (uint32_t) ( item->ns / 1000000000 );
     nanoseconds = (uint32_t) ( item->ns % 1000000000 );
-    fprintf( f, "%" PRIu32 ".%09" PRIu32 ":", seconds, nanoseconds );
-  } else {
-    fprintf( f, "*:" );
+    ns=nanoseconds;
   }
+    
+  ctf_item.event_id=0;
+  ctf_item.ns=ns;
+  ctf_item.cpu=item->cpu;
+  ctf_item.event=item->event;
+  ctf_item.data=item->data;
+
+  fwrite( &ctf_item, sizeof( ctf_item ), 1, f );
 
-  fprintf(
-    f,
-    "%" PRIu32 ":%s:%" PRIx64 "\n",
-    item->cpu,
-    rtems_record_event_text( item->event ),
-    item->data
-  );
 }
 
 static void flush_items( client_context *cctx )
@@ -188,7 +200,7 @@ static void flush_items( client_context *cctx )
 
     RB_REMOVE( active, &cctx->active_items, x );
     SLIST_INSERT_HEAD( &cctx->free_items, x, free_node );
-    print_item( stdout, x );
+    print_item( cctx->event_stream, x);
   }
 }
 
@@ -310,6 +322,9 @@ int main( int argc, char **argv )
   SLIST_INIT( &cctx.free_items );
   RB_INIT( &cctx.active_items );
 
+  FILE *event_stream=fopen("event","wb");
+  cctx.event_stream=event_stream;
+
   items = calloc( n, sizeof( *items ) );
   assert( items != NULL );
 
@@ -332,6 +347,7 @@ int main( int argc, char **argv )
     }
   }
 
+  fclose(event_stream);
   rv = close( fd );
   assert( rv == 0 );
 
-- 
2.7.4




More information about the devel mailing list