build/link.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/link.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +from __future__ import with_statement
     1.9 +import os, subprocess, sys, threading, time
    1.10 +from win32 import procmem
    1.11 +
    1.12 +def measure_vsize_threadfunc(proc, output_file):
    1.13 +    """
    1.14 +    Measure the virtual memory usage of |proc| at regular intervals
    1.15 +    until it exits, then print the maximum value and write it to
    1.16 +    |output_file|.  Also, print something to the console every
    1.17 +    half an hour to prevent the build job from getting killed when
    1.18 +    linking a large PGOed binary.
    1.19 +    """
    1.20 +    maxvsize = 0
    1.21 +    idleTime = 0
    1.22 +    while proc.returncode is None:
    1.23 +        maxvsize, vsize = procmem.get_vmsize(proc._handle)
    1.24 +        time.sleep(0.5)
    1.25 +        idleTime += 0.5
    1.26 +        if idleTime > 30 * 60:
    1.27 +          print "Still linking, 30 minutes passed..."
    1.28 +          sys.stdout.flush()
    1.29 +          idleTime = 0
    1.30 +    print "TinderboxPrint: linker max vsize: %d" % maxvsize
    1.31 +    with open(output_file, "w") as f:
    1.32 +        f.write("%d\n" % maxvsize)
    1.33 +
    1.34 +def measure_link_vsize(output_file, args):
    1.35 +    """
    1.36 +    Execute |args|, and measure the maximum virtual memory usage of the process,
    1.37 +    printing it to stdout when finished.
    1.38 +    """
    1.39 +    proc = subprocess.Popen(args)
    1.40 +    t = threading.Thread(target=measure_vsize_threadfunc,
    1.41 +                         args=(proc, output_file))
    1.42 +    t.start()
    1.43 +    # Wait for the linker to finish.
    1.44 +    exitcode = proc.wait()
    1.45 +    # ...and then wait for the background thread to finish.
    1.46 +    t.join()
    1.47 +    return exitcode
    1.48 +
    1.49 +if __name__ == "__main__":
    1.50 +    if sys.platform != "win32":
    1.51 +        print >>sys.stderr, "link.py is only for use on Windows!"
    1.52 +        sys.exit(1)
    1.53 +    if len(sys.argv) < 3:
    1.54 +        print >>sys.stderr, "Usage: link.py <output filename> <commandline>"
    1.55 +        sys.exit(1)
    1.56 +    sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:]))

mercurial