@@ -43,14 +43,21 @@ def clean(args):
4343
4444
4545def merge (args ):
46- if len (args ) < 3 :
47- print (
48- "Usage: %s merge <llvm-profdata> <output> <paths>\n " % __file__
49- + "\t Merges all profraw files from path into output."
50- )
51- return 1
52- cmd = [args [0 ], "merge" , "-o" , args [1 ]]
53- for path in args [2 :]:
46+ parser = argparse .ArgumentParser (
47+ prog = "perf-helper merge" ,
48+ description = "Merges all profraw files from path(s) into output"
49+ )
50+ parser .add_argument ("profdata" , help = "Path to llvm-profdata tool" )
51+ parser .add_argument ("output" , help = "Output filename" )
52+ parser .add_argument ("paths" , nargs = '+' ,
53+ help = "Folder(s) containing input profraw files" )
54+ parser .add_argument ("--sample" , action = "store_true" , help = "Sample profile" )
55+ opts = parser .parse_args (args )
56+
57+ cmd = [opts .profdata , "merge" , "-o" , opts .output ]
58+ if opts .sample :
59+ cmd += ["--sample" ]
60+ for path in opts .paths :
5461 cmd .extend (findFilesWithExtension (path , "profraw" ))
5562 subprocess .check_call (cmd )
5663 return 0
@@ -71,11 +78,19 @@ def merge_fdata(args):
7178
7279def perf (args ):
7380 parser = argparse .ArgumentParser (
74- prog = "perf-helper perf" , description = "perf wrapper for BOLT profile collection"
81+ prog = "perf-helper perf" ,
82+ description = "perf wrapper for BOLT/CSSPGO profile collection"
7583 )
7684 parser .add_argument (
7785 "--lbr" , action = "store_true" , help = "Use perf with branch stacks"
7886 )
87+ parser .add_argument (
88+ "--call-graph" , action = "store_true" , help = "Collect call graph"
89+ )
90+ parser .add_argument (
91+ "--event" , help = "PMU event name, defaults to cycles:u" ,
92+ default = "cycles:u"
93+ )
7994 parser .add_argument ("cmd" , nargs = argparse .REMAINDER , help = "" )
8095
8196 opts = parser .parse_args (args )
@@ -84,12 +99,14 @@ def perf(args):
8499 perf_args = [
85100 "perf" ,
86101 "record" ,
87- "--event=cycles:u " ,
102+ f "--event={ opts . event } " ,
88103 "--freq=max" ,
89104 "--output=%d.perf.data" % os .getpid (),
90105 ]
91106 if opts .lbr :
92107 perf_args += ["--branch-filter=any,u" ]
108+ if opts .call_graph :
109+ perf_args += ["-g" , "--call-graph=fp" ]
93110 perf_args .extend (cmd )
94111
95112 start_time = time .time ()
@@ -125,6 +142,23 @@ def perf2bolt(args):
125142 return 0
126143
127144
145+ def perf2prof (args ):
146+ parser = argparse .ArgumentParser (
147+ prog = "perf-helper perf2prof" ,
148+ description = "perf to CSSPGO prof conversion wrapper" ,
149+ )
150+ parser .add_argument ("profgen" , help = "Path to llvm-profgen binary" )
151+ parser .add_argument ("binary" , help = "Input binary" )
152+ parser .add_argument ("path" , help = "Path containing perf.data files" )
153+ opts = parser .parse_args (args )
154+
155+ profgen_args = [opts .profgen , f"--binary={ opts .binary } " ]
156+ for filename in findFilesWithExtension (opts .path , "perf.data" ):
157+ subprocess .check_call (profgen_args + [f"--perfdata={ filename } " ,
158+ f"--output={ filename } .profraw" ])
159+ return 0
160+
161+
128162def dtrace (args ):
129163 parser = argparse .ArgumentParser (
130164 prog = "perf-helper dtrace" ,
@@ -567,6 +601,7 @@ def genOrderFile(args):
567601 "merge-fdata" : merge_fdata ,
568602 "perf" : perf ,
569603 "perf2bolt" : perf2bolt ,
604+ "perf2prof" : perf2prof ,
570605}
571606
572607
0 commit comments