This commit is contained in:
PiotrP 2016-04-20 17:53:38 -07:00
parent 4f1dbeba0e
commit 6c1ef959cc
5 changed files with 142 additions and 0 deletions

View file

@ -0,0 +1,57 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli
{
internal class MulticoreJitProfilePathCalculator
{
private string _multicoreJitProfilePath;
public string MulticoreJitProfilePath
{
get
{
if (_multicoreJitProfilePath == null)
{
CalculateProfileRootPath();
}
return _multicoreJitProfilePath;
}
}
private void CalculateProfileRootPath()
{
var profileRoot = GetRuntimeDataRootPath();
var version = Product.Version;
var rid = PlatformServices.Default.Runtime.GetRuntimeIdentifier();
_multicoreJitProfilePath = Path.Combine(profileRoot, "sdk", version, rid, "optimizationdata");
}
private string GetRuntimeDataRootPath()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? GetWindowsRuntimeDataRoot()
: GetNonWindowsRuntimeDataRoot();
}
private static string GetWindowsRuntimeDataRoot()
{
return $@"{(Environment.GetEnvironmentVariable("LocalAppData"))}\Microsoft\dotnet\";
}
private static string GetNonWindowsRuntimeDataRoot()
{
return $"{(Environment.GetEnvironmentVariable("HOME"))}/.dotnet/";
}
}
}

View file

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Loader;
using System.Text;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
@ -42,6 +43,10 @@ namespace Microsoft.DotNet.Cli
{
DebugHelper.HandleDebugSwitch(ref args);
AssemblyLoadContext.Default.SetProfileOptimizationRoot(
new MulticoreJitProfilePathCalculator().MulticoreJitProfilePath);
AssemblyLoadContext.Default.StartProfileOptimization("dotnet");
if (Env.GetEnvironmentVariableAsBool("DOTNET_CLI_CAPTURE_TIMING", false))
{
PerfTrace.Enabled = true;

View file

@ -1,3 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;

View file

@ -0,0 +1,76 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. 
// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System;
using System.IO;
using System.Runtime.InteropServices;
using Xunit;
using Xunit.Abstractions;
using FluentAssertions;
namespace Microsoft.DotNet.Tests
{
public class GivenThatIWantToManageMulticoreJIT : TestBase
{
ITestOutputHelper _output;
private const string OptimizationProfileFileName = "dotnet.";
private readonly string _optimizationProfileFilePath;
public GivenThatIWantToManageMulticoreJIT(ITestOutputHelper output)
{
_output = output;
_optimizationProfileFilePath = GetOptimizationProfileFilePath();
}
[Fact]
public void When_invoked_it_writes_optimization_data_to_the_profile_root()
{
var testStartTime = DateTime.UtcNow;
new TestCommand("dotnet")
.Execute("--version");
File.Exists(_optimizationProfileFilePath)
.Should().BeTrue("Because dotnet CLI creates it after each run");
File.GetLastWriteTimeUtc(_optimizationProfileFilePath)
.Should().BeOnOrAfter(testStartTime, "Because dotnet CLI was executed after that time.");
}
private static string GetOptimizationProfileFilePath()
{
Console.WriteLine(GetOptimizationRootPath(GetDotnetVersion()));
return Path.Combine(GetOptimizationRootPath(GetDotnetVersion()),
OptimizationProfileFileName);
}
private static string GetOptimizationRootPath(string version)
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? GetWindowsProfileRoot(version)
: GetNonWindowsProfileRoot(version);
}
private static string GetWindowsProfileRoot(string version)
{
return $@"{(Environment.GetEnvironmentVariable("LocalAppData"))}\Microsoft\dotnet\sdk\{version}\optimizationdata";
}
private static string GetNonWindowsProfileRoot(string version)
{
return $"{(Environment.GetEnvironmentVariable("HOME"))}/.dotnet/sdk/{version}/optimizationdata";
}
private static string GetDotnetVersion()
{
return Command.Create("dotnet", new[] { "--version" })
.CaptureStdOut()
.Execute()
.StdOut
.Trim();
}
}
}

View file

@ -16,6 +16,7 @@
"target": "project",
"type": "build"
},
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20100",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-173361-36"
},