Skip to content

Commit cf52b7e

Browse files
authored
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
1 parent 504f1e8 commit cf52b7e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/coreclr/crossgen-corelib.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<DotNetPgoCmd>$(DotNetCli) $([MSBuild]::NormalizePath('$(BinDir)', 'dotnet-pgo', 'dotnet-pgo.dll')) merge</DotNetPgoCmd>
6767
<DotNetPgoCmd>$(DotNetPgoCmd) -o:$(MergedMibcPath)</DotNetPgoCmd>
6868
<DotNetPgoCmd>$(DotNetPgoCmd) @(OptimizationMibcFiles->'-i:%(Identity)', ' ')</DotNetPgoCmd>
69+
<DotNetPgoCmd>$(DotNetPgoCmd) --inherit-timestamp</DotNetPgoCmd> <!-- For incremental builds, otherwise timestamp is too far in the future -->
6970
</PropertyGroup>
7071

7172
<Message Condition="'$(DotNetBuildFromSource)' != 'true'" Importance="High" Text="$(DotNetPgoCmd)"/>

src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ internal class CommandLineOptions
4545
public bool DumpMibc = false;
4646
public FileInfo InputFileToDump;
4747
public List<FileInfo> CompareMibc;
48+
public bool InheritTimestamp;
4849

4950
public string[] HelpArgs = Array.Empty<string>();
5051

@@ -265,6 +266,8 @@ void HelpOption()
265266
}
266267
}
267268

269+
syntax.DefineOption(name: "inherit-timestamp", value: ref InheritTimestamp, help: "If specified, set the output's timestamp to the max timestamp of the input files");
270+
268271
VerbosityOption();
269272
CompressedOption();
270273
HelpOption();

src/coreclr/tools/dotnet-pgo/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,14 @@ static int InnerMergeMain(CommandLineOptions commandLineOptions)
378378
ProfileData.MergeProfileData(ref partialNgen, mergedProfileData, MIbcProfileParser.ParseMIbcFile(tsc, peReader, assemblyNamesInBubble, onlyDefinedInAssembly: null));
379379
}
380380

381-
return MibcEmitter.GenerateMibcFile(tsc, commandLineOptions.OutputFileName, mergedProfileData.Values, commandLineOptions.ValidateOutputFile, commandLineOptions.Uncompressed);
381+
int result = MibcEmitter.GenerateMibcFile(tsc, commandLineOptions.OutputFileName, mergedProfileData.Values, commandLineOptions.ValidateOutputFile, commandLineOptions.Uncompressed);
382+
if (result == 0 && commandLineOptions.InheritTimestamp)
383+
{
384+
commandLineOptions.OutputFileName.CreationTimeUtc = commandLineOptions.InputFilesToMerge.Max(fi => fi.CreationTimeUtc);
385+
commandLineOptions.OutputFileName.LastWriteTimeUtc = commandLineOptions.InputFilesToMerge.Max(fi => fi.LastWriteTimeUtc);
386+
}
387+
388+
return result;
382389
}
383390
finally
384391
{

0 commit comments

Comments
 (0)