build/link.py

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial