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
13 |output_file|. Also, print something to the console every
14 half an hour to prevent the build job from getting killed when
15 linking a large PGOed binary.
19 while proc
.returncode
is None:
20 maxvsize
, vsize
= procmem
.get_vmsize(proc
._handle
)
23 if idleTime
> 30 * 60:
24 print "Still linking, 30 minutes passed..."
27 print "TinderboxPrint: linker max vsize: %d" % maxvsize
28 with
open(output_file
, "w") as f
:
29 f
.write("%d\n" % maxvsize
)
31 def measure_link_vsize(output_file
, args
):
33 Execute |args|, and measure the maximum virtual memory usage of the process,
34 printing it to stdout when finished.
36 proc
= subprocess
.Popen(args
)
37 t
= threading
.Thread(target
=measure_vsize_threadfunc
,
38 args
=(proc
, output_file
))
40 # Wait for the linker to finish.
41 exitcode
= proc
.wait()
42 # ...and then wait for the background thread to finish.
46 if __name__
== "__main__":
47 if sys
.platform
!= "win32":
48 print >>sys
.stderr
, "link.py is only for use on Windows!"
51 print >>sys
.stderr
, "Usage: link.py <output filename> <commandline>"
53 sys
.exit(measure_link_vsize(sys
.argv
[1], sys
.argv
[2:]))