GithubHelp home page GithubHelp logo

z1076 / go-size-analyzer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zxilly/go-size-analyzer

0.0 0.0 0.0 1.88 MB

A tool for determining the extent to which dependencies contribute to the bloated size of compiled Go binaries.

Home Page: https://gsa.zxilly.dev/

License: GNU Affero General Public License v3.0

JavaScript 6.41% Python 16.25% Go 55.49% TypeScript 21.37% HTML 0.08% SCSS 0.40%

go-size-analyzer's Introduction

go-size-analyzer

Go Report Card Tests Codecov GitHub release go-recipes OpenSSF Scorecard

English | 简体中文

A simple tool to analyze the size of a Go compiled binary.

Packaging status

Installation

MacOS / Linux via Homebrew:

Using Homebrew

brew install go-size-analyzer

Windows:

Using scoop

scoop install go-size-analyzer

Go Install:

go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest

Usage

Example

Web mode

$ gsa --web golang-compiled-binary

Will start a web server on port 8080, you can view the result in your browser.

Or you can use the WASM version in the browser: GSA Treemap

Note

Due to the limitation of the browser, the wasm version is much slower than the native version. Normally costs 10x time to analyze the same binary.

Only recommended for analysing small applications (less than 30 MB in size)

The web page will look like this:

image

You can click to expand the package to see the details.

Terminal UI

$ gsa --tui golang-compiled-binary

demo

Text mode

$ gsa docker-compose-linux-x86_64
+------------------------------------------------------------------------------+
| docker-compose-linux-x86_64                                                  |
+---------+-----------------------------------------------+--------+-----------+
| PERCENT | NAME                                          | SIZE   | TYPE      |
+---------+-----------------------------------------------+--------+-----------+
| 27.76%  | .gopclntab                                    | 17 MB  | section   |
| 15.17%  | .rodata                                       | 9.5 MB | section   |
| 11.63%  | k8s.io/api                                    | 7.3 MB | vendor    |
| 6.69%   | .strtab                                       | 4.2 MB | section   |
| 3.47%   | k8s.io/client-go                              | 2.2 MB | vendor    |
| 3.37%   | .symtab                                       | 2.1 MB | section   |
| 2.28%   | github.com/moby/buildkit                      | 1.4 MB | vendor    |
| 1.54%   | github.com/gogo/protobuf                      | 968 kB | vendor    |
| 1.53%   | github.com/google/gnostic-models              | 958 kB | vendor    |
| 1.33%   | github.com/aws/aws-sdk-go-v2                  | 836 kB | vendor    |
| 1.26%   | crypto                                        | 790 kB | std       |
| 1.25%   | google.golang.org/protobuf                    | 782 kB | vendor    |
| 1.24%   | k8s.io/apimachinery                           | 779 kB | vendor    |
| 1.24%   | net                                           | 777 kB | std       |
| 1.20%   | github.com/docker/compose/v2                  | 752 kB | main      |
| 0.95%   | .noptrdata                                    | 596 kB | section   |
| 0.93%   | go.opentelemetry.io/otel                      | 582 kB | vendor    |
| 0.85%   | google.golang.org/grpc                        | 533 kB | vendor    |
| 0.71%   | runtime                                       | 442 kB | std       |
| 0.59%   | github.com/docker/buildx                      | 371 kB | vendor    |
| 0.55%   | github.com/docker/docker                      | 347 kB | vendor    |
| 0.53%   |                                               | 331 kB | generated |
| 0.52%   | golang.org/x/net                              | 326 kB | vendor    |
| 0.47%   | github.com/theupdateframework/notary          | 294 kB | vendor    |

...[Collapsed]...

| 0.00%   | database/sql/driver                           | 128 B  | std       |
| 0.00%   | .note.go.buildid                              | 100 B  | section   |
| 0.00%   | hash/fnv                                      | 96 B   | std       |
| 0.00%   | maps                                          | 96 B   | std       |
| 0.00%   | github.com/moby/sys/sequential                | 64 B   | vendor    |
| 0.00%   | .text                                         | 1 B    | section   |
+---------+-----------------------------------------------+--------+-----------+
| 97.65%  | KNOWN                                         | 61 MB  |           |
| 100%    | TOTAL                                         | 63 MB  |           |
+---------+-----------------------------------------------+--------+-----------+

Svg Mode

gsa cockroach-darwin-amd64 -f svg -o data.svg --hide-sections

image

Full options

Usage: gsa <file> [flags]

A tool for analyzing the size of dependencies in compiled Golang binaries,
providing insight into their impact on the final build.

Arguments:
  <file>    Binary file to analyze

Flags:
  -h, --help             Show context-sensitive help.
      --verbose          Verbose output
  -f, --format="text"    Output format, possible values: text,json,html,svg
      --no-disasm        Skip disassembly pass
      --no-symbol        Skip symbol pass
      --no-dwarf         Skip dwarf pass
  -o, --output=STRING    Write to file
      --version          Show version

Text output options
  --hide-sections    Hide sections
  --hide-main        Hide main package
  --hide-std         Hide standard library

Json output options
  --indent=INDENT    Indentation for json output
  --compact          Hide function details, replacement with size

Svg output options
  --width=1028         Width of the svg treemap
  --height=640         Height of the svg treemap
  --margin-box=4       Margin between boxes
  --padding-box=4      Padding between box border and content
  --padding-root=32    Padding around root content

Web interface options
  --web               use web interface to explore the details
  --listen=":8080"    listen address
  --open              Open browser

Terminal interface options
  --tui    use terminal interface to explore the details

Caution

The tool can work with stripped binaries, but it may lead to inaccurate results.

TODO

  • Add more pattern for disassembling the binary
  • Extract the information from the DWARF section
  • Count the symbol size itself to package
  • Add other charts like flame graph, pie chart, etc.
  • Support C++/Rust symbol demangling in cgo
  • Add a TUI mode for exploring details
  • Compile to wasm, create a ui to analyze the binary in the browser

Contribution

Any contribution is welcome, feel free to open an issue or a pull request.

LICENSE

Published under the AGPL-3.0.

go-size-analyzer's People

Contributors

zxilly avatar dependabot[bot] avatar ccoveille avatar step-security-bot avatar nikolaydubina avatar cristaloleg avatar fossabot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.