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
{
dr_register_bb_event(event_basic_block);
}
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
+
+
+ #else
+ #endif
+
}
Top-level include file for DynamoRIO API.
DR_EXPORT void dr_client_main(client_id_t id, int argc, const char *argv[])
struct _instrlist_t instrlist_t
Definition dr_defines.h:842
uint client_id_t
Definition dr_defines.h:357
DR_API void dr_register_exit_event(void(*func)(void))
dr_emit_flags_t
Definition dr_events.h:138
@ DR_EMIT_DEFAULT
Definition dr_events.h:140
DR_API INSTR_INLINE instr_t * instr_get_next(instr_t *instr)
DR_API instr_t * instrlist_first(instrlist_t *ilist)
#define OPND_CREATE_INT8(val)
Definition dr_ir_macros.h:136
#define OPND_CREATE_INT_32OR8(val)
Definition dr_ir_macros.h:143
#define OPND_CREATE_ABSMEM(addr, size)
Definition dr_ir_macros_aarch64.h:102
#define INSTR_CREATE_add(dc, Rd, Rn, Rm_or_imm)
Definition dr_ir_macros_arm.h:1201
#define INSTR_CREATE_adc(dc, Rd, Rn, Rm_or_imm)
Definition dr_ir_macros_arm.h:1191
#define INSTR_CREATE_inc(dc, d)
Definition dr_ir_macros_x86.h:1580
#define LOCK(instr_ptr)
Definition dr_ir_macros_x86.h:60
@ OPSZ_8
Definition dr_ir_opnd.h:87
@ OPSZ_4
Definition dr_ir_opnd.h:85
DR_API void dr_restore_arith_flags(void *drcontext, instrlist_t *ilist, instr_t *where, dr_spill_slot_t slot)
DR_API void instrlist_meta_preinsert(instrlist_t *ilist, instr_t *where, instr_t *instr)
DR_API void dr_save_arith_flags(void *drcontext, instrlist_t *ilist, instr_t *where, dr_spill_slot_t slot)
Definition dr_defines.h:378