v8go icon indicating copy to clipboard operation
v8go copied to clipboard

Expose HitCount and HitLineCount to CPUProfileNode

Open mnutt opened this issue 3 years ago • 2 comments

This exposes hitCount and hitLineCount from v8's cpuprofile node. It's useful in order to be able to see relative percentages of time spent in a v8 function and its descendants, although computing total time is left up to the presentation implementation.

Sample implementation:

func printTree(nest string, node *v8.CPUProfileNode) {
	file, name, line, col := node.GetScriptResourceName(), node.GetFunctionName(), node.GetLineNumber(), node.GetColumnNumber()
	selfHits, totalHits := node.GetHitCount(), totalHitCountForNode(node)

	fmt.Printf("[%d/%d hits\t]  %s%s() %s:%d:%d\n", selfHits, totalHits, nest, name, file, line, col)

	count := node.GetChildrenCount()
	if count == 0 {
		return
	}

	nest = fmt.Sprintf("%s  ", nest)

	for i := 0; i < count; i++ {
		printTree(nest, node.GetChild(i))
	}
}

func totalHitCountForNode(node *v8.CPUProfileNode) uint {
	totalHitCount := node.GetHitCount()

	count := node.GetChildrenCount()
	for i := 0; i < count; i++ {
		totalHitCount += totalHitCountForNode(node.GetChild(i))
	}

	return totalHitCount
}

mnutt avatar Feb 10 '22 21:02 mnutt

The changes look good.

  1. Could you update the changelog to reflect these two new functions on nodes?
  2. Are there test assertions in the node suite that could cover these two new functions while also being reliable?

genevieve avatar Mar 09 '22 20:03 genevieve

Codecov Report

Merging #285 (99bdd18) into master (5e91d3d) will decrease coverage by 0.31%. The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #285      +/-   ##
==========================================
- Coverage   95.86%   95.54%   -0.32%     
==========================================
  Files          17       17              
  Lines         580      584       +4     
==========================================
+ Hits          556      558       +2     
- Misses         15       17       +2     
  Partials        9        9              
Impacted Files Coverage Δ
cpuprofilenode.go 77.77% <0.00%> (-22.23%) :arrow_down:
cpuprofiler.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5e91d3d...99bdd18. Read the comment docs.

codecov[bot] avatar Mar 09 '22 20:03 codecov[bot]