@@ -43,14 +43,22 @@ def clean(args):
43
43
44
44
45
45
def 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 (
53
+ "paths" , nargs = "+" , help = "Folder(s) containing input profraw files"
54
+ )
55
+ parser .add_argument ("--sample" , action = "store_true" , help = "Sample profile" )
56
+ opts = parser .parse_args (args )
57
+
58
+ cmd = [opts .profdata , "merge" , "-o" , opts .output ]
59
+ if opts .sample :
60
+ cmd += ["--sample" ]
61
+ for path in opts .paths :
54
62
cmd .extend (findFilesWithExtension (path , "profraw" ))
55
63
subprocess .check_call (cmd )
56
64
return 0
@@ -71,11 +79,16 @@ def merge_fdata(args):
71
79
72
80
def perf (args ):
73
81
parser = argparse .ArgumentParser (
74
- prog = "perf-helper perf" , description = "perf wrapper for BOLT profile collection"
82
+ prog = "perf-helper perf" ,
83
+ description = "perf wrapper for BOLT/CSSPGO profile collection" ,
75
84
)
76
85
parser .add_argument (
77
86
"--lbr" , action = "store_true" , help = "Use perf with branch stacks"
78
87
)
88
+ parser .add_argument ("--call-graph" , action = "store_true" , help = "Collect call graph" )
89
+ parser .add_argument (
90
+ "--event" , help = "PMU event name, defaults to cycles:u" , default = "cycles:u"
91
+ )
79
92
parser .add_argument ("cmd" , nargs = argparse .REMAINDER , help = "" )
80
93
81
94
opts = parser .parse_args (args )
@@ -84,12 +97,14 @@ def perf(args):
84
97
perf_args = [
85
98
"perf" ,
86
99
"record" ,
87
- "--event=cycles:u " ,
100
+ f "--event={ opts . event } " ,
88
101
"--freq=max" ,
89
102
"--output=%d.perf.data" % os .getpid (),
90
103
]
91
104
if opts .lbr :
92
105
perf_args += ["--branch-filter=any,u" ]
106
+ if opts .call_graph :
107
+ perf_args += ["-g" , "--call-graph=fp" ]
93
108
perf_args .extend (cmd )
94
109
95
110
start_time = time .time ()
@@ -125,6 +140,26 @@ def perf2bolt(args):
125
140
return 0
126
141
127
142
143
+ def perf2prof (args ):
144
+ parser = argparse .ArgumentParser (
145
+ prog = "perf-helper perf2prof" ,
146
+ description = "perf to CSSPGO prof conversion wrapper" ,
147
+ )
148
+ parser .add_argument ("profgen" , help = "Path to llvm-profgen binary" )
149
+ parser .add_argument ("binary" , help = "Input binary" )
150
+ parser .add_argument ("paths" , nargs = "+" , help = "Path containing perf.data files" )
151
+ opts = parser .parse_args (args )
152
+
153
+ profgen_args = [opts .profgen , f"--binary={ opts .binary } " ]
154
+ for path in opts .paths :
155
+ for filename in findFilesWithExtension (path , "perf.data" ):
156
+ subprocess .check_call (
157
+ profgen_args
158
+ + [f"--perfdata={ filename } " , f"--output={ filename } .profraw" ]
159
+ )
160
+ return 0
161
+
162
+
128
163
def dtrace (args ):
129
164
parser = argparse .ArgumentParser (
130
165
prog = "perf-helper dtrace" ,
@@ -567,6 +602,7 @@ def genOrderFile(args):
567
602
"merge-fdata" : merge_fdata ,
568
603
"perf" : perf ,
569
604
"perf2bolt" : perf2bolt ,
605
+ "perf2prof" : perf2prof ,
570
606
}
571
607
572
608
0 commit comments