summaryrefslogtreecommitdiffstats
path: root/clang/utils/perf-training/perf-helper.py
blob: 448801133e0a0650264d838dd360f506497a4d5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#===- perf-helper.py - Clang Python Bindings -----------------*- python -*--===#
#
#                     The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#

import sys
import os
import subprocess

def findProfrawFiles(path):
  profraw_files = []
  for root, dirs, files in os.walk(path): 
    for filename in files:
      if filename.endswith(".profraw"):
        profraw_files.append(os.path.join(root, filename))
  return profraw_files

def clean(args):
  if len(args) != 1:
    print 'Usage: %s clean <path>\n\tRemoves all *.profraw files from <path>.' % __file__
    return 1
  for profraw in findProfrawFiles(args[0]):
    os.remove(profraw)
  return 0

def merge(args):
  if len(args) != 3:
    print 'Usage: %s clean <llvm-profdata> <output> <path>\n\tMerges all profraw files from path into output.' % __file__
    return 1
  cmd = [args[0], 'merge', '-o', args[1]]
  cmd.extend(findProfrawFiles(args[2]))
  subprocess.check_call(cmd)
  return 0

commands = {'clean' : clean, 'merge' : merge}

def main():
  f = commands[sys.argv[1]]
  sys.exit(f(sys.argv[2:]))

if __name__ == '__main__':
  main()
OpenPOWER on IntegriCloud