setsamps.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 873 行 · 第 1/2 页
C
873 行
curr_sio->asm_src_info.rel_bar = rel_bar;
}
extern void StretchSetAll( sio_data *curr_sio, bint bar_max )
/***********************************************************/
{
image_info *curr_image;
mod_info *curr_mod;
file_info *curr_file;
long int count;
int count2;
int count3;
int count4;
count = 0;
while( count < curr_sio->image_count ) {
curr_image = curr_sio->images[count];
count2 = 0;
while( count2 < curr_image->mod_count ) {
curr_mod = curr_image->module[count2];
count3 = 0;
while( count3 < curr_mod->file_count ) {
curr_file = curr_mod->mod_file[count3];
count4 = 0;
while( count4 < curr_file->rtn_count ) {
curr_file->routine[count4]->bar_max = bar_max;
count4++;
}
curr_file->bar_max = bar_max;
count3++;
}
curr_mod->bar_max = bar_max;
count2++;
}
curr_image->bar_max = bar_max;
count++;
}
curr_sio->bar_max = bar_max;
curr_sio->asm_src_info.bar_max = bar_max;
}
extern void SortSetAll( sio_data *curr_sio, int sort_type )
/*********************************************************/
{
image_info *curr_image;
mod_info *curr_mod;
file_info *curr_file;
long int count;
int count2;
int count3;
count = 0;
while( count < curr_sio->image_count ) {
curr_image = curr_sio->images[count];
count2 = 0;
while( count2 < curr_image->mod_count ) {
curr_mod = curr_image->module[count2];
count3 = 0;
while( count3 < curr_mod->file_count ) {
curr_file = curr_mod->mod_file[count3];
curr_file->sort_type = sort_type;
curr_file->sort_needed = B_TRUE;
count3++;
}
curr_mod->sort_type = sort_type;
curr_mod->sort_needed = B_TRUE;
count2++;
}
curr_image->sort_type = sort_type;
curr_image->sort_needed = B_TRUE;
count++;
}
curr_sio->sort_type = sort_type;
curr_sio->sort_needed = B_TRUE;
}
STATIC void resolveImageSamples( void )
/*************************************/
{
image_info *curr_image;
massgd_sample_addr **massgd_data;
mod_info *curr_mod;
file_info *curr_file;
rtn_info *curr_rtn;
address *addr;
sample_index_t tick_index;
mod_handle mh;
sym_handle *sh;
long int count;
int count2;
int count3;
int count4;
int index;
int index2;
sh = __alloca( DIPHandleSize( HK_SYM ) );
massgd_data = CurrSIOData->massaged_sample;
tick_index = 1;
index = 0;
index2 = 0;
for( count = 0; count < CurrSIOData->number_massaged; ++count, ++index2 ) {
if( index2 > MAX_MASSGD_BUCKET_INDEX ) {
++index;
index2 = 0;
}
addr = massgd_data[index][index2].raw;
if( AddrMod( *addr, &mh ) == SR_NONE ) {
curr_image = AddrImage( addr );
if( curr_image == NULL ) {
curr_image = CurrSIOData->images[0];
}
curr_mod = curr_image->module[0];
curr_rtn = curr_mod->mod_file[0]->routine[0];
} else {
curr_image = *(image_info **)ImageExtra( mh );
curr_mod = findCurrMod( curr_image, mh );
if( AddrSym( mh, *addr, sh ) == SR_NONE ) {
curr_rtn = curr_mod->mod_file[0]->routine[0];
} else {
curr_rtn = findCurrRtn( curr_mod, sh );
/**/ myassert( curr_rtn != NULL );
}
}
if( curr_rtn != NULL ) {
curr_rtn->tick_count += massgd_data[index][index2].hits;
if( curr_rtn->first_tick_index == 0 ) {
curr_rtn->first_tick_index = tick_index;
if( curr_mod->first_tick_index == 0
|| curr_mod->first_tick_index > tick_index ) {
curr_mod->first_tick_index = tick_index;
}
}
curr_rtn->last_tick_index = tick_index;
}
tick_index++;
}
CurrSIOData->max_time = 0;
count = 0;
while( count < CurrSIOData->image_count ) {
curr_image = CurrSIOData->images[count];
curr_image->max_time = 0;
count2 = 0;
while( count2 < curr_image->mod_count ) {
curr_mod = curr_image->module[count2];
curr_mod->max_time = 0;
count3 = 0;
while( count3 < curr_mod->file_count ) {
curr_file = curr_mod->mod_file[count3];
curr_rtn = curr_file->routine[0];
if( curr_rtn->unknown_routine && curr_rtn->tick_count == 0 ) {
curr_rtn->ignore_unknown_rtn = B_TRUE;
curr_file->ignore_unknown_rtn = B_TRUE;
}
curr_file->max_time = 0;
count4 = 0;
while( count4 < curr_file->rtn_count ) {
curr_rtn = curr_file->routine[count4];
curr_file->agg_count += curr_rtn->tick_count;
if( curr_rtn->tick_count > curr_file->max_time ) {
curr_file->max_time = curr_rtn->tick_count;
}
count4++;
}
curr_mod->agg_count += curr_file->agg_count;
if( curr_file->agg_count > curr_mod->max_time ) {
curr_mod->max_time = curr_file->agg_count;
}
count3++;
}
curr_file = curr_mod->mod_file[0];
if( curr_file->unknown_file && curr_file->agg_count == 0 ) {
curr_file->ignore_unknown_file = B_TRUE;
curr_mod->ignore_unknown_file = B_TRUE;
}
curr_image->agg_count += curr_mod->agg_count;
if( curr_mod->agg_count > curr_image->max_time ) {
curr_image->max_time = curr_mod->agg_count;
}
count2++;
}
curr_mod = curr_image->module[0];
if( curr_mod->unknown_module && curr_mod->agg_count == 0 ) {
curr_mod->ignore_unknown_mod = B_TRUE;
curr_image->ignore_unknown_mod = B_TRUE;
}
if( curr_image->agg_count > CurrSIOData->max_time ) {
CurrSIOData->max_time = curr_image->agg_count;
}
count++;
}
curr_image = CurrSIOData->images[0];
if( curr_image->unknown_image && curr_image->agg_count == 0 ) {
curr_image->ignore_unknown_image = B_TRUE;
}
}
STATIC void loadImageInfo( image_info * curr_image )
/**************************************************/
{
int name_len;
int object_file;
int sym_file;
struct stat file_status;
sym_file = -1;
object_file = -1;
curr_image->dip_handle = NO_MOD;
if( curr_image->sym_deleted ) {
} else if( curr_image->sym_name != NULL ) {
sym_file = open( curr_image->sym_name, O_RDONLY|O_BINARY );
if( sym_file != -1 ) {
curr_image->dip_handle = WPDipLoadInfo( sym_file,
curr_image->sym_name, curr_image,
sizeof(image_info), DP_MIN, DP_MAX );
}
} else {
name_len = strlen( curr_image->name ) + 1;
memcpy( FNameBuff, curr_image->name, name_len );
ReplaceExt( FNameBuff, ".sym" );
name_len = strlen( FNameBuff ) + 1;
curr_image->sym_name = ProfAlloc( name_len );
memcpy( curr_image->sym_name, FNameBuff, name_len );
sym_file = open( curr_image->sym_name, O_RDONLY|O_BINARY );
if( sym_file != -1 ) {
curr_image->dip_handle = WPDipLoadInfo( sym_file,
curr_image->sym_name, curr_image,
sizeof(image_info), DP_MIN, DP_MAX );
}
if( curr_image->dip_handle == NO_MOD ) {
ProfFree( curr_image->sym_name );
curr_image->sym_name = NULL;
}
}
object_file = open( curr_image->name, O_RDONLY|O_BINARY );
if( object_file == -1 ) {
curr_image->exe_not_found = B_TRUE;
if( curr_image->main_load ) {
ErrorMsg( LIT( Exe_Not_Found ), curr_image->name );
}
} else if( curr_image->time_stamp == 0 ) {
/*
If sample timestamp is 0, the sampler couldn't figure out
the right value. Assume it's OK.
*/
} else if( fstat( object_file, &file_status ) == 0 ) {
/* QNX creation dates and time stamps tend to be 1 */
/* unit different, so do not test for equality */
if( file_status.st_mtime - curr_image->time_stamp > 1 ) {
curr_image->exe_changed = B_TRUE;
if( curr_image->main_load ) {
ErrorMsg( LIT( Exe_Has_Changed ), curr_image->name );
}
}
}
if( curr_image->dip_handle == NO_MOD && !curr_image->sym_deleted
&& object_file != -1 ) {
curr_image->dip_handle = WPDipLoadInfo( object_file,
curr_image->name, curr_image,
sizeof(image_info), DP_MIN, DP_MAX );
}
if( curr_image->dip_handle == NO_MOD ) {
if( sym_file != -1 ) {
close( sym_file );
}
if( object_file != -1 ) {
close( object_file );
}
}
initModuleInfo( curr_image );
if( curr_image->dip_handle != NO_MOD ) {
WalkModList( curr_image->dip_handle, &loadModuleInfo, curr_image );
}
}
STATIC void loadSampleImages( void )
/**********************************/
{
image_info *curr_image;
int image_count;
CurrSIOData->dip_process = WPDipProc();
WPDipSetProc( CurrSIOData->dip_process );
image_count = 0;
while( image_count < CurrSIOData->image_count ) {
if( CurrSIOData->images[image_count]->unknown_image ) break;
image_count++;
}
if( image_count != 0 ) {
curr_image = CurrSIOData->images[image_count];
CurrSIOData->images[image_count] = CurrSIOData->images[0];
CurrSIOData->images[0] = curr_image;
}
image_count = 0;
while( image_count < CurrSIOData->image_count ) {
curr_image = CurrSIOData->images[image_count];
curr_image->agg_count = 0;
if( curr_image->unknown_image ) {
initModuleInfo( curr_image );
} else {
loadImageInfo( curr_image );
}
image_count++;
}
}
STATIC void calcAggregates( void )
/********************************/
{
unsigned index;
unsigned index2;
int cmp_result;
unsigned *sorted_idx;
address ***sorted_vect;
massgd_sample_addr **massgd_data;
unsigned mbuckets;
unsigned curr_mbucket;
unsigned curr_midx;
thread_data *thd;
unsigned buckets;
unsigned base;
unsigned best;
unsigned end;
massgd_sample_addr *curr;
ClearMassaged( CurrSIOData );
buckets = 0;
for( thd = CurrSIOData->samples; thd != NULL; thd = thd->next ) {
buckets += RAW_BUCKET_IDX( thd->end_time - thd->start_time ) + 1;
}
sorted_idx = ProfCAlloc( buckets * sizeof( *sorted_idx ) );
sorted_vect = ProfAlloc( buckets * sizeof(*thd->raw_bucket) );
base = 0;
for( thd = CurrSIOData->samples; thd != NULL; thd = thd->next ) {
end = RAW_BUCKET_IDX( thd->end_time - thd->start_time ) + 1;
for( index = 0; index < end; ++index, ++base ) {
sorted_vect[base] = ProfAlloc( MAX_RAW_BUCKET_INDEX * sizeof( **sorted_vect ) );
for( index2 = 0; index2 < MAX_RAW_BUCKET_INDEX; ++index2 ) {
sorted_vect[base][index2]
= &thd->raw_bucket[index][index2];
}
qsort( sorted_vect[base], MAX_RAW_BUCKET_INDEX, sizeof(**sorted_vect), rawSampCmp );
}
}
/* skip over all the 0:0 samples */
for( index = 0; index < buckets; ++index ) {
index2 = 0;
for( ;; ) {
if( index2 >= MAX_RAW_BUCKET_INDEX ) break;
if( !(sorted_vect[index][index2]->mach.segment == 0
&& sorted_vect[index][index2]->mach.offset == 0) ) break;
++index2;
}
sorted_idx[index] = index2;
}
curr = NULL;
curr_mbucket = 0;
curr_midx = -1;
mbuckets = 1;
massgd_data = ProfAlloc( sizeof( *massgd_data ) );
massgd_data[0] = ProfCAlloc( MAX_MASSGD_BUCKET_SIZE );
for( ;; ) {
best = -1U;
for( index = 0; index < buckets; ++index ) {
index2 = sorted_idx[index];
if( index2 >= MAX_RAW_BUCKET_INDEX ) continue;
if( best == -1U ) best = index;
cmp_result = AddrCmp( sorted_vect[index][index2],
sorted_vect[best][sorted_idx[best]] );
if( cmp_result < 0 ) best = index;
}
if( best == -1U ) break;
if( curr == NULL || AddrCmp( sorted_vect[best][sorted_idx[best]], curr->raw ) != 0 ) {
if( ++curr_midx >= MAX_MASSGD_BUCKET_INDEX ) {
++curr_mbucket;
massgd_data = ProfRealloc( massgd_data, (curr_mbucket+1) * sizeof(*massgd_data) );
massgd_data[curr_mbucket] = ProfCAlloc( MAX_MASSGD_BUCKET_SIZE );
curr_midx = 0;
}
curr = &massgd_data[curr_mbucket][curr_midx];
curr->raw = sorted_vect[best][sorted_idx[best]];
}
curr->hits++;
sorted_idx[best]++;
}
CurrSIOData->massaged_sample = massgd_data;
CurrSIOData->number_massaged = 1 + curr_midx
+ (curr_mbucket * (unsigned long)MAX_MASSGD_BUCKET_INDEX);
CurrSIOData->massaged_mapped = B_TRUE;
for( index = 0; index < buckets; ++index ) {
ProfFree( sorted_vect[index] );
}
ProfFree( sorted_vect );
ProfFree( sorted_idx );
}
extern void SetSampleInfo( sio_data *curr_sio )
/*********************************************/
{
void *cursor_type;
cursor_type = WndHourGlass( NULL );
if( curr_sio->dip_process != NULL ) {
WPDipDestroyProc( curr_sio->dip_process );
curr_sio->dip_process = NULL;
}
CurrSIOData = curr_sio;
SetCurrentMAD( CurrSIOData->config.mad );
if( CurrSIOData->samples != NULL ) {
if( !CurrSIOData->massaged_mapped || CurrSIOData->massaged_sample == NULL ) {
calcAggregates();
}
}
loadSampleImages();
resolveImageSamples();
GatherSetAll( curr_sio, B_FALSE );
AbsSetAll( curr_sio, B_TRUE );
RelSetAll( curr_sio, B_TRUE );
SortSetAll( curr_sio, SORT_COUNT );
WndHourGlass( cursor_type );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?