From cf52b7e38d28b7e28358cee052effe0ed47efb2e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 28 Jul 2021 10:27:36 +0200 Subject: [PATCH] Properly rebuild optimization data when it changes (#56397) The timestamp of the merged .mibc file was set to when the tool was invoked, while the inputs have a timestamp from when they were created in the training scenarios. That means the target to create the merged .mibc file would not run incrementally until many weeks later. To fix add an --inherit-timestamp flag to dotnet-pgo that makes the merged output inherit the max timestamp from the inputs. This is not ideal as it means incrementally going backwards does not work, but it's better than the previous behavior. Fix #53637 --- src/coreclr/crossgen-corelib.proj | 1 + src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs | 3 +++ src/coreclr/tools/dotnet-pgo/Program.cs | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/coreclr/crossgen-corelib.proj b/src/coreclr/crossgen-corelib.proj index 6d675a2a59e24..655fc3281eb2e 100644 --- a/src/coreclr/crossgen-corelib.proj +++ b/src/coreclr/crossgen-corelib.proj @@ -66,6 +66,7 @@ $(DotNetCli) $([MSBuild]::NormalizePath('$(BinDir)', 'dotnet-pgo', 'dotnet-pgo.dll')) merge $(DotNetPgoCmd) -o:$(MergedMibcPath) $(DotNetPgoCmd) @(OptimizationMibcFiles->'-i:%(Identity)', ' ') + $(DotNetPgoCmd) --inherit-timestamp diff --git a/src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs b/src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs index 3da9ded70632f..a2e3a82f37fdb 100644 --- a/src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs +++ b/src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs @@ -45,6 +45,7 @@ internal class CommandLineOptions public bool DumpMibc = false; public FileInfo InputFileToDump; public List CompareMibc; + public bool InheritTimestamp; public string[] HelpArgs = Array.Empty(); @@ -265,6 +266,8 @@ void HelpOption() } } + syntax.DefineOption(name: "inherit-timestamp", value: ref InheritTimestamp, help: "If specified, set the output's timestamp to the max timestamp of the input files"); + VerbosityOption(); CompressedOption(); HelpOption(); diff --git a/src/coreclr/tools/dotnet-pgo/Program.cs b/src/coreclr/tools/dotnet-pgo/Program.cs index f129fdfee59bf..77113377c478d 100644 --- a/src/coreclr/tools/dotnet-pgo/Program.cs +++ b/src/coreclr/tools/dotnet-pgo/Program.cs @@ -378,7 +378,14 @@ static int InnerMergeMain(CommandLineOptions commandLineOptions) ProfileData.MergeProfileData(ref partialNgen, mergedProfileData, MIbcProfileParser.ParseMIbcFile(tsc, peReader, assemblyNamesInBubble, onlyDefinedInAssembly: null)); } - return MibcEmitter.GenerateMibcFile(tsc, commandLineOptions.OutputFileName, mergedProfileData.Values, commandLineOptions.ValidateOutputFile, commandLineOptions.Uncompressed); + int result = MibcEmitter.GenerateMibcFile(tsc, commandLineOptions.OutputFileName, mergedProfileData.Values, commandLineOptions.ValidateOutputFile, commandLineOptions.Uncompressed); + if (result == 0 && commandLineOptions.InheritTimestamp) + { + commandLineOptions.OutputFileName.CreationTimeUtc = commandLineOptions.InputFilesToMerge.Max(fi => fi.CreationTimeUtc); + commandLineOptions.OutputFileName.LastWriteTimeUtc = commandLineOptions.InputFilesToMerge.Max(fi => fi.LastWriteTimeUtc); + } + + return result; } finally {