MCPcopy Create free account
hub / github.com/PolyhedraZK/ExpanderCompilerCollection / ShowProfiling

Function ShowProfiling

ecgo/utils/profiling.go:15–71  ·  view source on GitHub ↗
(varSourceInfo []SourceInfo, varCost []int)

Source from the content-addressed store, hash-verified

13}
14
15func ShowProfiling(varSourceInfo []SourceInfo, varCost []int) {
16 fileCost := make(map[string]map[int]int)
17 for i := 0; i < len(varSourceInfo) && i < len(varCost); i++ {
18 if fileCost[varSourceInfo[i].File] == nil {
19 fileCost[varSourceInfo[i].File] = make(map[int]int)
20 }
21 fileCost[varSourceInfo[i].File][varSourceInfo[i].Line] += varCost[i]
22 }
23 files := []string{}
24 for file := range fileCost {
25 files = append(files, file)
26 }
27 sort.Strings(files)
28
29 for _, file := range files {
30 if file == "finalize" || file == "input" || file == "one" {
31 continue
32 }
33 totalCost := 0
34 lines := []int{}
35 for line, cost := range fileCost[file] {
36 if cost != 0 {
37 lines = append(lines, line)
38 }
39 totalCost += cost
40 }
41 sort.Ints(lines)
42 fmt.Printf("File: %s | Total Cost: %d\n", file, totalCost)
43 content, err := os.ReadFile(file)
44 if err != nil {
45 fmt.Printf("Can't read file content\n\n")
46 continue
47 }
48 fileLines := strings.Split(string(content), "\n")
49
50 fmt.Printf("%7s | Line | Code\n", "Cost")
51 lastLine := 0
52 for _, line := range lines {
53 for i := line - 2; i <= line+2; i++ {
54 if lastLine >= i {
55 continue
56 }
57 if i-lastLine > 1 {
58 fmt.Printf("%7s | %4s | ...\n", "", "")
59 }
60 lastLine = i
61 cost := fileCost[file][i]
62 if cost != 0 {
63 fmt.Printf("%7d | %4d | %s\n", cost, i, fileLines[i-1])
64 } else {
65 fmt.Printf("%7s | %4d | %s\n", "", i, fileLines[i-1])
66 }
67 }
68 }
69 fmt.Println()
70 }
71}

Callers

nothing calls this directly

Calls 1

PrintlnMethod · 0.80

Tested by

no test coverage detected