bpf 实现支持热插拔的内存泄露检测
This commit is contained in:
@@ -84,7 +84,7 @@ void *nMalloc(size_t size, const char * filename, const char *func, int line){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fprintf(fp, "[+] [%s : %s : %d] %p: %ld malloc\n", filename, func, line, ptr, size);
|
||||
fprintf(fp, "[+] [%s:%d:%s] [%p:%ld]\n", filename, line, func, ptr, size);
|
||||
fflush(fp);
|
||||
fclose(fp);
|
||||
|
||||
|
||||
BIN
memory/leak_detect/bpftrace
Executable file
BIN
memory/leak_detect/bpftrace
Executable file
Binary file not shown.
36
memory/leak_detect/memleak.bpf
Normal file
36
memory/leak_detect/memleak.bpf
Normal file
@@ -0,0 +1,36 @@
|
||||
BEGIN
|
||||
{
|
||||
printf("Start memory leakage detect\n");
|
||||
}
|
||||
|
||||
uprobe:/home/lian/share/9.1-kvstore/kvstore:nMalloc
|
||||
{
|
||||
@tmp_size[tid] = arg0;
|
||||
@tmp_file[tid] = str(arg1);
|
||||
@tmp_func[tid] = str(arg2);
|
||||
@tmp_line[tid] = arg3;
|
||||
}
|
||||
|
||||
uretprobe:/home/lian/share/9.1-kvstore/kvstore:nMalloc
|
||||
{
|
||||
$ptr = retval;
|
||||
|
||||
if ($ptr != 0) {
|
||||
@allocs[$ptr] = ( @tmp_file[tid], @tmp_line[tid], @tmp_func[tid], @tmp_size[tid]);
|
||||
}
|
||||
|
||||
delete(@tmp_size[tid]);
|
||||
delete(@tmp_file[tid]);
|
||||
delete(@tmp_func[tid]);
|
||||
delete(@tmp_line[tid]);
|
||||
}
|
||||
|
||||
uprobe:/home/lian/share/9.1-kvstore/kvstore:nFree
|
||||
{
|
||||
delete(@allocs[arg0]);
|
||||
}
|
||||
|
||||
END
|
||||
{
|
||||
printf("\n=== Memory Leaks ===\n");
|
||||
}
|
||||
Reference in New Issue
Block a user