func doSims(cmd string, args []string) { ids, err := query.SimIds(db) fatalif(err) for _, id := range ids { info, err := query.SimStat(db, id) fatalif(err) fmt.Println(info) } }
func doTaint(cmd string, args []string) { fs := flag.NewFlagSet(cmd, flag.ExitOnError) fs.Usage = func() { log.Printf("Usage: %v", cmd) log.Printf("%v\n", cmds.Help(cmd)) fs.PrintDefaults() } t := fs.Int("t", -1, "time step for which to print taint") res := fs.Int("res", -1, "resource ID of object to track") fs.Parse(args) initdb() if *t == -1 || *res == -1 { log.Fatalf("'-t' and '-res' flags are both required and cannot be negative") } roots := taint.TreeFromDb(db, simid) var base *taint.Node visited := taint.Visited{} for _, root := range roots { if base = root.Locate(visited, *res); base != nil { break } } if base == nil { log.Fatalf("couldn't find resource id %v in graph", *res) } si, err := query.SimStat(db, simid) fatalif(err) taints := base.Taint(si.Duration) // print graph dot file byproto := false t1, t2 := 0, -1 arcs, err := query.FlowGraph(db, simid, t1, t2, byproto) fatalif(err) fmt.Println("digraph ResourceFlows {") fmt.Println(" overlap = false;") fmt.Println(" nodesep=1.0;") fmt.Println(" edge [fontsize=9];") for _, arc := range arcs { var srctaint taint.TaintVal if ts := taints[arc.SrcId]; *t < len(ts) { srctaint = ts[*t] } else if len(ts) > 0 { srctaint = ts[len(ts)-1] } var dsttaint taint.TaintVal if ts := taints[arc.DstId]; *t < len(ts) { dsttaint = ts[*t] } else if len(ts) > 0 { dsttaint = ts[len(ts)-1] } srccolor := byte(255 * (1 - math.Pow(srctaint.Taint*srctaint.Quantity/base.Quantity, 1.0/5))) dstcolor := byte(255 * (1 - math.Pow(dsttaint.Taint*dsttaint.Quantity/base.Quantity, 1.0/5))) srcname := fmt.Sprintf("%v %v\\n(%.3e kg of %.4f taint)", arc.SrcProto, arc.SrcId, srctaint.Quantity, srctaint.Taint) dstname := fmt.Sprintf("%v %v\\n(%.3e kg of %.4f taint)", arc.DstProto, arc.DstId, dsttaint.Quantity, dsttaint.Taint) fmt.Printf(" \"%v\" [style=filled, fillcolor=\"#FF%.2X%.2X\"];\n", srcname, srccolor, srccolor) fmt.Printf(" \"%v\" [style=filled, fillcolor=\"#FF%.2X%.2X\"];\n", dstname, dstcolor, dstcolor) fmt.Printf(" \"%v\" -> \"%v\" [label=\"%v\"];\n", srcname, dstname, arc.Commod) } fmt.Println("}") }