functrace

package module
v0.0.0-...-318a19d Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: Apache-2.0 Imports: 0 Imported by: 1

README

functrace

Quick Start

Install gen
$go get github.com/bigwhite/functrace/cmd/gen

And make sure the gen executable file is configured as part of the PATH env variable.

Generate trace entry for your packages

See the demo case: https://github.com/bigwhite/functrace/tree/main/examples/gen-demo

Add trace in batches

You can use the scripts/batch_add_trace.sh to add trace in batches for all go source files in some repo.

for example:

let's add trace in batches for github.com/panjf2000/gnet, the steps is below:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/bigwhite/functrace/main/scripts/batch_add_trace.sh)"

If the access to github.com is very slow in your area, then you can copy scripts/batch_add_trace.sh of functrace to gnet dir and execute bash batch_add_trace.sh.

The command will output:

[gen -w ./ringbuffer/ring_buffer_test.go]
add trace for ./ringbuffer/ring_buffer_test.go ok
[gen -w ./ringbuffer/ring_buffer.go]
add trace for ./ringbuffer/ring_buffer.go ok
... ...
[gen -w ./internal/netpoll/queue/queue.go]
no trace added for ./internal/netpoll/queue/queue.go
[gen -w ./gnet.go]
add trace for ./gnet.go ok
[gen -w ./acceptor_windows.go]
add trace for ./acceptor_windows.go ok

After debugging, you can use 'git checkout .' to recover the origin status of your local workspace.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Trace

func Trace() func()
Example
// go test -tags trace
package main

import (
	"github.com/bigwhite/functrace"
)

func a() {
	defer functrace.Trace()()
	b()
}

func b() {
	defer functrace.Trace()()
	c()
}

func c() {
	defer functrace.Trace()()
	d()
}

func d() {
	defer functrace.Trace()()
}

func main() {
	a()
}
Output:

g[01]:	->github.com/bigwhite/functrace_test.a
g[01]:		->github.com/bigwhite/functrace_test.b
g[01]:			->github.com/bigwhite/functrace_test.c
g[01]:				->github.com/bigwhite/functrace_test.d
g[01]:				<-github.com/bigwhite/functrace_test.d
g[01]:			<-github.com/bigwhite/functrace_test.c
g[01]:		<-github.com/bigwhite/functrace_test.b
g[01]:	<-github.com/bigwhite/functrace_test.a

Types

This section is empty.

Directories

Path Synopsis
cmd
gen
pkg

Jump to

Keyboard shortcuts

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