标签:linux different 基本原理 use 函数调用 参数表 快速 堆栈 function
“different,but not less. 不同,但也不差!”
出现内存错误,查问题是一方面,更多的是需要考虑,以后写代码如何不出现内存错误。总结很关键。
#启动程序的方式: HEAPCHECK=normal HEAPPROFILE=prefix ./test //需要前台启动程序 #第一个参数HEAPCHECK表示检查的严格程度 HEAPPROFILE参数表示生产的内存快照 #默认生成的内存快照文件在/tmp 目录下。
使用HeapProFilerStart("prefix") "prefix"是生成文件的前缀和 HeapProFilerStop 接口
1.在头文件 <gperftools/heap-profiler.h> 中。 2.可以使用http接口或者telnet 使用方式:程序可以前台,也可以后台,启动之后,发命令或者请求让其执行HeapProFilerStart ,
然后复现程序内存上涨的情况,接着在程序的当前目录可以看到 prefix_heap.0001.heap (prefix为start传入的前缀),
随着内存上涨,会持续的生很多的内存快照,差不多的时候stop。然后开始使用获得的内存快照分析。
执行命令: pprof --pdf ./test ./prefix_heap.0001.heap > 1.pdf
执行命令:pprof --pdf --base=prefix_heap.0001.heap ./test ./prefix_heap.0002.heap > 1.pdf
HeapLeakChecker heap_checker("test_foo"); { code that exercises some foo functionality; this code should preserve memory allocation state;
} if (!heap_checker.SameHeap()) assert(NULL == "heap memory leak");
No Leaks found for check "test_foo"
Leak check _main_ detected leaks of 1136 bytes in 2 objects The 2 largest leaks: Leak of 568 bytes in 1 objects allocated from: @ 7fa7f4197dd2 If the preceding stack traces are not enough to find the leaks, try running THIS shell command: pprof ./bin/exe "/tmp/exe.7539._main_-end.heap" --inuse_objects --lines --heapcheck --edgefraction=1e-10 --nodefraction=1e-10 --pdf If you are still puzzled about why the leaks are there, try rerunning this program with HEAP_CHECK_TEST_POINTER_ALIGNMENT=1 and/or with HEAP_CHECK_MAX_POINTER_OFFSET=-1
If the leak report occurs in a small fraction of runs, try running with TCMALLOC_MAX_FREE_QUEUE_SIZE of few hundred MB or with TCMALLOC_RECLAIM_MEMORY=false,
it mi Exiting with error code (instead of crashing) because of whole-program memory leaks
标签:linux different 基本原理 use 函数调用 参数表 快速 堆栈 function
原文地址:https://www.cnblogs.com/panhao/p/10166381.html