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 6d675a2..655fc32 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 3da9ded..a2e3a82 100644 --- a/src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs +++ b/src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs @@ -45,6 +45,7 @@ namespace Microsoft.Diagnostics.Tools.Pgo public bool DumpMibc = false; public FileInfo InputFileToDump; public List CompareMibc; + public bool InheritTimestamp; public string[] HelpArgs = Array.Empty(); @@ -265,6 +266,8 @@ namespace Microsoft.Diagnostics.Tools.Pgo } } + 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 f129fdfe..7711337 100644 --- a/src/coreclr/tools/dotnet-pgo/Program.cs +++ b/src/coreclr/tools/dotnet-pgo/Program.cs @@ -378,7 +378,14 @@ namespace Microsoft.Diagnostics.Tools.Pgo 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 { -- 2.7.4