Back to index

enigmail  1.4.3
link.py
Go to the documentation of this file.
00001 # ***** BEGIN LICENSE BLOCK *****
00002 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003 #
00004 # The contents of this file are subject to the Mozilla Public License Version
00005 # 1.1 (the "License"); you may not use this file except in compliance with
00006 # the License. You may obtain a copy of the License at
00007 # http://www.mozilla.org/MPL/
00008 #
00009 # Software distributed under the License is distributed on an "AS IS" basis,
00010 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011 # for the specific language governing rights and limitations under the
00012 # License.
00013 #
00014 # The Original Code is cl.py: a python wrapper for cl to automatically generate
00015 # dependency information.
00016 #
00017 # The Initial Developer of the Original Code is
00018 #   Mozilla Foundation.
00019 # Portions created by the Initial Developer are Copyright (C) 2010
00020 # the Initial Developer. All Rights Reserved.
00021 #
00022 # Contributor(s):
00023 #   Ted Mielczarek <ted@mielczarek.org>
00024 #
00025 # Alternatively, the contents of this file may be used under the terms of
00026 # either the GNU General Public License Version 2 or later (the "GPL"), or
00027 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028 # in which case the provisions of the GPL or the LGPL are applicable instead
00029 # of those above. If you wish to allow use of your version of this file only
00030 # under the terms of either the GPL or the LGPL, and not to allow others to
00031 # use your version of this file under the terms of the MPL, indicate your
00032 # decision by deleting the provisions above and replace them with the notice
00033 # and other provisions required by the GPL or the LGPL. If you do not delete
00034 # the provisions above, a recipient may use your version of this file under
00035 # the terms of any one of the MPL, the GPL or the LGPL.
00036 #
00037 # ***** END LICENSE BLOCK *****
00038 
00039 from __future__ import with_statement
00040 import os, platform, subprocess, sys, threading, time
00041 from win32 import procmem
00042 
00043 def measure_vsize_threadfunc(proc, output_file):
00044     """
00045     Measure the virtual memory usage of |proc| at regular intervals
00046     until it exits, then print the maximum value and write it to
00047     |output_file|.
00048     """
00049     maxvsize = 0
00050     while proc.returncode is None:
00051         maxvsize, vsize = procmem.get_vmsize(proc._handle)
00052         time.sleep(0.5)
00053     print "linker max virtual size: %d" % maxvsize
00054     with open(output_file, "w") as f:
00055         f.write("%d\n" % maxvsize)
00056 
00057 def measure_link_vsize(output_file, args):
00058     """
00059     Execute |args|, and measure the maximum virtual memory usage of the process,
00060     printing it to stdout when finished.
00061     """
00062     proc = subprocess.Popen(args)
00063     t = threading.Thread(target=measure_vsize_threadfunc,
00064                          args=(proc, output_file))
00065     t.start()
00066     # Wait for the linker to finish.
00067     exitcode = proc.wait()
00068     # ...and then wait for the background thread to finish.
00069     t.join()
00070     return exitcode
00071 
00072 if __name__ == "__main__":
00073     if platform.system() != "Windows":
00074         print >>sys.stderr, "link.py is only for use on Windows!"
00075         sys.exit(1)
00076     if len(sys.argv) < 3:
00077         print >>sys.stderr, "Usage: link.py <output filename> <commandline>"
00078         sys.exit(1)
00079     sys.exit(measure_link_vsize(sys.argv[1], sys.argv[2:]))