Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fa02660

Browse files
author
Daniel Podder
committed
Consume optimization data during release builds
Restore optimization data from nuget prior to the native build. Update PGO implementation to consume the data from the restored package.
1 parent 6ad9f31 commit fa02660

File tree

7 files changed

+110
-1
lines changed

7 files changed

+110
-1
lines changed

build.cmd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ call "%__VSToolsRoot%\VsDevCmd.bat"
189189

190190
@call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\build.proj -generateHeaderWindows -NativeVersionHeaderFile="%__RootBinDir%\obj\_version.h" %__RunArgs% %__UnprocessedBuildArgs%
191191

192+
REM =========================================================================================
193+
REM ===
194+
REM === Restore optimization profile data
195+
REM ===
196+
REM =========================================================================================
197+
198+
echo %__MsgPrefix%Restoring the OptimizationData Package
199+
@call %__ProjectDir%\run.cmd sync -optdata
200+
192201
REM =========================================================================================
193202
REM ===
194203
REM === Build the CLR VM

build.proj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<Delete Files="$(BinDir)System.Private.CoreLib.*" />
2525
</Target>
2626

27+
<Target Name="RestoreOptData">
28+
<Exec Command="$(DnuRestoreCommand) &quot;$(SourceDir).nuget/optdata/project.json&quot; --source https://dotnet.myget.org/F/dotnet-core-optimization-data/api/v3/index.json" />
29+
</Target>
30+
2731
<Target Name="RestoreNETCorePlatforms" AfterTargets="Build" Condition="'$(RestoreDuringBuild)'=='true'">
2832
<Exec Command="$(DnuRestoreCommand) &quot;$(SourceDir).nuget/init/project.json&quot; --source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
2933
</Target>

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ build_coreclr()
176176
echo $__versionSourceLine > $__versionSourceFile
177177
fi
178178

179+
echo "Restoring the OptimizationData package"
180+
"$__ProjectRoot/run.sh" sync -optdata
181+
179182
pushd "$__IntermediatesDir"
180183
# Regenerate the CMake solution
181184
__ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"

config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
"values": [],
4949
"defaultValue": ""
5050
},
51+
"RestoreOptData": {
52+
"description": "MsBuild target that restores optimization profile data.",
53+
"valueType": "target",
54+
"values": [],
55+
"defaultValue": ""
56+
},
5157
"RestoreDuringBuild": {
5258
"description": "Enables/disables package restore.",
5359
"valueType": "property",
@@ -362,6 +368,14 @@
362368
"RestoreNETCorePlatforms": "default"
363369
}
364370
},
371+
"optdata": {
372+
"description": "Restores optimization profile data for the repository.",
373+
"settings": {
374+
"Project": "./build.proj",
375+
"RestoreDuringBuild": true,
376+
"RestoreOptData": "default"
377+
}
378+
},
365379
"ab": {
366380
"description": "Downloads the latests product packages from Azure. The values for '-AzureAccount' and '-AzureToken' are required",
367381
"settings": {

extract-from-json.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/python
2+
3+
import argparse
4+
import json
5+
import sys
6+
7+
def parse_args():
8+
parser = argparse.ArgumentParser(
9+
description="""Extracts information from a json file by navigating the JSON object using a
10+
sequence of property accessors and returning the JSON subtree, or the raw data, found
11+
at that location."""
12+
)
13+
14+
parser.add_argument(
15+
'-f', '--file',
16+
metavar='<project.json>',
17+
help="Path to project.json file to parse",
18+
required=True,
19+
)
20+
21+
parser.add_argument(
22+
'property',
23+
metavar='property_name',
24+
help="""Name of property to extract using object notation.
25+
Pass multiple values to drill down into nested objects (in order).""",
26+
nargs='*',
27+
)
28+
29+
parser.add_argument(
30+
'-r', '--raw',
31+
help="""Dumps the raw object found at the requested location.
32+
If omitted, returns a JSON formatted object instead.""",
33+
action='store_true',
34+
default=False
35+
)
36+
37+
return parser.parse_args()
38+
39+
def main():
40+
args = parse_args()
41+
42+
with open(args.file) as json_file:
43+
selected_property = json.load(json_file)
44+
45+
for prop in args.property:
46+
selected_property = selected_property[prop]
47+
48+
if args.raw:
49+
print(selected_property)
50+
else:
51+
print(json.dumps(selected_property))
52+
53+
return 0
54+
55+
if __name__ == "__main__":
56+
sys.exit(main())

pgosupport.cmake

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function(add_pgo TargetName)
1313
endif(WIN32)
1414

1515
file(TO_NATIVE_PATH
16-
"${CLR_CMAKE_PACKAGES_DIR}/Microsoft.DotNet.OptimizationData.Coreclr/${CLR_CMAKE_TARGET_OS}.${CLR_CMAKE_TARGET_ARCH}/${ProfileFileName}"
16+
"${CLR_CMAKE_PACKAGES_DIR}/${CLR_CMAKE_OPTDATA_PACKAGEWITHRID}/${CLR_CMAKE_OPTDATA_VERSION}/data/${ProfileFileName}"
1717
ProfilePath
1818
)
1919

@@ -37,6 +37,18 @@ function(add_pgo TargetName)
3737
endforeach(ConfigType)
3838
endfunction(add_pgo)
3939

40+
set(CLR_CMAKE_OPTDATA_PACKAGEID "optimization.PGO.CoreCLR")
41+
set(CLR_CMAKE_OPTDATA_PACKAGEWITHRID "optimization.${CLR_CMAKE_TARGET_OS}-${CLR_CMAKE_TARGET_ARCH}.PGO.CoreCLR")
42+
43+
# Parse optdata package version from project.json
44+
file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}/extract-from-json.py" ExtractFromJsonScript)
45+
file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}/src/.nuget/optdata/project.json" OptDataProjectJsonPath)
46+
execute_process(
47+
COMMAND python "${ExtractFromJsonScript}" -rf "${OptDataProjectJsonPath}" dependencies "${CLR_CMAKE_OPTDATA_PACKAGEID}"
48+
OUTPUT_VARIABLE CLR_CMAKE_OPTDATA_VERSION
49+
OUTPUT_STRIP_TRAILING_WHITESPACE
50+
)
51+
4052
if(WIN32)
4153
if(CLR_CMAKE_PGO_INSTRUMENT)
4254
# Instrumented PGO binaries on Windows introduce an additional runtime dependency, pgort<ver>.dll.

src/.nuget/optdata/project.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"dependencies": {
3+
"optimization.PGO.CoreCLR": "1.1.0-release-20161025"
4+
},
5+
"frameworks": {
6+
"netstandard": {}
7+
},
8+
"runtimes": {
9+
"win7-x64": {}
10+
}
11+
}

0 commit comments

Comments
 (0)