In this variation we use inlined atomic instructions to adjust the counters. On a single core box this form should be quite fast, but on a multi-core box the cache line locking for atomic operations will slow things dramatically. We'll look at forms more suitable for multi-core further on.
#ifdef WINDOWS
# define DISPLAY_STRING(msg) dr_messagebox(msg)
#else
# define DISPLAY_STRING(msg) dr_printf("%s\n", msg)
#endif
typedef struct bb_counts {
uint64 blocks;
uint64 total_size;
} bb_counts;
static bb_counts counts_as_built;
void *as_built_lock;
static bb_counts counts_dynamic;
static void
event_exit(void);
event_basic_block(void *drcontext, void *tag, instrlist_t *bb,
bool for_trace, bool translating);
DR_EXPORT void
{
}
static void
event_exit(void)
{
char msg[512];
int len;
len = snprintf(msg, sizeof(msg)/sizeof(msg[0]),
"Number of blocks built : %"UINT64_FORMAT_CODE"\n"
" Average size : %5.2lf instructions\n"
"Number of blocks executed : %"UINT64_FORMAT_CODE"\n"
" Average weighted size : %5.2lf instructions\n",
counts_as_built.blocks,
counts_as_built.total_size / (double)counts_as_built.blocks,
counts_dynamic.blocks,
counts_dynamic.total_size / (double)counts_dynamic.blocks);
msg[sizeof(msg)/sizeof(msg[0])-1] = '\0';
DISPLAY_STRING(msg);
}
event_basic_block(void *drcontext, void *tag, instrlist_t *bb,
bool for_trace, bool translating)
{
uint num_instructions = 0;
num_instructions++;
}
counts_as_built.blocks++;
counts_as_built.total_size += num_instructions;
+
+ #ifdef X86_32
+
+
LOCK(INSTR_CREATE_add(drcontext,
+
LOCK(INSTR_CREATE_adc(drcontext,
+
+
LOCK(INSTR_CREATE_add(drcontext,
+
LOCK(INSTR_CREATE_adc(drcontext,
+ #else
+
LOCK(INSTR_CREATE_add(drcontext,
+ #endif
+
}