Skip to content

Commit

Permalink
Bug 1047621 - Have link.py import and call expandlibs_exec.py; r=gps
Browse files Browse the repository at this point in the history
  • Loading branch information
mshal committed Aug 13, 2014
1 parent 35b4ff1 commit 21bbc49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
11 changes: 7 additions & 4 deletions config/expandlibs_exec.py
Expand Up @@ -311,7 +311,7 @@ def print_command(out, args):
print >>out, "".join([" " + l for l in file.readlines()])
out.flush()

def main():
def main(args, proc_callback=None):
parser = OptionParser()
parser.add_option("--extract", action="store_true", dest="extract",
help="when a library has no descriptor file, extract it first, when possible")
Expand All @@ -322,7 +322,7 @@ def main():
parser.add_option("--symbol-order", dest="symbol_order", metavar="FILE",
help="use the given list of symbols to order symbols in the resulting binary when using with a linker")

(options, args) = parser.parse_args()
(options, args) = parser.parse_args(args)

with ExpandArgsMore(args) as args:
if options.extract:
Expand All @@ -336,6 +336,8 @@ def main():
print_command(sys.stderr, args)
try:
proc = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
if proc_callback:
proc_callback(proc)
except Exception, e:
print >>sys.stderr, 'error: Launching', args, ':', e
raise e
Expand All @@ -345,7 +347,8 @@ def main():
sys.stderr.write(stdout)
sys.stderr.flush()
if proc.returncode:
exit(proc.returncode)
return proc.returncode
return 0

if __name__ == '__main__':
main()
exit(main(sys.argv[1:]))
29 changes: 18 additions & 11 deletions config/link.py
Expand Up @@ -2,8 +2,11 @@
# 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/.

from __future__ import with_statement
import os, subprocess, sys, threading, time
import expandlibs_exec
import sys
import threading
import time

from win32 import procmem

def measure_vsize_threadfunc(proc, output_file):
Expand Down Expand Up @@ -33,14 +36,17 @@ 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()

# This needs to be a list in order for the callback to set the
# variable properly with python-2's scoping rules.
t = [None]
def callback(proc):
t[0] = threading.Thread(target=measure_vsize_threadfunc,
args=(proc, output_file))
t[0].start()
exitcode = expandlibs_exec.main(args, proc_callback=callback)
# Wait for the background thread to finish.
t[0].join()
return exitcode

if __name__ == "__main__":
Expand All @@ -50,4 +56,5 @@ def measure_link_vsize(output_file, args):
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:]))
output_file = sys.argv.pop(1)
sys.exit(measure_link_vsize(output_file, sys.argv[1:]))
4 changes: 3 additions & 1 deletion toolkit/library/Makefile.in
Expand Up @@ -4,9 +4,11 @@

include $(topsrcdir)/toolkit/library/libxul.mk

include $(topsrcdir)/config/config.mk

ifeq (WINNT_1,$(OS_TARGET)_$(MOZ_PROFILE_USE))
# Wrap linker to measure peak virtual memory usage.
LD := $(PYTHON) $(topsrcdir)/config/link.py linker-vsize $(LD)
EXPAND_LIBS_EXEC := $(PYTHON) $(topsrcdir)/config/link.py linker-vsize
endif

include $(topsrcdir)/config/rules.mk
Expand Down

0 comments on commit 21bbc49

Please sign in to comment.