Is there a “function size profiler” out there?

后端 未结 5 1082
时光说笑
时光说笑 2021-01-31 21:40

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

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 21:59

    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 
    

    Options:

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

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

    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.

    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.

    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.

提交回复
热议问题