build/win32/pgomerge.py
author Sebastian Kromp <46b@gulli.com>
Thu, 31 Mar 2011 07:32:13 -0400
changeset 64453 b7534c685c11affc13e1ee4d7def829d694d6d67
parent 23477 2e8178964532168626421214905651951fad4925
child 94484 f4157e8c410708d76703f19e4dfb61859bfe32d8
permissions -rwxr-xr-x
Bug 633066: Remove nsICiter and make nsInternetCiter a static class. r=ehsan

#!/usr/bin/python
# Usage: pgomerge.py <binary basename> <dist/bin>
# Gathers .pgc files from dist/bin and merges them into
# $PWD/$basename.pgd using pgomgr, then deletes them.
# No errors if any of these files don't exist.

import sys, os, os.path, subprocess
if not sys.platform == "win32":
    raise Exception("This script was only meant for Windows.")

def MergePGOFiles(basename, pgddir, pgcdir):
  """Merge pgc files produced from an instrumented binary
     into the pgd file for the second pass of profile-guided optimization
     with MSVC.  |basename| is the name of the DLL or EXE without the
     extension.  |pgddir| is the path that contains <basename>.pgd
     (should be the objdir it was built in).  |pgcdir| is the path
     containing basename!N.pgc files, which is probably dist/bin.
     Calls pgomgr to merge each pgc file into the pgd, then deletes
     the pgc files."""
  if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir):
    return
  pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
  if not os.path.isfile(pgdfile):
    return
  for file in os.listdir(pgcdir):
    if file.startswith(basename+"!") and file.endswith(".pgc"):
      try:
        pgcfile = os.path.normpath(os.path.join(pgcdir, file))
        subprocess.call(['pgomgr', '-merge',
                         pgcfile,
                         pgdfile])
        os.remove(pgcfile)
      except OSError:
        pass

if __name__ == '__main__':
  if len(sys.argv) != 3:
      print >>sys.stderr, "Usage: pgomerge.py <binary basename> <dist/bin>"
      sys.exit(1)
  MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])