pgomerge.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/python
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. # Usage: pgomerge.py <binary basename> <dist/bin>
  6. # Gathers .pgc files from dist/bin and merges them into
  7. # $PWD/$basename.pgd using pgomgr, then deletes them.
  8. # No errors if any of these files don't exist.
  9. import sys, os, os.path, subprocess
  10. if not sys.platform == "win32":
  11. raise Exception("This script was only meant for Windows.")
  12. def MergePGOFiles(basename, pgddir, pgcdir):
  13. """Merge pgc files produced from an instrumented binary
  14. into the pgd file for the second pass of profile-guided optimization
  15. with MSVC. |basename| is the name of the DLL or EXE without the
  16. extension. |pgddir| is the path that contains <basename>.pgd
  17. (should be the objdir it was built in). |pgcdir| is the path
  18. containing basename!N.pgc files, which is probably dist/bin.
  19. Calls pgomgr to merge each pgc file into the pgd, then deletes
  20. the pgc files."""
  21. if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir):
  22. return
  23. pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
  24. if not os.path.isfile(pgdfile):
  25. return
  26. for file in os.listdir(pgcdir):
  27. if file.startswith(basename+"!") and file.endswith(".pgc"):
  28. try:
  29. pgcfile = os.path.normpath(os.path.join(pgcdir, file))
  30. subprocess.call(['pgomgr', '-merge',
  31. pgcfile,
  32. pgdfile])
  33. os.remove(pgcfile)
  34. except OSError:
  35. pass
  36. if __name__ == '__main__':
  37. if len(sys.argv) != 3:
  38. print >>sys.stderr, "Usage: pgomerge.py <binary basename> <dist/bin>"
  39. sys.exit(1)
  40. MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])