Is there a "function size profiler" out there?
c++, function, profiler, size
Solution
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>
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.
Problem
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?) Edit: Note, I am using Visual C++ on Windows.