是否有“函数大小分析器”在那里? [英] Is there a "function size profiler" out there?

查看:130
本文介绍了是否有“函数大小分析器”在那里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++项目上工作了三年后,可执行文件已经增长到4 MB。我想看看所有这些空间在哪里。有没有工具,可以报告什么是最大的空间猪?这将是很高兴看到类的大小(所有函数在一个类),通过模板(所有实例化)和库(多少属于C标准库和STL?每个库在EXE有多少?

After three years working on a C++ project, the executable has grown to 4 MB. I'd like to see where all this space is going. Is there a tool that could report what the biggest space hogs are? It would be nice to see the size by class (all functions in a class), by template (all instantiations), and by library (how much belongs to the C standard library and STL? how much for each library in the exe?)

编辑:注意,我在Windows上使用Visual C ++。

Note, I am using Visual C++ on Windows.

推荐答案

p> 在Linux 中,您可以使用 nm 以显示可执行文件中的所有符号,并按大小以相反的顺序对它们进行排序:

In Linux, you can use nm to show all symbols in the executable and to sort them in reverse order by size:

$ nm -CSr --size-sort <exe>

选项:


  • -C 拆分C ++名称。

  • 显示符号的大小。

  • - size-sort / strong>按大小排序符号。

  • -r b $ b
  • -C demangles C++ names.
  • -S shows size of symbols.
  • --size-sort sorts symbols by size.
  • -r reverses the sort.

如果要获得每个命名空间或每个类的结果,可以只输入 grep for' namespace :: ',' namespace :: class_name :: ',等。 >。

If you want to get the results per namespace or per class, you can just grep the output for 'namespace::', 'namespace::class_name::', etc..

如果您只想查看可执行文件中定义的符号(不是在库中定义的符号),请添加 - defined-only

If you only want to see symbols that are defined in the executable (not ones defined elsewhere, like in libraries) then add --defined-only. Sorting by size should take care of this, though, since undefined symbols aren't going to have a size.

对于Windows ,您应该按照尺寸排序,因为未定义的符号不会有大小。仍然能够在您的二进制文件上使用 nm ,因为 nm 支持 COFF 二进制。您可以通过cygwin安装 nm ,或者您可以将Windows可执行文件复制到linux框中,然后在其上运行 nm

For Windows, you should still be able to use nm on your binary files, since nm supports COFF binaries. You can install nm via cygwin, or you could copy your windows executable to a linux box and run nm on it there.

您也可以尝试 dumpbin ,它在Windows上转储有关二进制文件的信息。您可以使用 / SYMBOLS 开关获取符号上的信息,但它看起来不像直接提供关于它们大小的信息。

You could also try dumpbin, which dumps info about a binary on Windows. You can get info on symbols with the /SYMBOLS switch, but it doesn't look like it directly provides information about their size.

这篇关于是否有“函数大小分析器”在那里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