1#===- perf-helper.py - Clang Python Bindings -----------------*- python -*--===# 2# 3# The LLVM Compiler Infrastructure 4# 5# This file is distributed under the University of Illinois Open Source 6# License. See LICENSE.TXT for details. 7# 8#===------------------------------------------------------------------------===# 9 10import sys 11import os 12import subprocess 13 14def findProfrawFiles(path): 15 profraw_files = [] 16 for root, dirs, files in os.walk(path): 17 for filename in files: 18 if filename.endswith(".profraw"): 19 profraw_files.append(os.path.join(root, filename)) 20 return profraw_files 21 22def clean(args): 23 if len(args) != 1: 24 print 'Usage: %s clean <path>\n\tRemoves all *.profraw files from <path>.' % __file__ 25 return 1 26 for profraw in findProfrawFiles(args[0]): 27 os.remove(profraw) 28 return 0 29 30def merge(args): 31 if len(args) != 3: 32 print 'Usage: %s clean <llvm-profdata> <output> <path>\n\tMerges all profraw files from path into output.' % __file__ 33 return 1 34 cmd = [args[0], 'merge', '-o', args[1]] 35 cmd.extend(findProfrawFiles(args[2])) 36 subprocess.check_call(cmd) 37 return 0 38 39commands = {'clean' : clean, 'merge' : merge} 40 41def main(): 42 f = commands[sys.argv[1]] 43 sys.exit(f(sys.argv[2:])) 44 45if __name__ == '__main__': 46 main() 47