1
0
Fork 0
mirror of https://github.com/imjasonh/gobinsize synced 2026-07-07 00:22:39 +00:00
Commit graph

59 commits

Author SHA1 Message Date
Jason Hall
2bf2749a95 fix some things, generate more
Signed-off-by: Jason Hall <jason@chainguard.dev>
2025-11-18 09:42:10 -05:00
Jason Hall
6b3eda4aaf Track data sections, debug info, and symbol tables
Add tracking for data sections, DWARF debug info, and symbol tables to provide comprehensive binary size attribution to packages.

- Parse and attribute data sections (.data, .rodata, .bss)
- Track DWARF debug info distributed by compile units
- Track symbol tables using Go function tables
- Fix Mach-O symbol attribution (use gosym instead of C symbols)
- Add "internal" category, color stdlib/internal/other gray in SVG

Improves attribution coverage to 89% (gobinsize) and 75% (kubectl).
2025-11-17 18:27:00 -05:00
Jason Hall
2782bab6f9
Update README.md 2025-11-17 11:52:35 -05:00
Jason Hall
d44e871a9a
Merge pull request #5 from imjasonh/copilot/add-svg-dependency-treemap 2025-11-17 11:49:09 -05:00
copilot-swe-agent[bot]
ee90d3a032 Use lighter gray for stdlib and golang.org/x packages
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 16:36:04 +00:00
copilot-swe-agent[bot]
7cb865175d Color all stdlib packages with middle gray
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 16:26:25 +00:00
copilot-swe-agent[bot]
54c6d93c78 Add SVG title tooltips for all treemap rectangles
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 16:11:50 +00:00
copilot-swe-agent[bot]
f405c44899 Include binary name and total size in SVG title
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 15:49:26 +00:00
copilot-swe-agent[bot]
ce492dac63 Add SVG treemap visualization with -svg flag
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 15:42:56 +00:00
copilot-swe-agent[bot]
2aa73979dd Run go fmt and go mod tidy
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 15:40:20 +00:00
copilot-swe-agent[bot]
d68a85a125 Update README and add example SVG treemaps
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 15:36:33 +00:00
copilot-swe-agent[bot]
5bc58e0a47 Add SVG treemap visualization feature with tests
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 15:34:42 +00:00
copilot-swe-agent[bot]
2d62def700 Initial plan 2025-11-17 15:28:33 +00:00
Jason Hall
6074e32197
Merge pull request #4 from imjasonh/copilot/fix-binary-attribute-errors 2025-11-17 09:24:48 -05:00
copilot-swe-agent[bot]
30a59ada38 Use golang.org/x/tools/go/packages instead of go list std
Replaced exec.Command("go", "list", "std") with packages.Load(nil, "std")
from golang.org/x/tools/go/packages as suggested.

Source attribution:
- https://stackoverflow.com/a/53541580
- Posted by Martin Tournoij, modified by community
- Retrieved 2025-11-17, License - CC BY-SA 4.0

This approach is more idiomatic and doesn't require spawning a subprocess.
Added golang.org/x/tools dependency to go.mod.

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 14:10:51 +00:00
copilot-swe-agent[bot]
1592567e90 Use go list std to get stdlib packages dynamically, remove deprecated functions
- Removed hardcoded stdlibPackages map (anti-pattern)
- Added getStdlibPackages() that calls `go list std` dynamically
- Removed deprecated getPackageName(), isExternalDependency(), getModuleName() functions
- Updated findModuleForSymbol() to use dynamic stdlib list
- Fixed assumption that stdlib packages don't have slashes (encoding/json does)
- Updated tests to use findModuleForSymbol instead of deprecated functions
- Removed unused net/url import

All stdlib packages are now properly detected including those with slashes.
No hardcoded lists needed.

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 13:51:20 +00:00
copilot-swe-agent[bot]
6d50d6d9ef Simplify symbol attribution using substring matching
Completely rewrote the attribution logic per feedback. Instead of complex
string parsing to extract package names, now simply check if any module
from BuildInfo or stdlib package is contained in the symbol name.

Key changes:
- New findModuleForSymbol() function uses simple substring matching
- Check BuildInfo modules first (longest first for best match)
- Then check stdlib packages with prefix matching
- Removed all complex string manipulation logic
- Added stdlib package map to avoid guessing based on dots

Fixes:
- google.golang.org symbols now correctly attributed (was: "google")
- Simpler, more maintainable code
- No more edge cases with domains containing dots

