diff options
Diffstat (limited to 'internal/flamegraph')
| -rw-r--r-- | internal/flamegraph/collapsed.go | 4 | ||||
| -rw-r--r-- | internal/flamegraph/iordata.go | 69 | ||||
| -rw-r--r-- | internal/flamegraph/worker.go | 6 |
3 files changed, 76 insertions, 3 deletions
diff --git a/internal/flamegraph/collapsed.go b/internal/flamegraph/collapsed.go index 012ea45..57e5ac0 100644 --- a/internal/flamegraph/collapsed.go +++ b/internal/flamegraph/collapsed.go @@ -13,7 +13,7 @@ type counter struct { duration uint64 } -func (c *counter) merge(other counter) { +func (c *counter) add(other counter) { c.count += other.count c.duration += other.duration } @@ -33,7 +33,7 @@ func (c collapsed) merge(other collapsed) (merged int) { } for traceId, cnt := range v { if existingCnt, ok := c[k][traceId]; ok { - existingCnt.merge(cnt) + existingCnt.add(cnt) merged++ c[k][traceId] = existingCnt continue diff --git a/internal/flamegraph/iordata.go b/internal/flamegraph/iordata.go new file mode 100644 index 0000000..bd0b522 --- /dev/null +++ b/internal/flamegraph/iordata.go @@ -0,0 +1,69 @@ +package flamegraph + +import ( + "encoding/json" + "fmt" + "ior/internal/types" + "os" + "time" +) + +const fileSuffix = ".ior" + +// e.g. pathType ¶ traceid ¶ comm ¶ pid ¶ tid ¶ flags ¶ counter +type pathType = string +type traceIdType = types.TraceId +type commType = string +type pidType = uint32 +type tidType = uint32 +type flagsType = int32 + +type pathMap map[pathType]map[traceIdType]map[commType]map[pidType]map[tidType]map[flagsType]counter + +type iorData struct { + paths pathMap +} + +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) + } + if _, ok := id.paths[path][traceId]; !ok { + id.paths[path][traceId] = make(map[commType]map[pidType]map[tidType]map[flagsType]counter) + } + if _, ok := id.paths[path][traceId][comm]; !ok { + id.paths[path][traceId][comm] = make(map[pidType]map[tidType]map[flagsType]counter) + } + if _, ok := id.paths[path][traceId][comm][pid]; !ok { + id.paths[path][traceId][comm][pid] = make(map[tidType]map[flagsType]counter) + } + if _, ok := id.paths[path][traceId][comm][pid][tid]; !ok { + id.paths[path][traceId][comm][pid][tid] = make(map[flagsType]counter) + } + if _, ok := id.paths[path][traceId][comm][pid][tid][flags]; !ok { + id.paths[path][traceId][comm][pid][tid][flags] = cnt + } else { + // iorData.paths[path][traceId][comm][pid][tid][flags] += cnt + } +} + +func (id 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) + file, err := os.Create(filename) + if err != nil { + return err + } + defer file.Close() + + encoder := json.NewEncoder(file) + return encoder.Encode(id.paths) +} diff --git a/internal/flamegraph/worker.go b/internal/flamegraph/worker.go index 7369949..7c8d848 100644 --- a/internal/flamegraph/worker.go +++ b/internal/flamegraph/worker.go @@ -10,11 +10,15 @@ import ( type worker struct { collapsed collapsed + data iorData done chan struct{} } func newWorker() worker { - return worker{collapsed: make(collapsed)} + return worker{ + collapsed: make(collapsed), // TODO: Retire + data: newIorData(), // TODO: Implement fully + } } // Run until ch is closed or has no more events and ctx is done. |
