diff options
| author | Paul Buetow <paul@buetow.org> | 2025-03-28 23:01:25 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-03-28 23:01:25 +0200 |
| commit | 525e38ae59ce7a0d3be49ecba94df678f1def409 (patch) | |
| tree | 0e8011f99d52d1d24a2ebeeb8d17237887861212 /internal/flamegraph/iordata.go | |
| parent | a9b56186f32b4a1899543c8cddad400390d795c4 (diff) | |
initial iordata implementation
Diffstat (limited to 'internal/flamegraph/iordata.go')
| -rw-r--r-- | internal/flamegraph/iordata.go | 69 |
1 files changed, 69 insertions, 0 deletions
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) +} |
