Skip to content

Commit 2d3dd72

Browse files
committed
feat(qlsrc): support sort cpu flat/cum time and flamegraph root node cum time
1 parent 948d7fc commit 2d3dd72

5 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cpuprofile
2+
3+
from CPUProfile p, string rootFuncFName
4+
where rootFuncFName = p.flameGraphRootFuncName()
5+
select rootFuncFName, timeInUnit(p.cumTimeOfFunc(rootFuncFName), "ms", 4) as rootCumTime
6+
order by rootCumTime desc
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cpuprofile
2+
3+
from CPUProfile profile, string funcFName
4+
where profile.containsFunc(funcFName)
5+
select funcNamePart(funcFName) as funcName, timeInUnit(profile.cumTimeOfFunc(funcFName), "ms", 4) as cum
6+
order by cum desc
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cpuprofile
2+
3+
from CPUProfile profile, string funcFName
4+
where profile.containsFunc(funcFName)
5+
select funcNamePart(funcFName) as funcName, timeInUnit(profile.flatTimeOfFunc(funcFName), "ms", 4) as flat
6+
order by flat desc

qlsrc/pprof_ext/cpuprofile.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,11 @@ class CPUProfile extends Profile {
108108
| sample.getLocation(sample.locationNum()-1).getLastLine().getFunction().getName() = result
109109
)
110110
}
111+
112+
predicate containsFunc(string funcFullName) {
113+
exists(Sample sample |
114+
sample.containsFunc(funcFullName)
115+
)
116+
}
111117
}
112118

qlsrc/pprof_ext/helper.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ bindingset[pkgPath, funcName]
2222
string funcFullName(string pkgPath, string funcName) {
2323
result = pkgPath+"."+funcName
2424
}
25+
26+
/**
27+
* return funcName part of pkgPath+"."+funcName
28+
*/
29+
bindingset[fullname]
30+
string funcNamePart(string fullname) {
31+
result = fullname.suffix(fullname.splitAt(".", 0).length()+1)
32+
}

0 commit comments

Comments
 (0)