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/.
10 from win32
import procmem
12 def measure_vsize_threadfunc(proc
, output_file
):
14 Measure the virtual memory usage of |proc| at regular intervals
15 until it exits, then print the maximum value and write it to
16 |output_file|. Also, print something to the console every
17 half an hour to prevent the build job from getting killed when
18 linking a large PGOed binary.
22 while proc
.returncode
is None:
23 maxvsize
, vsize
= procmem
.get_vmsize(proc
._handle
)
26 if idleTime
> 30 * 60:
27 print "Still linking, 30 minutes passed..."
30 print "TinderboxPrint: linker max vsize: %d" % maxvsize
31 with
open(output_file
, "w") as f
:
32 f
.write("%d\n" % maxvsize
)
34 def measure_link_vsize(output_file
, args
):
36 Execute |args|, and measure the maximum virtual memory usage of the process,
37 printing it to stdout when finished.
40 # This needs to be a list in order for the callback to set the
41 # variable properly with python-2's scoping rules.
44 t
[0] = threading
.Thread(target
=measure_vsize_threadfunc
,
45 args
=(proc
, output_file
))
47 exitcode
= expandlibs_exec
.main(args
, proc_callback
=callback
)
48 # Wait for the background thread to finish.
52 if __name__
== "__main__":
53 if sys
.platform
!= "win32":
54 print >>sys
.stderr
, "link.py is only for use on Windows!"
57 print >>sys
.stderr
, "Usage: link.py <output filename> <commandline>"
59 output_file
= sys
.argv
.pop(1)
60 sys
.exit(measure_link_vsize(output_file
, sys
.argv
[1:]))