예제 #1
0
파일: list.go 프로젝트: DanB91/dcpu
// Display detailed instruction view for the given filter.
func list(p *prof.Profile, filemode bool, filter *regexp.Regexp) {
	var blocks prof.BlockList
	var linedata prof.Block
	var count, cost uint64

	if filemode {
		blocks = p.ListFiles()
	} else {
		blocks = p.ListFunctions()
	}

	if len(blocks) == 0 {
		fmt.Println("[*] 0 samples.")
		if !filemode {
			fmt.Println("[*] This most likely means that there are no function")
			fmt.Println("    definitions in the source code. Try using -file mode.")
		}
		return
	}

	for i := range blocks {
		if !filter.MatchString(blocks[i].Label) {
			continue
		}

		start, end := blocks[i].StartAddr, blocks[i].EndAddr
		totalcount, totalcost := blocks[i].Cost()

		file := p.Files[p.Data[start].File]
		startline := blocks[i].StartLine
		endline := blocks[i].EndLine
		source := GetSourceLines(file.Name, startline, endline)

		fmt.Printf("[*] ===> %s\n", blocks[i].Label)
		fmt.Printf("[*] %d sample(s), %d cycle(s)\n\n", totalcount, totalcost)

		if startline == 0 {
			startline++
		}

		for j := range source {
			linedata = getLineData(p.Data, start, end, startline+j)
			count, cost = linedata.Cost()

			if count == 0 {
				fmt.Printf("                    %03d: %s\n", startline+j, source[j])
			} else {
				fmt.Printf("%8d %8d   %03d: %s\n", count, cost, startline+j, source[j])
			}
		}

		fmt.Println()
	}
}
예제 #2
0
파일: top.go 프로젝트: DanB91/dcpu
// Display sorted list of profile data for every function call.
func top(p *prof.Profile, filemode bool, count uint, sort string) {
	var counttotal, costtotal float64
	var blocks prof.BlockList

	if filemode {
		blocks = p.ListFiles()
	} else {
		blocks = p.ListFunctions()
	}

	if len(blocks) == 0 {
		fmt.Println("[*] 0 samples.")
		if !filemode {
			fmt.Println("[*] This most likely means that there are no function")
			fmt.Println("    definitions in the source code. Try using -file mode.")
		}
		return
	}

	for i := range blocks {
		a, b := blocks[i].Cost()
		counttotal += float64(a)
		costtotal += float64(b)
	}

	switch strings.ToLower(sort) {
	case "count":
		prof.BlockListByCount(blocks).Sort()
	case "cost":
		prof.BlockListByCost(blocks).Sort()
	}

	if uint(len(blocks)) > count {
		blocks = blocks[:count]
	}

	fmt.Printf("[*] %.0f sample(s), %.0f cycle(s)\n", counttotal, costtotal)

	for i := range blocks {
		count, cost := blocks[i].Cost()
		scount := fmt.Sprintf("%.2f%%", float64(count)/(counttotal*0.01))
		scost := fmt.Sprintf("%.2f%%", float64(cost)/(costtotal*0.01))

		fmt.Printf(" %8d %7s %8d %7s %s\n",
			count, scount, cost, scost, blocks[i].Label)
	}

	fmt.Println()
}