Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly rebuild optimization data when it changes #56397

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/coreclr/crossgen-corelib.proj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<DotNetPgoCmd>$(DotNetCli) $([MSBuild]::NormalizePath('$(BinDir)', 'dotnet-pgo', 'dotnet-pgo.dll')) merge</DotNetPgoCmd>
<DotNetPgoCmd>$(DotNetPgoCmd) -o:$(MergedMibcPath)</DotNetPgoCmd>
<DotNetPgoCmd>$(DotNetPgoCmd) @(OptimizationMibcFiles->'-i:%(Identity)', ' ')</DotNetPgoCmd>
<DotNetPgoCmd>$(DotNetPgoCmd) --inherit-timestamp</DotNetPgoCmd> <!-- For incremental builds, otherwise timestamp is too far in the future -->
</PropertyGroup>

<Message Condition="'$(DotNetBuildFromSource)' != 'true'" Importance="High" Text="$(DotNetPgoCmd)"/>
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/tools/dotnet-pgo/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal class CommandLineOptions
public bool DumpMibc = false;
public FileInfo InputFileToDump;
public List<FileInfo> CompareMibc;
public bool InheritTimestamp;

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

Expand Down Expand Up @@ -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");
EgorBo marked this conversation as resolved.
Show resolved Hide resolved

VerbosityOption();
CompressedOption();
HelpOption();
Expand Down
12 changes: 11 additions & 1 deletion src/coreclr/tools/dotnet-pgo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,17 @@ 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)
{
static DateTime Latest(IEnumerable<DateTime> datetimes)
=> datetimes.Aggregate((cur, dt) => dt > cur ? dt : cur);

commandLineOptions.OutputFileName.CreationTimeUtc = Latest(commandLineOptions.InputFilesToMerge.Select(fi => fi.CreationTimeUtc));
commandLineOptions.OutputFileName.LastWriteTimeUtc = Latest(commandLineOptions.InputFilesToMerge.Select(fi => fi.LastWriteTimeUtc));
}
Copy link
Member

@EgorBo EgorBo Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do it in one chain 🙂:

commandLineOptions.InputFilesToMerge
    .Select(fi => fi.CreationTimeUtc)
    .Combine(commandLineOptions.InputFilesToMerge.Select(fi => fi.LastWriteTimeUtc))
    .OrderByDescending(d => d).FirstOrDefault();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm setting CreationTimeUtc and LastWriteTimeUtc separately here, so I would need two chains (or set both to the same, I guess that would work too). Actually, I see now that I can just use .Max() so will change it to that.


return result;
}
finally
{
Expand Down