author L. David Baron <>
Thu, 21 Feb 2013 18:10:59 -0800
changeset 122588 b968708558b928354922880cb98501cb80ae3338
parent 94969 a8e08361c00efce2e2b71b80bd5b019d8be43f33
child 148850 c3fd83b98898bc9ae8e2f743f6f8901cdf5d7c59
permissions -rw-r--r--
Bug 839809: Make counter-increments and list counting that would go past our internal (int32_t) limit keep the counter at its current value rather than wrapping. r=dholbert Per CSS WG resolution regarding counter-styles-3, afternoon of 2013-02-05: Note that this patch depends on signed integer overflow behavior in C++, which I believe is portable despite being unspecified.

# 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

from __future__ import with_statement
import os, subprocess, sys, threading, time
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
    maxvsize = 0
    while proc.returncode is None:
        maxvsize, vsize = procmem.get_vmsize(proc._handle)
    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))
    # Wait for the linker to finish.
    exitcode = proc.wait()
    # ...and then wait for the background thread to finish.
    return exitcode

if __name__ == "__main__":
    if sys.platform != "win32":
        print >>sys.stderr, " is only for use on Windows!"
    if len(sys.argv) < 3:
        print >>sys.stderr, "Usage: <output filename> <commandline>"
    sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:]))