@@ -43,14 +43,22 @@ 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 (
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 :
5462        cmd .extend (findFilesWithExtension (path , "profraw" ))
5563    subprocess .check_call (cmd )
5664    return  0 
@@ -71,11 +79,16 @@ def merge_fdata(args):
7179
7280def  perf (args ):
7381    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" ,
7584    )
7685    parser .add_argument (
7786        "--lbr" , action = "store_true" , help = "Use perf with branch stacks" 
7887    )
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+     )
7992    parser .add_argument ("cmd" , nargs = argparse .REMAINDER , help = "" )
8093
8194    opts  =  parser .parse_args (args )
@@ -84,12 +97,14 @@ def perf(args):
8497    perf_args  =  [
8598        "perf" ,
8699        "record" ,
87-         "--event=cycles:u " ,
100+         f "--event={ opts . event } 
88101        "--freq=max" ,
89102        "--output=%d.perf.data"  %  os .getpid (),
90103    ]
91104    if  opts .lbr :
92105        perf_args  +=  ["--branch-filter=any,u" ]
106+     if  opts .call_graph :
107+         perf_args  +=  ["-g" , "--call-graph=fp" ]
93108    perf_args .extend (cmd )
94109
95110    start_time  =  time .time ()
@@ -125,6 +140,26 @@ def perf2bolt(args):
125140    return  0 
126141
127142
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 }  ]
159+             )
160+     return  0 
161+ 
162+ 
128163def  dtrace (args ):
129164    parser  =  argparse .ArgumentParser (
130165        prog = "perf-helper dtrace" ,
@@ -567,6 +602,7 @@ def genOrderFile(args):
567602    "merge-fdata" : merge_fdata ,
568603    "perf" : perf ,
569604    "perf2bolt" : perf2bolt ,
605+     "perf2prof" : perf2prof ,
570606}
571607
572608
0 commit comments