22import orjson
33import argparse
44import sys
5+ import pathlib
6+ from preciceprofiling .perfetto import open_in_perfetto
57
68
79def makeTraceParser (add_help : bool = True ):
@@ -15,7 +17,17 @@ def makeTraceParser(add_help: bool = True):
1517 help = "The profiling file to process" ,
1618 )
1719 trace .add_argument (
18- "-o" , "--output" , default = "trace.json" , help = "The resulting trace file"
20+ "-o" ,
21+ "--output" ,
22+ default = "trace.json" ,
23+ type = pathlib .Path ,
24+ help = "The resulting trace file" ,
25+ )
26+ trace .add_argument (
27+ "-w" ,
28+ "--web" ,
29+ action = "store_true" ,
30+ help = "Open resulting trace in ui.perfetto.dev" ,
1931 )
2032 trace .add_argument (
2133 "-l" , "--limit" , type = int , metavar = "n" , help = "Select the first n ranks"
@@ -27,10 +39,10 @@ def makeTraceParser(add_help: bool = True):
2739
2840
2941def runTrace (ns ):
30- return traceCommand (ns .profilingfile , ns .output , ns .rank , ns .limit )
42+ return traceCommand (ns .profilingfile , ns .output , ns .rank , ns .limit , ns . web )
3143
3244
33- def traceCommand (profilingfile , outfile , rankfilter , limit ):
45+ def traceCommand (profilingfile , outfile , rankfilter , limit , web ):
3446 run = Run (profilingfile )
3547 selection = (
3648 set ()
@@ -39,8 +51,10 @@ def traceCommand(profilingfile, outfile, rankfilter, limit):
3951 )
4052 traces = run .toTrace (selection )
4153 print (f"Writing to { outfile } " )
42- with open (outfile , "wb" ) as outfile :
43- outfile .write (orjson .dumps (traces ))
54+ outfile .write_bytes (orjson .dumps (traces ))
55+
56+ if web :
57+ open_in_perfetto (outfile )
4458 return 0
4559
4660
0 commit comments