| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Generic utils.""" | 5 """Generic utils.""" |
| 6 | 6 |
| 7 import codecs | 7 import codecs |
| 8 import cStringIO | 8 import cStringIO |
| 9 import datetime | 9 import datetime |
| 10 import logging | 10 import logging |
| (...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 if keyvals.get(key): | 1134 if keyvals.get(key): |
| 1135 keyvals[key] = UpgradeToHttps(keyvals[key]) | 1135 keyvals[key] = UpgradeToHttps(keyvals[key]) |
| 1136 fix_url('CODE_REVIEW_SERVER') | 1136 fix_url('CODE_REVIEW_SERVER') |
| 1137 fix_url('VIEW_VC') | 1137 fix_url('VIEW_VC') |
| 1138 return keyvals | 1138 return keyvals |
| 1139 | 1139 |
| 1140 | 1140 |
| 1141 def NumLocalCpus(): | 1141 def NumLocalCpus(): |
| 1142 """Returns the number of processors. | 1142 """Returns the number of processors. |
| 1143 | 1143 |
| 1144 Python on OSX 10.6 raises a NotImplementedError exception. | 1144 multiprocessing.cpu_count() is permitted to raise NotImplementedError, and |
| 1145 is known to do this on some Windows systems and OSX 10.6. If we can't get the |
| 1146 CPU count, we will fall back to '1'. |
| 1145 """ | 1147 """ |
| 1148 # Surround the entire thing in try/except; no failure here should stop gclient |
| 1149 # from working. |
| 1146 try: | 1150 try: |
| 1147 import multiprocessing | 1151 # Use multiprocessing to get CPU count. This may raise |
| 1148 return multiprocessing.cpu_count() | 1152 # NotImplementedError. |
| 1149 except: # pylint: disable=W0702 | 1153 try: |
| 1150 # Mac OS 10.6 only | 1154 import multiprocessing |
| 1151 # pylint: disable=E1101 | 1155 return multiprocessing.cpu_count() |
| 1152 return int(os.sysconf('SC_NPROCESSORS_ONLN')) | 1156 except NotImplementedError: # pylint: disable=W0702 |
| 1157 # (UNIX) Query 'os.sysconf'. |
| 1158 # pylint: disable=E1101 |
| 1159 if hasattr(os, 'sysconf') and 'SC_NPROCESSORS_ONLN' in os.sysconf_names: |
| 1160 return int(os.sysconf('SC_NPROCESSORS_ONLN')) |
| 1161 |
| 1162 # (Windows) Query 'NUMBER_OF_PROCESSORS' environment variable. |
| 1163 if 'NUMBER_OF_PROCESSORS' in os.environ: |
| 1164 return int(os.environ['NUMBER_OF_PROCESSORS']) |
| 1165 except Exception as e: |
| 1166 logging.exception("Exception raised while probing CPU count: %s", e) |
| 1167 |
| 1168 logging.debug('Failed to get CPU count. Defaulting to 1.') |
| 1169 return 1 |
| 1153 | 1170 |
| 1154 def DefaultDeltaBaseCacheLimit(): | 1171 def DefaultDeltaBaseCacheLimit(): |
| 1155 """Return a reasonable default for the git config core.deltaBaseCacheLimit. | 1172 """Return a reasonable default for the git config core.deltaBaseCacheLimit. |
| 1156 | 1173 |
| 1157 The primary constraint is the address space of virtual memory. The cache | 1174 The primary constraint is the address space of virtual memory. The cache |
| 1158 size limit is per-thread, and 32-bit systems can hit OOM errors if this | 1175 size limit is per-thread, and 32-bit systems can hit OOM errors if this |
| 1159 parameter is set too high. | 1176 parameter is set too high. |
| 1160 """ | 1177 """ |
| 1161 if platform.architecture()[0].startswith('64'): | 1178 if platform.architecture()[0].startswith('64'): |
| 1162 return '2g' | 1179 return '2g' |
| 1163 else: | 1180 else: |
| 1164 return '512m' | 1181 return '512m' |
| 1165 | 1182 |
| 1166 def DefaultIndexPackConfig(url=''): | 1183 def DefaultIndexPackConfig(url=''): |
| 1167 """Return reasonable default values for configuring git-index-pack. | 1184 """Return reasonable default values for configuring git-index-pack. |
| 1168 | 1185 |
| 1169 Experiments suggest that higher values for pack.threads don't improve | 1186 Experiments suggest that higher values for pack.threads don't improve |
| 1170 performance.""" | 1187 performance.""" |
| 1171 cache_limit = DefaultDeltaBaseCacheLimit() | 1188 cache_limit = DefaultDeltaBaseCacheLimit() |
| 1172 result = ['-c', 'core.deltaBaseCacheLimit=%s' % cache_limit] | 1189 result = ['-c', 'core.deltaBaseCacheLimit=%s' % cache_limit] |
| 1173 if url in THREADED_INDEX_PACK_BLACKLIST: | 1190 if url in THREADED_INDEX_PACK_BLACKLIST: |
| 1174 result.extend(['-c', 'pack.threads=1']) | 1191 result.extend(['-c', 'pack.threads=1']) |
| 1175 return result | 1192 return result |
| OLD | NEW |