Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit 034fd21

Browse files
committed
Add msbuild tracker support
Detecting of tracker presence by TRACKER_ENABLED environ. Move reading of stats.txt and manifests out of main thread to avoid tracking. Using ProcessPoolExecutor to make it trackable.
1 parent 7b70cc1 commit 034fd21

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

clcache/__main__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ def __str__(self):
163163
return repr(self.message)
164164

165165

166+
def isTrackerEnabled():
167+
return 'TRACKER_ENABLED' in os.environ
168+
169+
def untrackable(func):
170+
if not isTrackerEnabled():
171+
return func
172+
173+
if not hasattr(untrackable, "untrackableExecutor"):
174+
setattr(untrackable, "untrackableExecutor", concurrent.futures.ThreadPoolExecutor(max_workers=1))
175+
176+
def executeNotInMainThread(*args, **kwargs):
177+
future = untrackable.untrackableExecutor.submit(func, *args, **kwargs) # pylint: disable=no-member
178+
return future.result()
179+
180+
return executeNotInMainThread
181+
166182
class Manifest:
167183
def __init__(self, entries=None):
168184
if entries is None:
@@ -203,6 +219,7 @@ def setManifest(self, manifestHash, manifest):
203219
jsonobject = {'entries': entries}
204220
json.dump(jsonobject, outFile, sort_keys=True, indent=2)
205221

222+
@untrackable
206223
def getManifest(self, manifestHash):
207224
fileName = self.manifestPath(manifestHash)
208225
if not os.path.exists(fileName):
@@ -741,6 +758,7 @@ def __init__(self, statsFile):
741758
self._stats = None
742759
self.lock = CacheLock.forPath(self._statsFile)
743760

761+
@untrackable
744762
def __enter__(self):
745763
self._stats = PersistentJSONDict(self._statsFile)
746764
for k in Statistics.RESETTABLE_KEYS | Statistics.NON_RESETTABLE_KEYS:
@@ -1645,7 +1663,13 @@ def scheduleJobs(cache: Any, compiler: str, cmdLine: List[str], environment: Any
16451663

16461664
exitCode = 0
16471665
cleanupRequired = False
1648-
with concurrent.futures.ThreadPoolExecutor(max_workers=jobCount(cmdLine)) as executor:
1666+
1667+
if isTrackerEnabled():
1668+
poolExecutor = concurrent.futures.ProcessPoolExecutor
1669+
else:
1670+
poolExecutor = concurrent.futures.ThreadPoolExecutor
1671+
1672+
with poolExecutor(max_workers=min(jobCount(cmdLine), len(objectFiles))) as executor:
16491673
jobs = []
16501674
for (srcFile, srcLanguage), objFile in zip(sourceFiles, objectFiles):
16511675
jobCmdLine = baseCmdLine + [srcLanguage + srcFile]
@@ -1770,6 +1794,7 @@ def ensureArtifactsExist(cache, cachekey, reason, objectFile, compilerResult, ex
17701794

17711795

17721796
if __name__ == '__main__':
1797+
multiprocessing.freeze_support()
17731798
if 'CLCACHE_PROFILE' in os.environ:
17741799
INVOCATION_HASH = getStringHash(','.join(sys.argv))
17751800
cProfile.run('main()', filename='clcache-{}.prof'.format(INVOCATION_HASH))

0 commit comments

Comments
 (0)