Results on Hugo:
- google.golang.org/protobuf: 726.84 KB (was split as "google" 601KB + protobuf 125KB)
- All symbols properly attributed

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 13:31:40 +00:00
copilot-swe-agent[bot]
5f7adcafcd Simplify getModuleName logic by removing anti-pattern heuristics
Removed isLikelyPartialDomain function and complex domain detection logic.
New simpler algorithm:
- If first component has no dot → stdlib package
- If single component with dot → extract base (e.g., unicode.map → unicode)
- If multiple components with dot in first → other

This eliminates the hardcoded list of partial domains which was an anti-pattern.
The module prefix matching handles most cases, and edge cases like go.uber
now extract to their base (go) which is acceptable given the simplicity gain.

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 12:58:48 +00:00
copilot-swe-agent[bot]
38a481bac8 Refactor attribution logic to use sorted module list for proper matching
Completely rewrote the attribution algorithm as requested:
1. Get module dependencies from BuildInfo (including main module)
2. Sort module paths by length (longest first)
3. Iterate through modules to find matches via prefix matching
4. If no match and from stdlib, attribute to stdlib package (e.g., "unicode")
5. Otherwise, attribute to "other" with verbose logging

Key fixes:
- github.com/gohugoio/hugo/common/hstrings → github.com/gohugoio/hugo
- unicode.map → unicode (stdlib)
- go.uber → other (detected as partial domain)
- google.golang.org/protobuf/internal → google.golang.org/protobuf

Added tests covering all edge cases including partial domains, stdlib packages
with .map suffixes, and module subpackages.

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-17 12:08:12 +00:00
copilot-swe-agent[bot]
e0f499f1ef Split out stdlib modules and add verbose logging for 'other' attribution
- Split stdlib packages into individual modules (runtime, net, crypto, etc.) instead of grouping as 'stdlib'
- Added -verbose flag that logs packages attributed to 'other' for debugging
- This helps identify potential attribution errors and understand what's in 'other'

Example verbose output shows:
- Helper types (*.map packages)
- Partial package names (go.uber instead of go.uber.org/automaxprocs)
- Internal subpackages not listed as separate BuildInfo deps

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 22:56:27 +00:00
copilot-swe-agent[bot]
130798a6a5 Ensure all reported modules are in BuildInfo or grouped as stdlib/other
Changed getModuleName to only report modules that exist in BuildInfo.
Packages not in BuildInfo are grouped as:
- "stdlib" for standard library packages (no domain in path)
- "other" for unrecognized packages

