v8go
v8go copied to clipboard
Expose HitCount and HitLineCount to CPUProfileNode
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
}
The changes look good.
- Could you update the changelog to reflect these two new functions on nodes?
- Are there test assertions in the node suite that could cover these two new functions while also being reliable?
Codecov Report
Merging #285 (99bdd18) into master (5e91d3d) will decrease coverage by
0.31%
. The diff coverage is50.00%
.
@@ 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.