diff options
| author | Paul Buetow <paul@buetow.org> | 2025-03-29 11:25:27 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-03-29 11:25:27 +0200 |
| commit | 8a34be1f4fffca90d74e2092c7bc5a6af02392c4 (patch) | |
| tree | f003dc1b8d95a31bf8d01c786e98a5a622ac43cd /internal/flamegraph/iordata.go | |
| parent | 5f1b3be8ac4013ac7cf5041de339317defeb75ce (diff) | |
fix
Diffstat (limited to 'internal/flamegraph/iordata.go')
| -rw-r--r-- | internal/flamegraph/iordata.go | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/internal/flamegraph/iordata.go b/internal/flamegraph/iordata.go index 26e5749..80571d9 100644 --- a/internal/flamegraph/iordata.go +++ b/internal/flamegraph/iordata.go @@ -3,6 +3,7 @@ package flamegraph import ( "encoding/json" "fmt" + "ior/internal/event" "ior/internal/types" "os" "time" @@ -16,39 +17,73 @@ type traceIdType = types.TraceId type commType = string type pidType = uint32 type tidType = uint32 -type flagsType = int32 +type flagsType = string type pathMap map[pathType]map[traceIdType]map[commType]map[pidType]map[tidType]map[flagsType]counter type iorData struct{ paths pathMap } -# TODO: Flag to enable iorData -# TODO: Name flag for iorData -# TODO: Output path for iorData flag +// 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 (id iorData) addPath(path pathType, traceId traceIdType, comm commType, pid pidType, tid tidType, flags flagsType, cnt counter) { - if _, ok := id.paths[path]; !ok { - id.paths[path] = make(map[traceIdType]map[commType]map[pidType]map[tidType]map[flagsType]counter) +func (iod iorData) add(ev *event.Pair) { + // type Pair struct { + // EnterEv, ExitEv Event + // File file.File + // Comm string + // Duration uint64 + + // // To calculate the time difference from the previoud event. + // PrevPair *Pair + // durationToPrev uint64 + // } + // TODO: Add duration to prev to counter + cnt := counter{ + count: 1, + duration: ev.Duration, + } + iod.addPath(ev.File.Name(), ev.EnterEv.GetTraceId(), ev.Comm, + ev.EnterEv.GetPid(), ev.EnterEv.GetTid(), ev.File.FlagsString(), cnt) +} + +func (iod iorData) addPath(path pathType, traceId traceIdType, comm commType, + pid pidType, tid tidType, flags flagsType, addCnt counter) { + + pathMap, ok := iod.paths[path] + if !ok { + pathMap = make(map[traceIdType]map[commType]map[pidType]map[tidType]map[flagsType]counter) + iod.paths[path] = pathMap } - if _, ok := id.paths[path][traceId]; !ok { - id.paths[path][traceId] = make(map[commType]map[pidType]map[tidType]map[flagsType]counter) + traceIdMap, ok := iod.paths[path][traceId] + if !ok { + traceIdMap = make(map[commType]map[pidType]map[tidType]map[flagsType]counter) + iod.paths[path][traceId] = traceIdMap } - if _, ok := id.paths[path][traceId][comm]; !ok { - id.paths[path][traceId][comm] = make(map[pidType]map[tidType]map[flagsType]counter) + commMap, ok := iod.paths[path][traceId][comm] + if !ok { + commMap = make(map[pidType]map[tidType]map[flagsType]counter) + iod.paths[path][traceId][comm] = commMap } - if _, ok := id.paths[path][traceId][comm][pid]; !ok { - id.paths[path][traceId][comm][pid] = make(map[tidType]map[flagsType]counter) + pidMap, ok := iod.paths[path][traceId][comm][pid] + if !ok { + pidMap = make(map[tidType]map[flagsType]counter) + iod.paths[path][traceId][comm][pid] = pidMap } - if _, ok := id.paths[path][traceId][comm][pid][tid]; !ok { - id.paths[path][traceId][comm][pid][tid] = make(map[flagsType]counter) + tidMap, ok := iod.paths[path][traceId][comm][pid][tid] + if !ok { + tidMap = make(map[flagsType]counter) + iod.paths[path][traceId][comm][pid][tid] = tidMap } - if _, ok := id.paths[path][traceId][comm][pid][tid][flags]; !ok { - id.paths[path][traceId][comm][pid][tid][flags] = cnt + cnt, ok := iod.paths[path][traceId][comm][pid][tid][flags] + if !ok { + iod.paths[path][traceId][comm][pid][tid][flags] = addCnt } else { - // iorData.paths[path][traceId][comm][pid][tid][flags] += cnt + iod.paths[path][traceId][comm][pid][tid][flags] = cnt.add(addCnt) } } -func (id iorData) commit() error { +func (iod iorData) commit() error { currentTime := time.Now().Format("2006-01-02_15:04:05") hostname, err := os.Hostname() if err != nil { @@ -62,5 +97,5 @@ func (id iorData) commit() error { defer file.Close() encoder := json.NewEncoder(file) - return encoder.Encode(id.paths) + return encoder.Encode(iod.paths) } |
