2

Let's say that I have a C++ program, which when compiled, produces an executable binary many megabytes in size. How do I find out where this size came from? Is there a tool that can show that X% of the size came from file or class Y, etc?

Ideally, I'm looking for a tool similar to Disk Usage Analyzer that can break down what makes up an executable into some kind of pie chart or other graph. If not, at least having the information available would allow creating charts.

The final goal would be to identify parts of the program that I can exclude from the executable to shrink it down and optimize for size, starting from the largest pieces of unnecessary code.

7
  • 1
    Does this solve your problem? stackoverflow.com/questions/2509734/break-down-c-code-size Commented Jul 19, 2021 at 2:04
  • This might help as well. Commented Jul 19, 2021 at 2:05
  • 3
    You could take a look at Bloaty McBloatface, if only for the name. Commented Jul 19, 2021 at 2:13
  • 1
    If you just assume 90% of it comes from the libraries you're using, including the ones provided with C++, you probably won't be far off. Commented Jul 19, 2021 at 2:14
  • @PaulSanders Thanks, Bloaty works really well! Here is the command I ended up using: ./bloaty filenamehere -n 0 -d compileunits --csv > output.csv. If you post this as an answer I will accept it. Commented Jul 19, 2021 at 5:36

1 Answer 1

2

You could take a look at Bloaty McBloatface, which claims to be designed to do exactly this:

Ever wondered what's making your binary big? Bloaty McBloatface will show you a size profile of the binary so you can understand what's taking up space inside.

Bloaty performs a deep analysis of the binary. Using custom ELF, DWARF, and Mach-O parsers, Bloaty aims to accurately attribute every byte of the binary to the symbol or compileunit that produced it. It will even disassemble the binary looking for references to anonymous data. For more information about the analysis performed by Bloaty, please see doc/how-bloaty-works.md.

Bloaty works on binaries, shared objects, object files, and static libraries (.a files). The following file formats are supported:

ELF
Mach-O
WebAssembly (experimental)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.