diff options
Diffstat (limited to 'internal/flamegraph')
| -rw-r--r-- | internal/flamegraph/iordata.go | 8 | ||||
| -rw-r--r-- | internal/flamegraph/iordatacollector.go | 23 |
2 files changed, 19 insertions, 12 deletions
diff --git a/internal/flamegraph/iordata.go b/internal/flamegraph/iordata.go index db5bad6..61a65a9 100644 --- a/internal/flamegraph/iordata.go +++ b/internal/flamegraph/iordata.go @@ -7,7 +7,6 @@ import ( "io" "ior/internal/event" "ior/internal/file" - "ior/internal/flags" "ior/internal/types" "iter" "os" @@ -98,13 +97,16 @@ func (iod iorData) merge(other iorData) iorData { return iod } -func (iod iorData) serializeToFile() error { +func (iod iorData) serializeToFile(flamegraphName string) error { hostname, err := os.Hostname() if err != nil { panic(err) } + if flamegraphName == "" { + flamegraphName = "default" + } - filename := fmt.Sprintf("%s-%s-%s.ior.zst", hostname, flags.Get().FlamegraphName, + filename := fmt.Sprintf("%s-%s-%s.ior.zst", hostname, flamegraphName, time.Now().Format("2006-01-02_15:04:05")) fmt.Println("Writing", filename) tmpFilename := fmt.Sprintf("%s.tmp", filename) diff --git a/internal/flamegraph/iordatacollector.go b/internal/flamegraph/iordatacollector.go index 948af97..9e92b63 100644 --- a/internal/flamegraph/iordatacollector.go +++ b/internal/flamegraph/iordatacollector.go @@ -4,22 +4,27 @@ import ( "context" "fmt" "ior/internal/event" - "ior/internal/flags" "runtime" "sync" ) type IorDataCollector struct { - flags flags.Flags - Ch chan *event.Pair - Done chan error - workers []worker + flamegraphName string + Ch chan *event.Pair + Done chan error + workers []worker } -func New() IorDataCollector { +func New(flamegraphName ...string) IorDataCollector { + name := "default" + if len(flamegraphName) > 0 && flamegraphName[0] != "" { + name = flamegraphName[0] + } + f := IorDataCollector{ - Ch: make(chan *event.Pair, 4096), - Done: make(chan error, 1), + flamegraphName: name, + Ch: make(chan *event.Pair, 4096), + Done: make(chan error, 1), } numWorkers := runtime.NumCPU() / 4 if numWorkers == 0 { @@ -50,7 +55,7 @@ func (f IorDataCollector) Start(ctx context.Context) { fmt.Println("Worker", i+1, "merged") } } - if err := iod.serializeToFile(); err != nil { + if err := iod.serializeToFile(f.flamegraphName); err != nil { f.Done <- err return } |
