gotrace

command module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 0 Imported by: 0

README

gotrace

Install

go intall github.com/robertranjan/gotrace@latest

tracing for go programs

gotrace annotates function calls in go source files with log statements on entry and exit.

❯ bin/gotrace help
NAME:
gotrace - trace go src func calls

USAGE:
gotrace [global options] command [command options] [arguments...]

VERSION:
v0.1.0

COMMANDS:
help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
--verbose                        run with verbosity (default: false) [$BUTLER_VERBOSE]
--debug                          run with debug logging (default: false) [$BUTLER_DEBUG]
--versionFlag                    versionFlag (default: false) [$BUTLER_VERSIONFLAG]
--exportedOnly                   exportedOnly (default: false) [$BUTLER_EXPORTEDONLY]
--showPackage                    showPackage (default: false) [$BUTLER_SHOWPACKAGE]
--writeFiles, -w                 writeFiles (default: false) [$BUTLER_WRITEFILES]
--timing                         timing (default: false) [$BUTLER_TIMING]
--showReturn                     showReturn (default: false) [$BUTLER_SHOWRETURN]
--prefix value                   prefix [$BUTLER_PREFIX]
--filterFlag value               filterFlag [$BUTLER_FILTERFLAG]
--excludeFlag value              excludeFlag [$BUTLER_EXCLUDEFLAG]
--formatLength value             formatLength (default: 0) [$BUTLER_FORMATLENGTH]
--files value [ --files value ]  go source files [$BUTLER_GOFILES]
--help, -h                       show help
--version, -v                    print the version

Example

# gotrace operates directly on go source files.
# Insert gotrace logging statements into all *.go files in the current directory
# Make sure all files are saved in version control, as this rewrites them in-place!

$ gotrace -w -returns ./*.go

generate trace

Go to a project with .go src files

  • Git commit all changes and make sure git diff --exit-code exits with 0

  • run below command to annotate

      gotrace $(find . -type f -name *.go) --files file1,file2,...,fileN
      gotrace $(fd -e go)
    

    you may need to add -w to write to the files

      bin/gotrace --debug -w --files $(fd -e go| tr '\n' ',')
    

cleanup trace

As all the files are already checked in and annotation can be done quickly on-demand, you may simple git co . to clean up the annotations.

Documentation

Overview

Command gotrace annotates function entry and exit points to provide strace-like tracing of go programs.

usage: gotrace [flags] [path ...]
-exclude string
		exclude any matching functions, takes precedence over filter
-exported
		only annotate exported functions
-filter string
		only annotate functions matching the regular expression (default ".")
-package
		show package name prefix on function calls
-prefix string
		log prefix (default "\t")
-returns
		show function return
-w	re-write files in place

Directories

Path Synopsis
cmd
Custom logger for gotrace
Custom logger for gotrace

Jump to

Keyboard shortcuts

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