tt
A simple, thread-safe execution time tracker in Go in ~50 lines of code.

⚡ Features
- Zero Friction: One line instrumentation via
defer tt.T()().
- Automatic Function Name Detection: Leverages
runtime.Caller to infer caller name automatically.
- Thread-Safe: Fully safe for concurrent calls and log configuration updates.
- Configurable Output: Direct logs to any
io.Writer via tt.SetOutput(w) or adjust log flags with tt.SetFlags(flag).
🚀 Installation
go get github.com/chneau/tt
💡 Usage
Simply add defer tt.T()() at the top of your function:
package main
import (
"time"
"github.com/chneau/tt"
)
func process() {
defer tt.T()() // Automatically prints function name and duration upon return
time.Sleep(50 * time.Millisecond)
}
func customNamed() {
defer tt.Track(time.Now(), "myCustomOperation")
time.Sleep(25 * time.Millisecond)
}
func main() {
process()
customNamed()
}
Example Output
[TRACK] 2026/09/04 13:36:00 <[main.process]> 50.123456ms
[TRACK] 2026/09/04 13:36:00 <[myCustomOperation]> 25.045612ms
🛠️ Development Commands
# Run tests with race detector and coverage
go test -v -race -cover ./...
# Run benchmarks
go test -benchmem -bench=. ./...
# Modernize codebase
modernize ./...
# Run linter
golangci-lint run ./...
📄 License
MIT