author Gregory Szorc <>
Wed, 28 Jan 2015 13:37:00 -0800
changeset 110571 16775e809a2ffbaed93543daa8b0013d2759d8c7
parent 98529 f4157e8c410708d76703f19e4dfb61859bfe32d8
permissions -rwxr-xr-x
Close old release branch GECKO1708esr_2013080114_RELBRANCH

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

# Usage: <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):
  pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
  if not os.path.isfile(pgdfile):
  for file in os.listdir(pgcdir):
    if file.startswith(basename+"!") and file.endswith(".pgc"):
        pgcfile = os.path.normpath(os.path.join(pgcdir, file))['pgomgr', '-merge',
      except OSError:

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