Shotizam analyzes the size of Go binaries

Related tags



Shotizam analyzes the size of Go binaries and outputs SQL with size info for analysis in SQLite3.

$ shotizam --sqlite /some/go.binary
SQLite version 3.28.0 2019-04-15 14:49:49
Enter ".help" for usage hints.
sqlite> .width 40
sqlite> .mode column

sqlite> select func, sum(size) from bin where func <> '' group by 1 order by 2 desc limit 20;
unicode.init                              21528
debug/dwarf.init                          13764
fmt.(*pp).printValue                      11941
debug/macho.NewFile                       10017
time.Time.AppendFormat                    9949
runtime.gentraceback                      8278
debug/elf.NewFile                         7631
runtime.selectgo                          6722
encoding/binary.Read                      6555
main.main                                 6476
internal/                  6373
time.LoadLocationFromTZData               5795
fmt.(*pp).doPrintf                        5520
runtime.findrunnable                      5287
runtime.typesEqual                        4843
time.nextStdChunk                         4736
time.ParseDuration                        4440
time.loadTzinfoFromZip                    4234
runtime.(*pageAlloc).find                 4109
runtime.heapBitsSetType                   3938

sqlite> select what, sum(size) from bin group by 1;
TODO                                      1370985
fixedheader                               101800
funcdata                                  99656
funcname                                  63062
pcdata0-regmap                            54361
pcdata1-stackmap                          47977
pcdata2-inltree                           40024
pcfile                                    38544
pcln                                      141103
pcsp                                      36478
text                                      896722

sqlite> select pkg, sum(size) from bin where pkg <> '' group by 1 order by 2 desc limit 20;
runtime               621236
reflect               187926
fmt                   61727
time                  58786
strconv               55817
syscall               39481
debug/elf             37070
os                    36707
compress/flate        31462
debug/macho           27117
encoding/binary       26637
os/exec               26599
internal/reflectlite  23687
unicode               22316
sync                  21322
flag                  20871
debug/dwarf           17692
internal/poll         17092
strings               15511
sort                  14992

