2012-05-21 15:12:37 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-05-01 20:09:44 +04:00
|
|
|
|
|
|
|
from __future__ import with_statement
|
2012-05-25 22:02:54 +04:00
|
|
|
import os, subprocess, sys, threading, time
|
2012-05-01 20:09:44 +04:00
|
|
|
from win32 import procmem
|
|
|
|
|
|
|
|
def measure_vsize_threadfunc(proc, output_file):
|
|
|
|
"""
|
|
|
|
Measure the virtual memory usage of |proc| at regular intervals
|
|
|
|
until it exits, then print the maximum value and write it to
|
|
|
|
|output_file|.
|
|
|
|
"""
|
|
|
|
maxvsize = 0
|
|
|
|
while proc.returncode is None:
|
|
|
|
maxvsize, vsize = procmem.get_vmsize(proc._handle)
|
|
|
|
time.sleep(0.5)
|
|
|
|
print "TinderboxPrint: linker max vsize: %d" % maxvsize
|
|
|
|
with open(output_file, "w") as f:
|
|
|
|
f.write("%d\n" % maxvsize)
|
|
|
|
|
|
|
|
def measure_link_vsize(output_file, args):
|
|
|
|
"""
|
|
|
|
Execute |args|, and measure the maximum virtual memory usage of the process,
|
|
|
|
printing it to stdout when finished.
|
|
|
|
"""
|
|
|
|
proc = subprocess.Popen(args)
|
|
|
|
t = threading.Thread(target=measure_vsize_threadfunc,
|
|
|
|
args=(proc, output_file))
|
|
|
|
t.start()
|
|
|
|
# Wait for the linker to finish.
|
|
|
|
exitcode = proc.wait()
|
|
|
|
# ...and then wait for the background thread to finish.
|
|
|
|
t.join()
|
|
|
|
return exitcode
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2012-05-25 22:02:54 +04:00
|
|
|
if sys.platform != "win32":
|
2012-05-01 20:09:44 +04:00
|
|
|
print >>sys.stderr, "link.py is only for use on Windows!"
|
|
|
|
sys.exit(1)
|
|
|
|
if len(sys.argv) < 3:
|
|
|
|
print >>sys.stderr, "Usage: link.py <output filename> <commandline>"
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:]))
|