Skip to content

Commit

Permalink
Write event stream in file
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeena840 committed Jun 25, 2019
1 parent 1bd10a2 commit a213896
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions misc/record/record-main.c
Expand Up @@ -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;
Expand All @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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 );

Expand All @@ -332,6 +347,7 @@ int main( int argc, char **argv )
}
}

fclose(event_stream);
rv = close( fd );
assert( rv == 0 );

Expand Down

0 comments on commit a213896

Please sign in to comment.