michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: from __future__ import with_statement michael@0: import os, subprocess, sys, threading, time michael@0: from win32 import procmem michael@0: michael@0: def measure_vsize_threadfunc(proc, output_file): michael@0: """ michael@0: Measure the virtual memory usage of |proc| at regular intervals michael@0: until it exits, then print the maximum value and write it to michael@0: |output_file|. Also, print something to the console every michael@0: half an hour to prevent the build job from getting killed when michael@0: linking a large PGOed binary. michael@0: """ michael@0: maxvsize = 0 michael@0: idleTime = 0 michael@0: while proc.returncode is None: michael@0: maxvsize, vsize = procmem.get_vmsize(proc._handle) michael@0: time.sleep(0.5) michael@0: idleTime += 0.5 michael@0: if idleTime > 30 * 60: michael@0: print "Still linking, 30 minutes passed..." michael@0: sys.stdout.flush() michael@0: idleTime = 0 michael@0: print "TinderboxPrint: linker max vsize: %d" % maxvsize michael@0: with open(output_file, "w") as f: michael@0: f.write("%d\n" % maxvsize) michael@0: michael@0: def measure_link_vsize(output_file, args): michael@0: """ michael@0: Execute |args|, and measure the maximum virtual memory usage of the process, michael@0: printing it to stdout when finished. michael@0: """ michael@0: proc = subprocess.Popen(args) michael@0: t = threading.Thread(target=measure_vsize_threadfunc, michael@0: args=(proc, output_file)) michael@0: t.start() michael@0: # Wait for the linker to finish. michael@0: exitcode = proc.wait() michael@0: # ...and then wait for the background thread to finish. michael@0: t.join() michael@0: return exitcode michael@0: michael@0: if __name__ == "__main__": michael@0: if sys.platform != "win32": michael@0: print >>sys.stderr, "link.py is only for use on Windows!" michael@0: sys.exit(1) michael@0: if len(sys.argv) < 3: michael@0: print >>sys.stderr, "Usage: link.py " michael@0: sys.exit(1) michael@0: sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:]))