Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Go module #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,12 @@ burn is a CLI tool to convert performance profiles (perf_events, pprof, etc) to

## Getting Started

Just download _burn_ from github using `go get` or the _pre-build_ binary and use it!

### From go

Make sure you have [golang](https://golang.org/) installed and `GOPATH` correctly set.

```bash
$ go get github.com/spiermar/burn
$ burn $GOPATH/src/github.com/spiermar/burn/examples/out.perf
```

### From binary

Binaries are being provided for both `linux` and `darwin`, in `amd64` arch.

#### darwin/amd64

```bash
$ curl -L "https://dl.bintray.com/mspier/binaries/burn/1.0.1/darwin/amd64/burn" -o burn
$ chmod +x burn
$ ./burn <input_file>
```

#### linux/amd64
Make sure you have [golang](https://go.dev) installed.

```bash
$ curl -L "https://dl.bintray.com/mspier/binaries/burn/1.0.1/linux/amd64/burn" -o burn
$ chmod +x burn
$ ./burn <input_file>
$ go install github.com/spiermar/burn@latest
$ curl https://raw.githubusercontent.com/spiermar/burn/master/examples/out.perf >out.perf
$ burn convert out.perf
```

## Options
Expand Down Expand Up @@ -74,11 +51,11 @@ Input and output examples can be found in the [examples](/examples) directory.

## Building from source

Make sure you have [golang](https://golang.org/) installed and `GOPATH` correctly set.
Make sure you have [golang](https://go.dev) installed.

```bash
$ go get github.com/spiermar/burn
$ cd $GOPATH/src/github.com/spiermar/burn
$ git clone https://github.com/spiermar/burn
$ cd burn
$ go build
$ ./burn examples/out.perf
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Examples:
if input == "folded" {
profile = convert.ParseFolded(file)
} else if input == "perf" {
profile = convert.ParsePerf(file)
profile = convert.ParsePerf(cmd.Context(), file)
} else {
panic("input type not supported: " + input)
}
Expand Down
25 changes: 13 additions & 12 deletions convert/perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package convert

import (
"bufio"
"context"
"io"
"regexp"

Expand All @@ -24,7 +25,7 @@ import (
)

// ParsePerf parses a perf_events file format.
func ParsePerf(r io.Reader) types.Profile {
func ParsePerf(ctx context.Context, r io.Reader) types.Profile {
rootNode := types.Node{Name: "root", Value: 0, Children: make(map[string]*types.Node)}
profile := types.Profile{RootNode: rootNode, Stack: []string{}}

Expand All @@ -43,13 +44,13 @@ func ParsePerf(r io.Reader) types.Profile {
{Name: "finish", Src: []string{"closed"}, Dst: "end"},
},
fsm.Callbacks{
"enter_event": func(e *fsm.Event) {
"enter_event": func(_ context.Context, e *fsm.Event) {

},
"enter_open": func(e *fsm.Event) {
"enter_open": func(_ context.Context, e *fsm.Event) {

},
"enter_closed": func(e *fsm.Event) {
"enter_closed": func(_ context.Context, e *fsm.Event) {

},
},
Expand All @@ -67,12 +68,12 @@ func ParsePerf(r io.Reader) types.Profile {
switch current {
case "start":
if reCommentLine.MatchString(line) {
err := state.Event("read_comment")
err := state.Event(ctx, "read_comment")
if err != nil {
panic(err)
}
} else if matches := reEventRecordStartLine.FindStringSubmatch(line); matches != nil {
err := state.Event("open_stack")
err := state.Event(ctx, "open_stack")
if err != nil {
panic(err)
}
Expand All @@ -85,7 +86,7 @@ func ParsePerf(r io.Reader) types.Profile {
if reCommentLine.MatchString(line) {
// do nothing
} else if matches := reEventRecordStartLine.FindStringSubmatch(line); matches != nil {
err := state.Event("open_stack")
err := state.Event(ctx, "open_stack")
if err != nil {
panic(err)
}
Expand All @@ -96,13 +97,13 @@ func ParsePerf(r io.Reader) types.Profile {
}
case "event":
if matches := reStackLine.FindStringSubmatch(line); matches != nil {
err := state.Event("read_stack")
err := state.Event(ctx, "read_stack")
if err != nil {
panic(err)
}
profile.AddFrame(matches[2])
} else if reEndStackLine.MatchString(line) { // empty stack
err := state.Event("close_stack")
err := state.Event(ctx, "close_stack")
if err != nil {
panic(err)
}
Expand All @@ -114,7 +115,7 @@ func ParsePerf(r io.Reader) types.Profile {
if matches := reStackLine.FindStringSubmatch(line); matches != nil {
profile.AddFrame(matches[2])
} else if reEndStackLine.MatchString(line) {
err := state.Event("close_stack")
err := state.Event(ctx, "close_stack")
if err != nil {
panic(err)
}
Expand All @@ -124,14 +125,14 @@ func ParsePerf(r io.Reader) types.Profile {
}
case "closed":
if matches := reEventRecordStartLine.FindStringSubmatch(line); matches != nil {
err := state.Event("open_stack")
err := state.Event(ctx, "open_stack")
if err != nil {
panic(err)
}
profile.OpenStack()
profile.AddFrame(matches[1])
} else {
err := state.Event("finish")
err := state.Event(ctx, "finish")
if err != nil {
panic(err)
}
Expand Down
28 changes: 28 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module github.com/spiermar/burn

go 1.20

require (
github.com/looplab/fsm v1.0.1
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
)

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading