Bug 767636 - Expose plugin fallback type to extensions. r=josh
[gecko.git] / build / link.py
blob19fbfac7bcfd6f32c252f6c000a41f26374994dd
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 from __future__ import with_statement
6 import os, subprocess, sys, threading, time
7 from win32 import procmem
9 def measure_vsize_threadfunc(proc, output_file):
10 """
11 Measure the virtual memory usage of |proc| at regular intervals
12 until it exits, then print the maximum value and write it to
13 |output_file|.
14 """
15 maxvsize = 0
16 while proc.returncode is None:
17 maxvsize, vsize = procmem.get_vmsize(proc._handle)
18 time.sleep(0.5)
19 print "TinderboxPrint: linker max vsize: %d" % maxvsize
20 with open(output_file, "w") as f:
21 f.write("%d\n" % maxvsize)
23 def measure_link_vsize(output_file, args):
24 """
25 Execute |args|, and measure the maximum virtual memory usage of the process,
26 printing it to stdout when finished.
27 """
28 proc = subprocess.Popen(args)
29 t = threading.Thread(target=measure_vsize_threadfunc,
30 args=(proc, output_file))
31 t.start()
32 # Wait for the linker to finish.
33 exitcode = proc.wait()
34 # ...and then wait for the background thread to finish.
35 t.join()
36 return exitcode
38 if __name__ == "__main__":
39 if sys.platform != "win32":
40 print >>sys.stderr, "link.py is only for use on Windows!"
41 sys.exit(1)
42 if len(sys.argv) < 3:
43 print >>sys.stderr, "Usage: link.py <output filename> <commandline>"
44 sys.exit(1)
45 sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:]))