diff options
Diffstat (limited to 'internal/flamegraph')
| -rw-r--r-- | internal/flamegraph/counter.go | 1 | ||||
| -rw-r--r-- | internal/flamegraph/iordata.go | 42 | ||||
| -rw-r--r-- | internal/flamegraph/worker.go | 2 |
3 files changed, 32 insertions, 13 deletions
diff --git a/internal/flamegraph/counter.go b/internal/flamegraph/counter.go index 4a63f50..98ac035 100644 --- a/internal/flamegraph/counter.go +++ b/internal/flamegraph/counter.go @@ -4,6 +4,7 @@ type counter struct { count uint64 duration uint64 durationToPrev uint64 + // bytes uint64 TODO implement } func (c counter) add(other counter) counter { diff --git a/internal/flamegraph/iordata.go b/internal/flamegraph/iordata.go index 80571d9..c167f22 100644 --- a/internal/flamegraph/iordata.go +++ b/internal/flamegraph/iordata.go @@ -4,14 +4,14 @@ import ( "encoding/json" "fmt" "ior/internal/event" + "ior/internal/flags" "ior/internal/types" "os" "time" -) -const fileSuffix = ".ior" + "github.com/DataDog/zstd" +) -// e.g. pathType ¶ traceid ¶ comm ¶ pid ¶ tid ¶ flags ¶ counter type pathType = string type traceIdType = types.TraceId type commType = string @@ -19,14 +19,24 @@ type pidType = uint32 type tidType = uint32 type flagsType = string type pathMap map[pathType]map[traceIdType]map[commType]map[pidType]map[tidType]map[flagsType]counter -type iorData struct{ paths pathMap } + +type iorData struct { + flags flags.Flags + paths pathMap +} // TODO: Flag to enable iorData // TODO: Name flag for iorData (outfile format: hostname-name-timestamp.ior.zst) // TODO: Output path for iorData flag // TODO: Add helper to convert .ior data file to collapsed format -func newIorData() iorData { return iorData{paths: make(pathMap)} } +func newIorData(flags flags.Flags) iorData { + return iorData{ + flags: flags, + paths: make(pathMap), + } +} +// TODO: Unit test func (iod iorData) add(ev *event.Pair) { // type Pair struct { // EnterEv, ExitEv Event @@ -38,15 +48,16 @@ func (iod iorData) add(ev *event.Pair) { // PrevPair *Pair // durationToPrev uint64 // } - // TODO: Add duration to prev to counter cnt := counter{ - count: 1, - duration: ev.Duration, + count: 1, + duration: ev.Duration, + durationToPrev: ev.DurationToPrev, } iod.addPath(ev.File.Name(), ev.EnterEv.GetTraceId(), ev.Comm, ev.EnterEv.GetPid(), ev.EnterEv.GetTid(), ev.File.FlagsString(), cnt) } +// TODO: Unit test func (iod iorData) addPath(path pathType, traceId traceIdType, comm commType, pid pidType, tid tidType, flags flagsType, addCnt counter) { @@ -84,18 +95,25 @@ func (iod iorData) addPath(path pathType, traceId traceIdType, comm commType, } func (iod iorData) commit() error { - currentTime := time.Now().Format("2006-01-02_15:04:05") hostname, err := os.Hostname() if err != nil { panic(err) } - filename := fmt.Sprintf("%s-%s.%s", hostname, currentTime, fileSuffix) + + filename := fmt.Sprintf("%s-%s-%s.ior.zst", hostname, iod.flags.FlamegraphName, + time.Now().Format("2006-01-02_15:04:05")) file, err := os.Create(filename) if err != nil { return err } defer file.Close() - encoder := json.NewEncoder(file) - return encoder.Encode(iod.paths) + encoder, err := zstd.NewWriter(file) + if err != nil { + return err + } + defer encoder.Close() + + jsonEncoder := json.NewEncoder(encoder) + return jsonEncoder.Encode(iod.paths) } diff --git a/internal/flamegraph/worker.go b/internal/flamegraph/worker.go index 6c2b9cd..e47329e 100644 --- a/internal/flamegraph/worker.go +++ b/internal/flamegraph/worker.go @@ -17,7 +17,7 @@ type worker struct { func newWorker() worker { return worker{ collapsed: make(collapsed), // COLLAPSED: Retire ocne newIorData implemented - iod: newIorData(), + iod: newIorData(), // TODO: make flags global, so i don't have to pass them through the whole code base } } |
