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/.
5 from __future__
import with_statement
6 import os
, subprocess
, sys
, threading
, time
7 from win32
import procmem
9 def measure_vsize_threadfunc(proc
, output_file
):
11 Measure the virtual memory usage of |proc| at regular intervals
12 until it exits, then print the maximum value and write it to
16 while proc
.returncode
is None:
17 maxvsize
, vsize
= procmem
.get_vmsize(proc
._handle
)
19 print "TinderboxPrint: linker max vsize: %d" % maxvsize
20 with
open(output_file
, "w") as f
:
21 f
.write("%d\n" % maxvsize
)
23 def measure_link_vsize(output_file
, args
):
25 Execute |args|, and measure the maximum virtual memory usage of the process,
26 printing it to stdout when finished.
28 proc
= subprocess
.Popen(args
)
29 t
= threading
.Thread(target
=measure_vsize_threadfunc
,
30 args
=(proc
, output_file
))
32 # Wait for the linker to finish.
33 exitcode
= proc
.wait()
34 # ...and then wait for the background thread to finish.
38 if __name__
== "__main__":
39 if sys
.platform
!= "win32":
40 print >>sys
.stderr
, "link.py is only for use on Windows!"
43 print >>sys
.stderr
, "Usage: link.py <output filename> <commandline>"
45 sys
.exit(measure_link_vsize(sys
.argv
[1], sys
.argv
[2:]))