This fixes the issue where partial package names like "google", "google.golang",
and stdlib packages like "encoding", "net", "crypto" were being reported as
separate modules when they don't exist in BuildInfo.

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 21:46:48 +00:00
copilot-swe-agent[bot]
8451eac0ca Fix Type.method pattern detection to handle all edge cases
- Handle .init functions before Type.method detection to avoid false positives
- Fix Type.method detection for external packages with 4+ parts
- Add special handling for (*Type).Method followed by type.method patterns
- Add comprehensive tests for all problematic patterns found in Hugo
- Fixes issues like github.com/spf13/pflag.timeValue.Add and nested closures

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 17:05:44 +00:00
copilot-swe-agent[bot]
569a73d2fc Strip trailing semicolons from function names and remove analyze-binaries workflow
- Added handling for trailing semicolons in function names (e.g., io.Reader;)
- Removed analyze-binaries.yml workflow as CI tests now cover everything needed
- Added tests for patterns with semicolons and the new symbols mentioned

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 16:35:21 +00:00
copilot-swe-agent[bot]
468d557808 Extract package info from go: patterns instead of filtering
Changed go:struct and go:itab patterns to extract package information
instead of filtering them out entirely. This ensures symbols like
go:struct { github.com/gohugoio/hugo are attributed to Hugo.

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 13:27:25 +00:00
copilot-swe-agent[bot]
ce4fe88592 Fix mis-attribution of symbols with special characters
- Handle generic instantiations with [go.shape suffix
- Handle go: prefix patterns (go:struct, go:itab, etc.)
- Fix Type.method pattern detection for stdlib packages
- Add comprehensive test coverage for problematic patterns

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 13:14:26 +00:00
copilot-swe-agent[bot]
403c78025f Initial plan 2025-11-16 13:06:38 +00:00
Jason Hall
66f4ae2171
Merge pull request #3 from imjasonh/copilot/add-ci-workflow-go-test 2025-11-16 03:02:47 -05:00
Jason Hall
79aa2ca1d5
Update test.yml 2025-11-16 03:01:16 -05:00
copilot-swe-agent[bot]
24c0d38d9b Fix binary naming for Windows GOOS in integration test
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 07:43:29 +00:00
copilot-swe-agent[bot]
ab6d53493f Run go fmt to clean up whitespace
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 07:42:24 +00:00
copilot-swe-agent[bot]
db324581a0 Add test.yml CI workflow and refactor integration tests for GOOS
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 07:41:36 +00:00
copilot-swe-agent[bot]
6753d6ebf4 Initial plan 2025-11-16 07:31:15 +00:00
Jason Hall
bc95798eff
Merge pull request #2 from imjasonh/copilot/add-binary-analysis-ci 2025-11-16 02:29:14 -05:00
copilot-swe-agent[bot]
81a19db87e Address code review feedback: improve symtab handling and readability
- Make symtab extraction failures non-fatal for modern Go binaries
- Handle cases where symtab symbols are missing or equal (empty symtab)
- Extract symtab as named constant noNextSectionRVA for better readability
- Add comments explaining that modern Go can work without separate symtab

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 07:23:32 +00:00
Jason Hall
0b53836b34
Update analyze-binaries.yml
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 02:18:58 -05:00
copilot-swe-agent[bot]
bed8ace625 Fix Windows PE binary support and add to CI workflow
- Fixed PE symbol handling: symbols are section-relative, not RVAs
- Implemented multi-section data extraction for pclntab/symtab
- Added gap handling between PE sections
- Handle empty symtab (modern Go uses pclntab-only)
- Added ImageBase calculation for correct text address
- Added Windows binary analysis steps to CI workflow
- All three platforms (Linux ELF, Darwin Mach-O, Windows PE) now fully supported

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 06:58:45 +00:00
copilot-swe-agent[bot]
d5fd914924 WIP: Add support for extracting pclntab from modern Windows PE binaries
This is work in progress to support Windows binary analysis. Modern Go (1.16+)
embeds runtime tables within sections rather than as separate PE sections. The
code now attempts to extract pclntab/symtab using runtime symbols, but needs
further refinement to handle tables that span multiple sections.

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 06:40:11 +00:00
copilot-swe-agent[bot]
6fbffa745a Remove Windows binary analysis steps (not supported)
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 06:25:35 +00:00
copilot-swe-agent[bot]
dde12fa4bb Add Darwin and Windows binary analysis to CI workflow
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 06:15:19 +00:00
copilot-swe-agent[bot]
794c2ca921 Initial plan 2025-11-16 06:09:49 +00:00
Jason Hall
d4f75cf453
Merge pull request #1 from imjasonh/copilot/add-dependency-size-report 2025-11-16 01:08:51 -05:00
copilot-swe-agent[bot]
ca9a929442 Return error when __gosymtab section is missing in Mach-O analysis
- Made analyzeSymbolsMachO consistent with analyzeSymbolsPE
- Returns error instead of silently failing with empty report
- Provides clear feedback when symbol table is not found

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 06:01:48 +00:00
Jason Hall
6b1a906c47
Update main.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 00:58:15 -05:00
Jason Hall
274544d8b3
Update integration_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 00:58:08 -05:00
Jason Hall
3d38f3439f
Update main.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 00:57:58 -05:00
Jason Hall
66589aed1c
Update README.md
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 00:57:50 -05:00
Jason Hall
91b43a51b0
Update main.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 00:57:41 -05:00
copilot-swe-agent[bot]
c2a84a5306 Extract duplicated symbol analysis logic into shared function
- Created processSymbolTable() function to handle common symbol analysis
- Updated analyzeSymbols (ELF), analyzeSymbolsMachO, and analyzeSymbolsPE to use shared function
- Reduces code duplication and improves maintainability

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 05:28:35 +00:00
Jason Hall
6692e2f590
Update analyze-binaries.yml
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 00:23:46 -05:00
copilot-swe-agent[bot]
737db55486 Add BuildInfo support, fix .init suffix, and address code review feedback
- Extract module dependencies from BuildInfo and use for attribution
- Remove .init and .init.N suffixes from package names
- Add error checking for file seek operations
- Improve error message for unsupported binary format
- Fix analyzeLineTable to return error for unsupported case
- Add named constants for truncation suffix
- Fix go.mod version to 1.21
- Add comprehensive tests for .init suffix removal and BuildInfo integration

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-11-16 04:58:41 +00:00