/* duplicate RFG regions object */ RFG_Regions* RFG_Regions_dup( const RFG_Regions* oldRegions ) { RFG_Regions* ret = RFG_Regions_init(); if( ret ) { uint32_t i; /* copy region info hash table */ if( oldRegions->num_region_infos > 0 ) { for( i = 0; i < REGION_INFO_HASH_MAX; i++ ) { RFG_RegionInfoHN* curr = oldRegions->region_infos[i]; while( curr ) { region_info_hash_put( ret->region_infos, curr->info.regionId, curr->info.regionName, curr->info.groupName, curr->info.callLimit, curr->info.stackBounds, curr->info.flags ); ret->num_region_infos++; curr = curr->next; } } } /* copy call-path info hash table */ if( oldRegions->num_cpath_infos > 0 ) { for( i = 0; i < CPATH_INFO_HASH_MAX; i++ ) { RFG_CallPathInfoHN* curr = oldRegions->cpath_infos[i]; while( curr ) { cpath_info_hash_put( ret->cpath_infos, curr->info.hash, curr->info.size, curr->info.regionIds, curr->info.callLimit ); ret->num_cpath_infos++; curr = curr->next; } } } } return ret; }
void VTThrd_create(uint32_t tid, uint32_t ptid, const char* tname, uint8_t is_virtual) { VTThrd *thread; #if defined(VT_METR) uint32_t num_metrics = (uint32_t)vt_metric_num(); #endif /* VT_METR */ #if defined(VT_RUSAGE) uint32_t num_rusage = (uint32_t)vt_rusage_num(); #endif /* VT_RUSAGE */ thread = (VTThrd*)calloc(1, sizeof(VTThrd)); if ( thread == NULL ) vt_error(); /* set thread name, if available */ if ( tname == NULL ) { if ( tid == 0 ) tname = "Process"; else tname = "Thread"; } /* set thread name */ strncpy(thread->name, tname, sizeof(thread->name)); thread->name[sizeof(thread->name)-1] = '\0'; /* set thread name suffix */ if ( tid != 0 ) { #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); #endif /* VT_MT || VT_HYB || VT_JAVA */ snprintf(thread->name_suffix, sizeof(thread->name_suffix)-1, "%s:%d", VTThrdv[ptid]->name_suffix, ++(VTThrdv[ptid]->child_num)); #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_UNLOCK_ENV(); #endif /* VT_MT || VT_HYB || VT_JAVA */ } /* set parent ID of thread */ thread->parent_tid = ptid; /* set the virtual thread flag */ thread->is_virtual_thread = is_virtual; #if defined(VT_GETCPU) thread->cpuid_val = (uint32_t)-1; #endif /* VT_GETCPU */ #if defined(VT_RUSAGE) if ( num_rusage > 0 ) { /* create rusage object */ thread->ru_obj = vt_rusage_create(); /* initialize per-thread arrays for rusage counter values */ thread->ru_valv = (uint64_t*)calloc(num_rusage, sizeof(uint64_t)); if ( thread->ru_valv == NULL ) vt_error(); /* initialize next timestamp for reading rusage counters */ thread->ru_next_read = 0; } #endif /* VT_RUSAGE */ #if defined(VT_METR) if ( num_metrics > 0 && is_virtual == 0) { /* create event set */ thread->metv = vt_metric_create(); # if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) /* initialize per-thread arrays for counter offsets */ thread->offv = (uint64_t*)calloc(num_metrics, sizeof(uint64_t)); if ( thread->offv == NULL ) vt_error(); #endif /* VT_MT || VT_HYB || VT_JAVA */ /* initialize per-thread arrays for counter values */ thread->valv = (uint64_t*)calloc(num_metrics, sizeof(uint64_t)); if ( thread->valv == NULL ) vt_error(); } #endif /* VT_METR */ #if !defined(VT_DISABLE_RFG) /* initialize region filter and grouping management */ thread->rfg_regions = RFG_Regions_init(); if( thread->rfg_regions == NULL ) vt_error_msg("Could not initialize region filter and grouping management"); #endif /* VT_DISABLE_RFG */ /* enable tracing */ thread->trace_status = VT_TRACE_ON; VTThrdv[tid] = thread; #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); vt_cntl_msg(2, "Thread object #%u created, total number is %u", tid, VTThrdn); VTTHRD_UNLOCK_ENV(); #else /* VT_MT || VT_HYB || VT_JAVA */ vt_cntl_msg(2, "Thread object #%u created, total number is %u", tid, VTThrdn); #endif /* VT_MT || VT_HYB || VT_JAVA */ }