michael@0: #!/usr/bin/python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # Usage: pgomerge.py michael@0: # Gathers .pgc files from dist/bin and merges them into michael@0: # $PWD/$basename.pgd using pgomgr, then deletes them. michael@0: # No errors if any of these files don't exist. michael@0: michael@0: import sys, os, os.path, subprocess michael@0: if not sys.platform == "win32": michael@0: raise Exception("This script was only meant for Windows.") michael@0: michael@0: def MergePGOFiles(basename, pgddir, pgcdir): michael@0: """Merge pgc files produced from an instrumented binary michael@0: into the pgd file for the second pass of profile-guided optimization michael@0: with MSVC. |basename| is the name of the DLL or EXE without the michael@0: extension. |pgddir| is the path that contains .pgd michael@0: (should be the objdir it was built in). |pgcdir| is the path michael@0: containing basename!N.pgc files, which is probably dist/bin. michael@0: Calls pgomgr to merge each pgc file into the pgd, then deletes michael@0: the pgc files.""" michael@0: if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir): michael@0: return michael@0: pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd")) michael@0: if not os.path.isfile(pgdfile): michael@0: return michael@0: for file in os.listdir(pgcdir): michael@0: if file.startswith(basename+"!") and file.endswith(".pgc"): michael@0: try: michael@0: pgcfile = os.path.normpath(os.path.join(pgcdir, file)) michael@0: subprocess.call(['pgomgr', '-merge', michael@0: pgcfile, michael@0: pgdfile]) michael@0: os.remove(pgcfile) michael@0: except OSError: michael@0: pass michael@0: michael@0: if __name__ == '__main__': michael@0: if len(sys.argv) != 3: michael@0: print >>sys.stderr, "Usage: pgomerge.py " michael@0: sys.exit(1) michael@0: MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])