Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<PackageVersion Include="Nice3point.Revit.Api.RevitAPI" Version="$(RevitVersion).*" Condition="$(RevitVersion) != ''"/>
<PackageVersion Include="Nice3point.Revit.Api.RevitAPIUI" Version="$(RevitVersion).*" Condition="$(RevitVersion) != ''"/>

<PackageVersion Include="Nice3point.Revit.Injector" Version="2021.1.10" Condition="$(RevitVersion) == '2021'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2022.1.10" Condition="$(RevitVersion) == '2022'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2023.1.10" Condition="$(RevitVersion) == '2023'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2024.1.10" Condition="$(RevitVersion) == '2024'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2025.1.10" Condition="$(RevitVersion) == '2025'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2026.1.10" Condition="$(RevitVersion) == '2026'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2027.0.10" Condition="$(RevitVersion) == '2027'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2021.1.11" Condition="$(RevitVersion) == '2021'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2022.1.11" Condition="$(RevitVersion) == '2022'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2023.1.11" Condition="$(RevitVersion) == '2023'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2024.1.11" Condition="$(RevitVersion) == '2024'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2025.1.11" Condition="$(RevitVersion) == '2025'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2026.1.11" Condition="$(RevitVersion) == '2026'"/>
<PackageVersion Include="Nice3point.Revit.Injector" Version="2027.0.11" Condition="$(RevitVersion) == '2027'"/>
</ItemGroup>

<!-- Core dependencies -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;

namespace Nice3point.BenchmarkDotNet.Revit.Hosting;

/// <summary>
/// Provides the facts about the BenchmarkDotNet host process.
/// </summary>
internal static class BenchmarkHostProcess
{
private const string GeneratedProgramTypeName = "BenchmarkDotNet.Autogenerated.UniqueProgramName";

/// <summary>
/// Gets a value indicating whether the current process is the BenchmarkDotNet host process.
/// </summary>
/// <value>
/// <see langword="false" /> in a benchmark process that runs a generated program, and inside Revit.
/// </value>
public static bool IsCurrent { get; } = Assembly.GetEntryAssembly() is { } entryAssembly && entryAssembly.GetType(GeneratedProgramTypeName) is null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Nice3point.BenchmarkDotNet.Revit.Hosting;

/// <summary>
/// Starts the profiler attach thread of the .NET Framework runtime in every benchmark process.
/// </summary>
/// <remarks>
/// A .NET Framework benchmark process with Revit answers a profiler attach request only on the attach thread.
/// The runtime reads the setting when it starts.
/// A benchmark process inherits the setting from the BenchmarkDotNet host process.
/// </remarks>
internal static class ProfilerAttachThread
{
/// <summary>
/// Enables the profiler attach thread for the benchmark processes the host process starts.
/// </summary>
/// <remarks>
/// The call has no effect outside the BenchmarkDotNet host process and on .NET.
/// </remarks>
public static void Enable()
{
#if NETFRAMEWORK
if (BenchmarkHostProcess.IsCurrent)
{
Environment.SetEnvironmentVariable("COMPlus_AttachThreadAlwaysOn", "1");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace Nice3point.BenchmarkDotNet.Revit.Hosting;
internal static class RevitUiMetadataResolver
{
private const string AssemblyName = "RevitAPIUI";
private const string GeneratedProgramTypeName = "BenchmarkDotNet.Autogenerated.UniqueProgramName";

// IMAGE_COR20_HEADER offsets.
private const int CorFlagsOffset = 16;
Expand Down Expand Up @@ -57,7 +56,7 @@ internal static class RevitUiMetadataResolver
/// </remarks>
public static void Register()
{
if (Assembly.GetEntryAssembly() is not { } entryAssembly || entryAssembly.GetType(GeneratedProgramTypeName) is not null)
if (!BenchmarkHostProcess.IsCurrent)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class RevitApplicationBenchmark
/// The runtime calls the method once per process, when the module loads.
/// The method sets the STA apartment state of the current thread and initializes the injector.
/// In the BenchmarkDotNet host process, the method registers the resolver of the RevitAPIUI metadata.
/// On .NET Framework, the host process enables the profiler attach thread of the benchmark processes.
/// Inside Revit, the method has no effect.
/// </remarks>
#pragma warning disable CA2255
Expand All @@ -49,6 +50,7 @@ public static void Initialize()
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

RevitUiMetadataResolver.Register();
ProfilerAttachThread.Enable();
InjectorInitializer.InitializeModule();
}

Expand Down
Loading