1 |
siliconforks |
399 |
#!/usr/bin/python |
2 |
|
|
# Usage: pgomerge.py <binary basename> <dist/bin> |
3 |
|
|
# Gathers .pgc files from dist/bin and merges them into |
4 |
|
|
# $PWD/$basename.pgd using pgomgr, then deletes them. |
5 |
|
|
# No errors if any of these files don't exist. |
6 |
|
|
|
7 |
|
|
import sys, os, os.path, subprocess |
8 |
|
|
if not sys.platform == "win32": |
9 |
|
|
raise Exception("This script was only meant for Windows.") |
10 |
|
|
|
11 |
|
|
def MergePGOFiles(basename, pgddir, pgcdir): |
12 |
|
|
"""Merge pgc files produced from an instrumented binary |
13 |
|
|
into the pgd file for the second pass of profile-guided optimization |
14 |
|
|
with MSVC. |basename| is the name of the DLL or EXE without the |
15 |
|
|
extension. |pgddir| is the path that contains <basename>.pgd |
16 |
|
|
(should be the objdir it was built in). |pgcdir| is the path |
17 |
|
|
containing basename!N.pgc files, which is probably dist/bin. |
18 |
|
|
Calls pgomgr to merge each pgc file into the pgd, then deletes |
19 |
|
|
the pgc files.""" |
20 |
|
|
if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir): |
21 |
|
|
return |
22 |
|
|
pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd")) |
23 |
|
|
if not os.path.isfile(pgdfile): |
24 |
|
|
return |
25 |
|
|
for file in os.listdir(pgcdir): |
26 |
siliconforks |
460 |
if file.startswith(basename+"!") and file.endswith(".pgc"): |
27 |
siliconforks |
399 |
try: |
28 |
|
|
pgcfile = os.path.normpath(os.path.join(pgcdir, file)) |
29 |
|
|
subprocess.call(['pgomgr', '-merge', |
30 |
|
|
pgcfile, |
31 |
|
|
pgdfile]) |
32 |
|
|
os.remove(pgcfile) |
33 |
|
|
except OSError: |
34 |
|
|
pass |
35 |
|
|
|
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]) |