OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # This script computs the number of concurrent links we want to run in the build | 5 # This script computs the number of concurrent links we want to run in the build |
6 # as a function of machine spec. It's based on GetDefaultConcurrentLinks in GYP. | 6 # as a function of machine spec. It's based on GetDefaultConcurrentLinks in GYP. |
7 | 7 |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 24 matching lines...) Expand all Loading... |
35 if os.path.exists("/proc/meminfo"): | 35 if os.path.exists("/proc/meminfo"): |
36 with open("/proc/meminfo") as meminfo: | 36 with open("/proc/meminfo") as meminfo: |
37 memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB') | 37 memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB') |
38 for line in meminfo: | 38 for line in meminfo: |
39 match = memtotal_re.match(line) | 39 match = memtotal_re.match(line) |
40 if not match: | 40 if not match: |
41 continue | 41 continue |
42 return float(match.group(1)) * 2**10 | 42 return float(match.group(1)) * 2**10 |
43 elif sys.platform == 'darwin': | 43 elif sys.platform == 'darwin': |
44 try: | 44 try: |
45 avail_bytes = int(subprocess.check_output(['sysctl', '-n', 'hw.memsize'])) | 45 return int(subprocess.check_output(['sysctl', '-n', 'hw.memsize'])) |
46 except Exception: | 46 except Exception: |
47 return 0 | 47 return 0 |
48 # TODO(scottmg): Implement this for other platforms. | 48 # TODO(scottmg): Implement this for other platforms. |
49 return 0 | 49 return 0 |
50 | 50 |
51 | 51 |
52 def _GetDefaultConcurrentLinks(mem_per_link_gb, reserve_mem_gb): | 52 def _GetDefaultConcurrentLinks(mem_per_link_gb, reserve_mem_gb): |
53 # Inherit the legacy environment variable for people that have set it in GYP. | 53 # Inherit the legacy environment variable for people that have set it in GYP. |
54 pool_size = int(os.getenv('GYP_LINK_CONCURRENCY', 0)) | 54 pool_size = int(os.getenv('GYP_LINK_CONCURRENCY', 0)) |
55 if pool_size: | 55 if pool_size: |
(...skipping 12 matching lines...) Expand all Loading... |
68 parser.add_option('--reserve_mem_gb', action="store", type="int", default=0) | 68 parser.add_option('--reserve_mem_gb', action="store", type="int", default=0) |
69 parser.disable_interspersed_args() | 69 parser.disable_interspersed_args() |
70 options, args = parser.parse_args() | 70 options, args = parser.parse_args() |
71 | 71 |
72 print _GetDefaultConcurrentLinks(options.mem_per_link_gb, | 72 print _GetDefaultConcurrentLinks(options.mem_per_link_gb, |
73 options.reserve_mem_gb) | 73 options.reserve_mem_gb) |
74 return 0 | 74 return 0 |
75 | 75 |
76 if __name__ == '__main__': | 76 if __name__ == '__main__': |
77 sys.exit(main()) | 77 sys.exit(main()) |
OLD | NEW |