Bumping manifests a=b2g-bump
[gecko.git] / config / link.py
blob57762803db2b760a6abad1e5554e071190926bbc
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import expandlibs_exec
6 import sys
7 import threading
8 import time
10 from win32 import procmem
12 def measure_vsize_threadfunc(proc, output_file):
13 """
14 Measure the virtual memory usage of |proc| at regular intervals
15 until it exits, then print the maximum value and write it to
16 |output_file|. Also, print something to the console every
17 half an hour to prevent the build job from getting killed when
18 linking a large PGOed binary.
19 """
20 maxvsize = 0
21 idleTime = 0
22 while proc.returncode is None:
23 maxvsize, vsize = procmem.get_vmsize(proc._handle)
24 time.sleep(0.5)
25 idleTime += 0.5
26 if idleTime > 30 * 60:
27 print "Still linking, 30 minutes passed..."
28 sys.stdout.flush()
29 idleTime = 0
30 print "TinderboxPrint: linker max vsize: %d" % maxvsize
31 with open(output_file, "w") as f:
32 f.write("%d\n" % maxvsize)
34 def measure_link_vsize(output_file, args):
35 """
36 Execute |args|, and measure the maximum virtual memory usage of the process,
37 printing it to stdout when finished.
38 """
40 # This needs to be a list in order for the callback to set the
41 # variable properly with python-2's scoping rules.
42 t = [None]
43 def callback(proc):
44 t[0] = threading.Thread(target=measure_vsize_threadfunc,
45 args=(proc, output_file))
46 t[0].start()
47 exitcode = expandlibs_exec.main(args, proc_callback=callback)
48 # Wait for the background thread to finish.
49 t[0].join()
50 return exitcode
52 if __name__ == "__main__":
53 if sys.platform != "win32":
54 print >>sys.stderr, "link.py is only for use on Windows!"
55 sys.exit(1)
56 if len(sys.argv) < 3:
57 print >>sys.stderr, "Usage: link.py <output filename> <commandline>"
58 sys.exit(1)
59 output_file = sys.argv.pop(1)
60 sys.exit(measure_link_vsize(output_file, sys.argv[1:]))