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