一、功能说明
执行优化,使用自定义跟踪API将整个callees 内联到跟踪中。
这句话什么意思,应用程序里会有 call 指令,通过该指令进入 子函数后,又会通过return指令返回。
我们要做的优化就是将 从call 到 return 的过程 内联(存放)到一个 自定义 trace中。
二、主要数据结构 和 配套函数
typedef struct _hashtable_t {
hash_entry_t **table;
hash_type_t hashtype;
bool str_dup;
void *lock;
uint table_bits;
bool synch;
void (*free_payload_func)(void *);
uint (*hash_key_func)(void *);
bool (*cmp_key_func)(void *, void *);
uint entries;
hashtable_config_t config;
uint persist_count;
} hashtable_t;
hashtable_t 结构体 定义在 hashtable.h 头文件里,不需要我们自己定义。并且这应该是属于 Container Data Structures 的文件。
不过这各结构体里面的东西有点多,后面看到我们再说吧。
/****************************************************************************/
/* We use a hashtable to know if a particular tag is for a call trace or a
* normal back branch trace.
*/
typedef struct _trace_head_entry_t {
void *tag;
bool is_trace_head;
// has_ret 的意义是该basic block 含有 return 指令
bool has_ret;
/* We have to end at the next block after we see a return. */
int end_next;
/* Some callees are too large to inline, so we have a size limit. */
uint size;
/* We use a ref count so we know when to remove in the presence of
* thread-private duplicated blocks.
*/
uint refcount;
struct _trace_head_entry_t *next;
} trace_head_entry_t;
static trace_head_entry_t *
create_trace_head_entry(void *tag)
{
trace_head_entry_t *e = (trace_head_entry_t *)dr_global_alloc(sizeof(*e));
e->tag = tag;
e->end_next = 0;
e->size = 0;
e->has_ret = false;
e->is_trace_head = false;
e->refcount = 1;
return e;
}
static void
free_trace_head_entry(void *entry)
{
trace_head_entry_t *e = (trace_head_entry_t *)entry;
dr_global_free(e, sizeof(*e));
}
DR主体函数
1、dr_client_main()
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
if (!drmgr_init())
DR_ASSERT(false)