tt

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 6 Imported by: 8

README

tt

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

Go Reference Go Report Card


⚡ 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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the logger in tt. It is safe for concurrent use.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger in tt. It is safe for concurrent use.

func T

func T() func()

T allows you to track execution time of a function. It automatically retrieves the caller's function name using runtime. Just add:

defer tt.T()()

at the top of your function.

func Track

func Track(start time.Time, name string)

Track allows you to track timing of a function. Just add:

defer tt.Track(time.Now(), "nameOfFunction")

at the top of your function.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL