Skip to content

Commit

Permalink
store thread id and thread name in hash map
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeena840 committed Aug 2, 2019
1 parent 672a8c1 commit a8da9cc
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions misc/record/record-main.c
Expand Up @@ -51,6 +51,103 @@
#define CTF_MAGIC 0xC1FC1FC1
#define TASK_RUNNING 0x0000
#define TASK_IDLE 0x0402
#define MAP_SIZE_PER_CPU 10000

typedef struct map_data {
uint64_t key;
const char* data;
} map_data;

// hashing the key
uint64_t hashCode( uint64_t key ) {
return key % MAP_SIZE_PER_CPU;
}

struct map_data *map_search( struct map_data* hashArray[], uint64_t key) {
uint64_t hashIndex = hashCode( key );

while( hashArray[hashIndex] != NULL ) {

if( hashArray[ hashIndex ]->key == key )
return hashArray[ hashIndex ];

// go to next cell
++hashIndex;

// wrap around the table
hashIndex %= MAP_SIZE_PER_CPU;
}

return NULL;
}

void map_insert(map_data* hashArray[],uint64_t key, const char* data) {

map_data *item = (map_data*) malloc(sizeof(map_data));
item->data = data;
item->key = key;

//get the hash
uint64_t hashIndex = hashCode(key);

//move in array until an empty or deleted cell
while( hashArray[ hashIndex ] != NULL && ( hashArray[hashIndex]->key != 0 ||
hashArray[hashIndex]->data != NULL )) {
//go to next cell
++hashIndex;

//wrap around the table
hashIndex %= MAP_SIZE_PER_CPU;
}

hashArray[ hashIndex ] = item;
}

map_data* map_delete( map_data* hashArray[], map_data* item ) {
uint64_t key = item->key;

// get the hash
uint64_t hashIndex = hashCode( key );

// move in array until an empty
while( hashArray[ hashIndex ] != NULL ) {

if( hashArray[hashIndex]->key == key ) {
struct map_data* temp = hashArray[ hashIndex ];

// assign a dummy item at deleted position
struct map_data* dummyItem = ( struct map_data* ) malloc( sizeof( struct map_data ) );
dummyItem->key = 0;
dummyItem->data = NULL;
hashArray[ hashIndex ] = dummyItem;
return temp;
}

// go to next cell
++hashIndex;

// wrap around the table
hashIndex %= MAP_SIZE_PER_CPU;
}

return NULL;
}

void map_display(map_data* hashArray[]) {
size_t i = 0;

for(i = 0; i<MAP_SIZE_PER_CPU; i++) {

if( hashArray[i] != NULL )
printf( "(%ld,%s)\n", hashArray[i]->key, hashArray[i]->data );
}

printf("\n");
}

typedef struct map_per_cpu {
map_data* hashArray[ MAP_SIZE_PER_CPU ];
} map_per_cpu;

static const struct option longopts[] = {
{ "help", 0, NULL, 'h' },
Expand Down Expand Up @@ -128,6 +225,7 @@ typedef struct client_context {
uint64_t content_size[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
uint64_t packet_size[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
switch_out_int switch_out_int[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
map_per_cpu map_per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
} client_context;

static const uint8_t uuid[] = { 0x6a, 0x77, 0x15, 0xd0, 0xb5, 0x02, 0x4c, 0x65,
Expand Down Expand Up @@ -201,6 +299,8 @@ static void print_item( client_context *cctx, const client_item *item )
cctx->timestamp_begin[ item->cpu ] = item->ns;
cctx->timestamp_end[ item->cpu ] = item->ns;

map_insert( cctx->map_per_cpu[ item->cpu ].hashArray, item->data, rtems_record_event_text( item->event ));

switch ( item->event )
{
case RTEMS_RECORD_THREAD_SWITCH_OUT:
Expand Down Expand Up @@ -441,6 +541,8 @@ int main( int argc, char **argv )
snprintf( file_index, sizeof( file_index ), "%ld", i );
strcat( filename, file_index );

memset( &cctx.map_per_cpu[ i ].hashArray, 0, sizeof( cctx.map_per_cpu[ i ].hashArray ));

event_streams[ i ] = fopen( filename , "wb" );

ctf_packet_header.ctf_magic = CTF_MAGIC;
Expand Down

0 comments on commit a8da9cc

Please sign in to comment.