blob: 0c045f423cb702583fd9387f2dcc723ba25c690a [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001#!/usr/bin/env python
2# Copyright 2015 the V8 project authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""
7This script calls the first argument for each of the following arguments in
8parallel. E.g.
9parallel.py "clang --opt" file1 file2
10calls
11clang --opt file1
12clang --opt file2
13
14The output (stdout and stderr) is concatenated sequentially in the form:
15______________ file1
16<output of clang --opt file1>
17______________ finish <exit code of clang --opt file1> ______________
18______________ file2
19<output of clang --opt file2>
20______________ finish <exit code of clang --opt file2> ______________
21"""
22
23import itertools
24import multiprocessing
25import subprocess
26import sys
27
28def invoke(cmdline):
29 try:
30 return (subprocess.check_output(
31 cmdline, shell=True, stderr=subprocess.STDOUT), 0)
32 except subprocess.CalledProcessError as e:
33 return (e.output, e.returncode)
34
35if __name__ == '__main__':
36 assert len(sys.argv) > 2
37 processes = multiprocessing.cpu_count()
38 pool = multiprocessing.Pool(processes=processes)
39 cmdlines = ["%s %s" % (sys.argv[1], filename) for filename in sys.argv[2:]]
40 for filename, result in itertools.izip(
41 sys.argv[2:], pool.imap(invoke, cmdlines)):
42 print "______________ %s" % filename
43 print result[0]
44 print "______________ finish %d ______________" % result[1]