Skip to content

Commit b8a1fa5

Browse files
authored
[Perf] Print loaded assembly versions (Azure#19122)
1 parent ffd81dc commit b8a1fa5

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

common/Perf/Azure.Test.Perf/PerfProgram.cs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@ private static async Task Run(Type testType, PerfOptions options)
6868
Console.WriteLine("Application started.");
6969
}
7070

71-
Console.WriteLine("=== Versions ===");
72-
Console.WriteLine($"Runtime: {Environment.Version}");
73-
var azureAssemblies = testType.Assembly.GetReferencedAssemblies()
74-
.Where(a => a.Name.StartsWith("Azure", StringComparison.OrdinalIgnoreCase) || a.Name.StartsWith("Microsoft.Azure", StringComparison.OrdinalIgnoreCase))
75-
.Where(a => !a.Name.Equals("Azure.Test.Perf", StringComparison.OrdinalIgnoreCase))
76-
.OrderBy(a => a.Name);
77-
foreach (var a in azureAssemblies)
78-
{
79-
var informationalVersion = FileVersionInfo.GetVersionInfo(Assembly.Load(a).Location).ProductVersion;
80-
Console.WriteLine($"{a.Name}: {a.Version} ({informationalVersion})");
81-
}
82-
Console.WriteLine();
83-
8471
Console.WriteLine("=== Options ===");
8572
Console.WriteLine(JsonSerializer.Serialize(options, options.GetType(), new JsonSerializerOptions()
8673
{
@@ -181,6 +168,46 @@ private static async Task Run(Type testType, PerfOptions options)
181168
{
182169
cleanupStatusThread.Join();
183170
}
171+
172+
// I would prefer to print assembly versions at the start of testing, but they cannot be determined until
173+
// code in each assembly has been executed, so this must wait until after testing is complete.
174+
PrintAssemblyVersions(testType);
175+
}
176+
177+
private static void PrintAssemblyVersions(Type testType)
178+
{
179+
Console.WriteLine("=== Versions ===");
180+
181+
Console.WriteLine($"Runtime: {Environment.Version}");
182+
183+
var referencedAssemblies = testType.Assembly.GetReferencedAssemblies();
184+
185+
var azureLoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies()
186+
// Include all Track1 and Track2 assemblies
187+
.Where(a => a.GetName().Name.StartsWith("Azure", StringComparison.OrdinalIgnoreCase) ||
188+
a.GetName().Name.StartsWith("Microsoft.Azure", StringComparison.OrdinalIgnoreCase))
189+
// Exclude this perf framework
190+
.Where(a => a != Assembly.GetExecutingAssembly())
191+
// Exclude assembly containing the perf test itself
192+
.Where(a => a != testType.Assembly)
193+
// Exclude Azure.Core.TestFramework since it is only used to setup environment and should not impact results
194+
.Where(a => !a.GetName().Name.Equals("Azure.Core.TestFramework", StringComparison.OrdinalIgnoreCase))
195+
.OrderBy(a => a.GetName().Name);
196+
197+
foreach (var a in azureLoadedAssemblies)
198+
{
199+
var name = a.GetName().Name;
200+
var referencedVersion = referencedAssemblies.Where(r => r.Name == name).SingleOrDefault()?.Version;
201+
var loadedVersion = a.GetName().Version;
202+
var informationalVersion = FileVersionInfo.GetVersionInfo(a.Location).ProductVersion;
203+
204+
Console.WriteLine($"{name}:");
205+
Console.WriteLine($" Referenced: {referencedVersion}");
206+
Console.WriteLine($" Loaded: {loadedVersion}");
207+
Console.WriteLine($" Informational: {informationalVersion}");
208+
}
209+
210+
Console.WriteLine();
184211
}
185212

186213
private static async Task RunTestsAsync(IPerfTest[] tests, PerfOptions options, string title, bool warmup = false)

0 commit comments

Comments
 (0)