sqlite> select func, length(func) from bin order by 2 desc limit 5;
type..eq.[67]struct { runtime.size uint3  89
type..eq.[67]struct { runtime.size uint3  89
type..eq.[67]struct { runtime.size uint3  89
type..eq.[67]struct { runtime.size uint3  89
type..eq.[67]struct { runtime.size uint3  89

sqlite> select func, sum(size) from bin where what = 'pcfile' and func <> '' group by 1 order by 2 desc limit 20;
internal/                  268
fmt.(*pp).printValue                      227
encoding/binary.Read                      195
os.Getwd                                  174
runtime.sighandler                        172
runtime.(*pageAlloc).scavengeOne          153
runtime.findrunnable                      148
debug/macho.NewFile                       131
runtime.selectgo                          130
syscall.forkAndExecInChild                129
main.main                                 123
runtime.(*mspan).sweep                    123
internal/fmtsort.nilCompare               119
runtime.growslice                         119
debug/elf.NewFile                         112
fmt.intFromArg                            107
runtime.greyobject                        105
runtime.evacuate_fast64                   103
runtime.mapaccess2_faststr                101
runtime.evacuate                          99

sqlite> select func, sum(size) from bin where what = 'pcln' and func <> '' group by 1 order by 2 desc limit 20;
time.Time.AppendFormat                    1347
runtime.gentraceback                      1132
runtime.selectgo                          1102
fmt.(*pp).printValue                      1027
runtime.findrunnable                      830
runtime.heapBitsSetType                   794
internal/                  720
runtime.memmove                           720
debug/macho.NewFile                       692
fmt.(*pp).doPrintf                        638
encoding/binary.Read                      616
runtime.runGCProg                         613
syscall.forkAndExecInChild                552
debug/elf.NewFile                         539
runtime.mallocgc                          532
time.LoadLocationFromTZData               530
runtime.duffcopy                          528
aeshashbody                               518
runtime.(*mspan).sweep                    502
runtime.sighandler                        478

sqlite> select * from bin limit 30;
go.buildid                                            fixedheader  40
go.buildid                                            text         112
go.buildid                                            funcname     11
internal/cpu.Initialize                   internal/c  fixedheader  40
internal/cpu.Initialize                   internal/c  pcsp         13
internal/cpu.Initialize                   internal/c  pcfile       5
internal/cpu.Initialize                   internal/c  pcln         21
internal/cpu.Initialize                   internal/c  pcdata0-reg  22
internal/cpu.Initialize                   internal/c  pcdata1-sta  21
internal/cpu.Initialize                   internal/c  text         80
internal/cpu.Initialize                   internal/c  funcname     24
internal/cpu.processOptions               internal/c  fixedheader  40
internal/cpu.processOptions               internal/c  pcsp         24
internal/cpu.processOptions               internal/c  pcfile       6
internal/cpu.processOptions               internal/c  pcln         167
internal/cpu.processOptions               internal/c  pcdata0-reg  30
internal/cpu.processOptions               internal/c  pcdata1-sta  60
internal/cpu.processOptions               internal/c  text         1792
internal/cpu.processOptions               internal/c  funcname     28
internal/cpu.indexByte                    internal/c  fixedheader  40
internal/cpu.indexByte                    internal/c  pcsp         9
internal/cpu.indexByte                    internal/c  pcfile       5
internal/cpu.indexByte                    internal/c  pcln         21
internal/cpu.indexByte                    internal/c  pcdata0-reg  22
internal/cpu.indexByte                    internal/c  text         64
internal/cpu.indexByte                    internal/c  funcname     23
internal/cpu.doinit                       internal/c  fixedheader  40
internal/cpu.doinit                       internal/c  pcsp         22
internal/cpu.doinit                       internal/c  pcfile       5
internal/cpu.doinit                       internal/c  pcln         159


For fun bugs to make Go smaller, see

  • no __gopclntab section found in ELF file when building with PIE enabled

    no __gopclntab section found in ELF file when building with PIE enabled

    I ran (current HEAD, i.e. c9a147c6aa3d4767214712d5886e8a9703f6085b):

    % shotizam --sqlite blaze-bin/…/testsrv
    no __gopclntab section found in ELF file

    When searching for __gopclntab, I only find matches in go/src/cmd/internal/objfile/macho.go. Is this a mac-related thing that I’m missing on Linux?

    opened by stapelberg 5
  • Alternatives?


    How that compares to and

    opened by AlekSi 4
  • Over-Escaping Quotes?

    Over-Escaping Quotes?

    I ran shotizam against Caddy 2 (v2.0.0-rc.3) executable and got about 18 lines of syntax error from SQLite. This is the first offending line and the line that precedes it:

    INSERT INTO Bin VALUES ("*jwtSource).Token", "", "funcname", 43);
    INSERT INTO Bin VALUES ("type..eq.struct { AccessToken string \"json:\\\"access_token\\\"\"; TokenType string \"json:\\\"token_type\\\"\"; IDToken string \"json:\\\"id_token\\\"\"; ExpiresIn int64 \"json:\\\"expires_in\\\"\" }", "", "fixedheader", 40);

    SQLite's complaint: Error: near line 159205: near "json": syntax error

    opened by Mohammed90 3
  • Add support for linux

    Add support for linux

    The linux objdump (at least on ubuntu) uses <> instead of _. Example output from objdump -D on ubuntu - 0000000000402bf0 <runtime.c64hash>:

    This way it works for compiled binaries on linux (checked on Ubuntu only) with CGO_ENABLE=1 and CGO_ENABLE=0

    opened by egorse 2
  • Add support for 1.16

    Add support for 1.16

    This pretty much just consists of integrating the changes to upstream debug/gosym.

    Not very well tested, but results seem OK, and all 0 unit tests pass!

    Fixes #10

    opened by prattmic 2
  • Windows and Mac support?

    Windows and Mac support?

    opened by pjebs 1
  • Add url.PathUnescape for package name

    Add url.PathUnescape for package name


    195749 ( 1.63%)


    195749 ( 1.63%)
    opened by SevereCloud 1
  • ELF support

    ELF support

    opened by hugelgupf 1
  • gosym: PCData comes from pctab, not funcdata

    gosym: PCData comes from pctab, not funcdata

    See LineTable.pcvalue and runtime.pcvalue as reference.

    This fixes values from PCData and occassional crashes if the garbage we were reading before happened to be bad varints.

    opened by prattmic 1
Brad Fitzpatrick
Xoogler. Ex @golang team (2010-2020). Currently making WireGuard easier and more magical @Tailscale.
Brad Fitzpatrick
structslop is a static analyzer for Go that recommends struct field rearrangements to provide for maximum space/allocation efficiency.

structslop Package structslop defines an Analyzer that checks struct can be re-arranged fields to get optimal struct size.

orijtech 335 Sep 1, 2021
Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

Sloc Cloc and Code (scc) A tool similar to cloc, sloccount and tokei. For counting physical the lines of code, blank lines, comment lines, and physica

Ben Boyter 2.7k Sep 10, 2021
Remove unnecessary type conversions from Go source

About The unconvert program analyzes Go packages to identify unnecessary type conversions; i.e., expressions T(x) where x already has type T. Install

Matthew Dempsky 310 Aug 10, 2021
a tool for code clone detection

dupl dupl is a tool written in Go for finding code clones. So far it can find clones only in the Go source files. The method uses suffix tree for seri

Michal Bohuslávek 255 Sep 8, 2021
A little fast cloc(Count Lines Of Code)

gocloc A little fast cloc(Count Lines Of Code), written in Go. Inspired by tokei. Installation $ go get -u Usage

Hideo Hattori 471 Sep 15, 2021
The most opinionated Go source code linter for code audit.

go-critic Highly extensible Go source code linter providing checks currently missing from other linters. There is never too much static code analysis.

null 985 Sep 12, 2021
Run linters from Go code -

Lint - run linters from Go Lint makes it easy to run linters from Go code. This allows lint checks to be part of a regular go build + go test workflow

Surul Software Labs GmbH 66 Oct 5, 2020
Staticcheck - The advanced Go linter

The advanced Go linter Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance

Dominik Honnef 4.1k Sep 14, 2021
Type check the empty interface{}

Static type checker for interface{} with a type list This is an experiment. This is a tool that performs a static type check on values of type interfa

Sina Siadat 16 Aug 25, 2021
Bundle k6 with extensions as fast and easily as possible

xk6bundler xk6bundler is a CLI tool and GitHub Action makes bundle k6 with extensions as fast and easily as possible. Features Build for multiple targ

Iván Szkiba 6 Sep 2, 2021
Fast division, modulus and divisibility checks in Go for divisors known only at runtime.

fastdiv Fast division, modulus and divisibility checks for divisors known only at runtime via the method of: "Faster Remainder by Direct Computation:

null 89 Jul 19, 2021
Know when GC runs from inside your golang code

gcnotifier gcnotifier provides a way to receive notifications after every run of the garbage collector (GC). Knowing when GC runs is useful to instruc

Carlo Alberto Ferraris 160 Jul 5, 2021