Skip to content

Commit 7b78671

Browse files
committed
Added cf-profile.py script for processing profiling output
Changelog: Title Signed-off-by: Victor Moene <[email protected]>
1 parent acd5705 commit 7b78671

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

contrib/cf-profile/cf-profile.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from argparse import ArgumentParser
2+
import sys
3+
import json
4+
import re
5+
6+
def parse_args():
7+
parser = ArgumentParser()
8+
9+
parser.add_argument("--top", type=int, default=10)
10+
parser.add_argument("--bundles", action="store_true")
11+
parser.add_argument("--promises", action="store_true")
12+
parser.add_argument("--functions", action="store_true")
13+
14+
return parser.parse_args()
15+
16+
def profile(data, args):
17+
18+
events = sorted([event for event in data["events"]], key=lambda x: x["elapsed"], reverse=True)
19+
20+
filter = []
21+
22+
if args.bundles:
23+
filter.append("bundle")
24+
25+
if args.promises:
26+
filter.append("promise")
27+
28+
if args.functions:
29+
filter.append("function")
30+
31+
if filter:
32+
events = [event for event in events if event["type"] in filter]
33+
34+
print("%-60s %-90s %20s" % ("Component", "Location", "Time"))
35+
for t in events[:args.top]:
36+
37+
label = "%s %s" % (t["type"], t["name"])
38+
location = "%s:%s" % (t["filename"], t["offset"]["line"])
39+
time_ms = "%.2f ms" % (float(t["elapsed"]) / 1e6)
40+
41+
print("%-60s %-90s %20s" % (label, location, time_ms))
42+
43+
def main():
44+
args = parse_args()
45+
m = re.search(r"\{[.\s\S]*\}", sys.stdin.read())
46+
data = json.loads(m.group(0))
47+
48+
profile(data, args)
49+
50+
51+
if __name__ == "__main__":
52+
main()

0 commit comments

Comments
 (0)