package segment import ( "encoding/json" "math/big" "os" "text/template" "time" ) var visDebuggingEnabled = false type visualizeNode2 struct { T1 time.Time T2 time.Time Depth int HasTrie bool Samples uint64 M int D int Used bool } type vis struct { nodes []*visualizeNode2 } // This is here for debugging func newVis() *vis { return &vis{nodes: []*visualizeNode2{}} } func (v *vis) add(n *streeNode, r *big.Rat, used bool) { if !visDebuggingEnabled { return } v.nodes = append(v.nodes, &visualizeNode2{ T1: n.time.UTC(), T2: n.time.Add(durations[n.depth]).UTC(), Depth: n.depth, HasTrie: n.present, Samples: n.samples, M: int(r.Num().Int64()), D: int(r.Denom().Int64()), Used: used, }) } type TmpltVars struct { Data string } func (v *vis) print(name string) { if !visDebuggingEnabled { return } vizTmplt, _ := template.New("viz").Parse(vizTmplt) jsonBytes, _ := json.MarshalIndent(v.nodes, "", " ") jsonStr := string(jsonBytes) w, _ := os.Create(name) vizTmplt.Execute(w, TmpltVars{Data: jsonStr}) } var vizTmplt = `
`