我正在尝试分析应用程序以比较其使用不同分配策略的性能。
我在使用 tcmalloc 时可以毫无困难地分析它,但是如何使用 libc 的分配函数来分析它呢?事实上,启用 gperftool 的堆分析器需要使用 -ltcmalloc
标志 ¹但这导致 tcmalloc 被用作分配策略。
最佳答案
how to profile it using libc's allocation functions?
注意:这个要求有点奇怪:当您从 tcmalloc 切换到 GLIBC malloc 时,您的应用程序不会突然开始使用更多或更少的堆内存,或者更改其分配模式或位置。
来自 https://gperftools.github.io/gperftools/heapprofile.html :
Heap profiling requires the use of libtcmalloc. This requirement may be removed in a future version of the heap profiler, and the heap profiler separated out into its own library.
所以你可以
- 等待 Google 开发人员取消此要求(这可能要等几天或几年——我不知道。实际上,上面的 github.io 页面似乎自 2012 年以来就没有更新过,所以我不会在这里屏住呼吸),或者
- 自己贡献分离所需的代码,或者
- 找到用 GLIBC 执行此操作的等效方法(并可能将该代码贡献给 GLIBC)。
我不知道现在有任何现有的 GLIBC 等效项。
关于c++ - 使用 gperftools 的堆分析器来分析 libc malloc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50535473/