|
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/. |
|
4 |
|
5 from __future__ import with_statement |
|
6 import os, subprocess, sys, threading, time |
|
7 from win32 import procmem |
|
8 |
|
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|. Also, print something to the console every |
|
14 half an hour to prevent the build job from getting killed when |
|
15 linking a large PGOed binary. |
|
16 """ |
|
17 maxvsize = 0 |
|
18 idleTime = 0 |
|
19 while proc.returncode is None: |
|
20 maxvsize, vsize = procmem.get_vmsize(proc._handle) |
|
21 time.sleep(0.5) |
|
22 idleTime += 0.5 |
|
23 if idleTime > 30 * 60: |
|
24 print "Still linking, 30 minutes passed..." |
|
25 sys.stdout.flush() |
|
26 idleTime = 0 |
|
27 print "TinderboxPrint: linker max vsize: %d" % maxvsize |
|
28 with open(output_file, "w") as f: |
|
29 f.write("%d\n" % maxvsize) |
|
30 |
|
31 def measure_link_vsize(output_file, args): |
|
32 """ |
|
33 Execute |args|, and measure the maximum virtual memory usage of the process, |
|
34 printing it to stdout when finished. |
|
35 """ |
|
36 proc = subprocess.Popen(args) |
|
37 t = threading.Thread(target=measure_vsize_threadfunc, |
|
38 args=(proc, output_file)) |
|
39 t.start() |
|
40 # Wait for the linker to finish. |
|
41 exitcode = proc.wait() |
|
42 # ...and then wait for the background thread to finish. |
|
43 t.join() |
|
44 return exitcode |
|
45 |
|
46 if __name__ == "__main__": |
|
47 if sys.platform != "win32": |
|
48 print >>sys.stderr, "link.py is only for use on Windows!" |
|
49 sys.exit(1) |
|
50 if len(sys.argv) < 3: |
|
51 print >>sys.stderr, "Usage: link.py <output filename> <commandline>" |
|
52 sys.exit(1) |
|
53 sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:])) |