Skip to content

Repository files navigation

debuggefire 🔥

Automatic Go function instrumentation tool that adds timing measurements and debug logging to your code.

Installation

go install github.com/alexshd/debuggefire/cmd/debuggefire@latest

Or build from source:

git clone https://github.com/alexshd/debuggefire.git
cd debuggefire
go build -o debuggefire ./cmd/debuggefire

Quick Start

# Add timing to a file
debuggefire add myfile.go
# Add to entire package recursively
debuggefire add ./pkg --recursive
# Remove instrumentation when done
debuggefire remove ./pkg --recursive

After instrumenting, install the required dependency:

go get github.com/lmittmann/tint

What It Does

Transforms this:

package main
funcCalculate(x, yint) int {
returnx+y
}

Into this:

package main
import (
"log/slog""os""time""github.com/lmittmann/tint"
)
funcinit() {
slog.SetDefault(slog.New(
tint.NewHandler(os.Stderr, &tint.Options{
Level: slog.LevelDebug,
TimeFormat: "15:04:05.0000",
NoColor: false,
AddSource: true,
}),
))
}
funcCalculate(x, yint) int {
__debuggefire_t0__:=time.Now()
deferfunc() {
slog.Debug("Calculate completed",
"duration", time.Since(__debuggefire_t0__))
}()
returnx+y
}

Commands

add

Add timing instrumentation to Go files.

debuggefire add [file or directory] [flags]
Flags:
-r, --recursive Process directories recursively
-b, --backup Create backup files (.bak) (default: true)

remove

Remove timing instrumentation from Go files.

debuggefire remove [file or directory] [flags]
Flags:
-r, --recursive Process directories recursively
-b, --backup Create backup files (.bak) (default: true)

Example

# Add instrumentation
debuggefire add ./mypackage --recursive
# Install required dependency
go get github.com/lmittmann/tint
# Run your code - see colored debug output!
go run main.go

Output example:

09:54:53 DBG myfile.go:19 Calculate completed duration=123.456µs
09:54:53 DBG myfile.go:27 ProcessData completed duration=2.345ms

When done debugging:

# Remove all instrumentation
debuggefire remove ./mypackage --recursive

How It Works

  • Uses Go's AST parser for safe code manipulation
  • Injects timing variable and defer statement at function start
  • Automatically manages imports (time, log/slog, os, tint)
  • Skips init() functions to avoid recursion
  • Creates backups by default (disable with --backup=false)

Requirements

  • Go 1.21+ (uses log/slog)
  • Your project needs github.com/lmittmann/tint after instrumentation

Testing

go test ./...

License

MIT

About

🔥 Automatic Go function instrumentation tool - adds timing measurements and debug logging to your code

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages