Repository navigation
Expand file tree
/
Copy pathdiff.cs
More file actions
798 lines (681 loc) · 31.1 KB
/
Copy pathdiff.cs
File metadata and controls
798 lines (681 loc) · 31.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.CommandLine;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ManagedCodeGen
{
using DasmWorkTask = Task<(DasmWorkKind kind, int errorCount)>;
public enum DasmWorkKind
{
Base,
Diff
}
public class ProgressBar
{
static readonly int progressInterval = 100; // update time in ms
static char[] figit = new char[] { '-', '/', '|', '\\' };
readonly DateTime m_start;
public ProgressBar()
{
m_start = DateTime.Now;
}
private static void StartTasks(List<AssemblyInfo> assemblyWorkList, jitdiff.Config config, List<DasmWorkTask> tasks)
{
int counter = 0;
tasks = tasks
// Filter out tasks that have already been started if we're called with the same tasks list multiple times
.Where(t => t.Status == TaskStatus.Created)
// Individual tasks are mainly single-threaded, order them by size to prioritize starting longer tasks earlier
// Assume that tasks were created in the same order as assemblyWorkList
.OrderByDescending(_ => new FileInfo(assemblyWorkList[counter++ % assemblyWorkList.Count].Path).Length)
.ToList();
Task.Run(async () =>
{
// We limit the number of tasks we start in parallel to avoid overwhelming the system.
// E.g. running frameworks diffs involves 100s of tasks, which can be problematic on machines with limited memory.
int parallelism = config.Sequential ? 1 : Environment.ProcessorCount;
bool anyFailed = false;
await Parallel.ForEachAsync(tasks, new ParallelOptions { MaxDegreeOfParallelism = parallelism }, async (task, _) =>
{
if (anyFailed)
{
// We don't have to start other tasks.
return;
}
try
{
task.Start();
await task;
}
catch
{
// AwaitTasksAndShowProgress will observe any failures
anyFailed = true;
}
});
});
}
public void AwaitTasksAndShowProgress(List<AssemblyInfo> assemblyWorkList, jitdiff.Config config,
List<DasmWorkTask> tasks, bool isFinalAwait)
{
StartTasks(assemblyWorkList, config, tasks);
var taskArray = tasks.ToArray();
// If output is redirected, just wait -- don't show any updates
if (Console.IsOutputRedirected)
{
Task.WaitAll(taskArray);
return;
}
// Wake up every so often and update the task bar.
// In verbose mode, only output when there is a change in the number of completed tasks, since
// there is lots of other output already.
int assemblyCount = assemblyWorkList.Count();
int totalBaseTasks = config.DoBaseCompiles ? assemblyCount : 0;
int totalDiffTasks = config.DoDiffCompiles ? assemblyCount : 0;
int previousCompletedBaseTasks = -1;
int previousCompletedDiffTasks = -1;
bool done = false;
int count = 0;
while (!done)
{
done = Task.WaitAll(taskArray, progressInterval);
TimeSpan elapsed = DateTime.Now - m_start;
IEnumerable<DasmWorkTask> completedTasks = taskArray.Where(x => x.IsCompleted);
int completedBaseTasks = completedTasks.Count(x => x.Result.kind == DasmWorkKind.Base);
int completedDiffTasks = completedTasks.Count(x => x.Result.kind == DasmWorkKind.Diff);
if (!config.Verbose || (completedBaseTasks != previousCompletedBaseTasks) || (completedDiffTasks != previousCompletedDiffTasks))
{
Console.CursorLeft = 0;
Console.Write(
$"{figit[count++ % figit.Length]} " +
$"Finished {completedBaseTasks}/{totalBaseTasks} Base " +
$"{completedDiffTasks}/{totalDiffTasks} Diff " +
$"[{((double)elapsed.TotalMilliseconds / 1000.0):F1} sec]");
if (config.Verbose)
{
Console.WriteLine();
}
previousCompletedBaseTasks = completedBaseTasks;
previousCompletedDiffTasks = completedDiffTasks;
}
}
if (isFinalAwait)
{
Console.WriteLine();
}
}
}
public partial class jitdiff
{
public class DasmResult
{
public int BaseErrors = 0;
public int DiffErrors = 0;
public bool CaughtException = false;
public bool Success => ((BaseErrors == 0) && (DiffErrors == 0) && !CaughtException);
}
public abstract class DiffTool
{
private class DasmWorkItem
{
public List<string> DasmArgs { get; set; }
public DasmWorkItem(List<string> dasmArgs)
{
DasmArgs = dasmArgs;
}
}
protected Config m_config;
protected List<DasmWorkTask> DasmWorkTasks = new List<DasmWorkTask>();
protected string m_name;
protected string m_commandName;
public String Name => m_name;
public string CommandName => m_commandName;
protected DiffTool(Config config)
{
m_config = config;
}
protected static DiffTool NewDiffTool(Config config)
{
DiffTool result = null;
switch (config.DoCommand)
{
case Commands.Diff:
result = new CrossgenDiffTool(config);
break;
case Commands.PmiDiff:
result = new PmiDiffTool(config);
break;
default:
Console.WriteLine($"Unexpected command for diff: {config.DoCommand}");
break;
}
return result;
}
// Returns a count of the number of failures.
private int RunDasmTool(DasmWorkItem item)
{
int dasmFailures = 0;
string command = CommandName + " " + String.Join(" ", item.DasmArgs);
if (m_config.Verbose)
{
Console.WriteLine("Dasm command: {0}", command);
}
ProcessResult result = Utility.ExecuteProcess(CommandName, item.DasmArgs);
if (result.ExitCode != 0)
{
Console.Error.WriteLine("Dasm command \"{0}\" returned with {1} failures", command, result.ExitCode);
dasmFailures += result.ExitCode;
}
return dasmFailures;
}
private void StartDasmWork(DasmWorkKind kind, List<string> args)
{
// The task will be started by ProgressBar.AwaitTasksAndShowProgress
var task = new DasmWorkTask(() => (kind, RunDasmTool(new DasmWorkItem(args))));
DasmWorkTasks.Add(task);
}
protected void StartDasmWorkOne(DasmWorkKind kind, List<string> commandArgs, string tagBaseDiff,
string clrPath, AssemblyInfo assemblyInfo)
{
List<string> args = ConstructArgs(commandArgs, clrPath);
string outputPath = Path.Combine(m_config.OutputPath, tagBaseDiff, assemblyInfo.OutputPath);
args.Add("--output");
args.Add(outputPath);
args.Add(assemblyInfo.Path);
StartDasmWork(kind, args);
}
protected virtual void StartDasmWorkBaseDiff(List<string> commandArgs, List<AssemblyInfo> assemblyWorkList)
{
foreach (var assemblyInfo in assemblyWorkList)
{
if (m_config.DoBaseCompiles)
{
StartDasmWorkOne(DasmWorkKind.Base, commandArgs, "base", m_config.BasePath, assemblyInfo);
}
if (m_config.DoDiffCompiles)
{
StartDasmWorkOne(DasmWorkKind.Diff, commandArgs, "diff", m_config.DiffPath, assemblyInfo);
}
}
var progress = new ProgressBar();
progress.AwaitTasksAndShowProgress(assemblyWorkList, m_config, DasmWorkTasks, true);
}
protected abstract List<string> ConstructArgs(List<string> commandArgs, string clrPath);
private DasmResult RunDasmTool(List<string> commandArgs, List<AssemblyInfo> assemblyWorkList)
{
DasmResult result = new DasmResult();
DasmWorkTask[] taskArray = new DasmWorkTask[0];
try
{
StartDasmWorkBaseDiff(commandArgs, assemblyWorkList);
taskArray = DasmWorkTasks.ToArray();
Task.WaitAll(taskArray);
}
catch (AggregateException ex)
{
Console.Error.WriteLine("Dasm task failed with {0}", ex.Message);
result.CaughtException = true;
}
foreach (var t in taskArray)
{
if (t.Result.kind == DasmWorkKind.Base)
{
result.BaseErrors += t.Result.errorCount;
}
else
{
result.DiffErrors += t.Result.errorCount;
}
}
if (!result.Success)
{
Console.Error.WriteLine("Dasm commands returned {0} base failures, {1} diff failures{2}.",
result.BaseErrors, result.DiffErrors, (result.CaughtException ? ", exception occurred" : ""));
}
return result;
}
// Returns 0 on success, 1 on failure.
public static int DiffCommand(Config config)
{
DiffTool diffTool = NewDiffTool(config);
string diffString = $"{diffTool.Name} {config.Metric} Diffs for ";
bool needPrefix = false;
if (config.CoreLib)
{
diffString += "System.Private.CoreLib.dll";
needPrefix = true;
}
else if (config.DoFrameworks)
{
diffString += "System.Private.CoreLib.dll, framework assemblies";
needPrefix = true;
}
if (config.Benchmarks)
{
if (needPrefix) diffString += ", ";
diffString += "benchstones and benchmarks game in " + config.TestRoot;
needPrefix = true;
}
else if (config.DoTestTree)
{
if (needPrefix) diffString += ", ";
diffString += "assemblies in " + config.TestRoot;
needPrefix = true;
}
foreach (string assembly in config.AssemblyList)
{
if (needPrefix) diffString += ", ";
diffString += assembly;
needPrefix = true;
}
Console.WriteLine($"Beginning {diffString}");
// Create subjob that runs jit-dasm or jit-dasm-pmi (which should be in path)
// with the relevent coreclr assemblies/paths.
List<string> commandArgs = new List<string>();
commandArgs.Add("--platform");
commandArgs.Add(config.CoreRoot);
if (config.GenerateGCInfo)
{
commandArgs.Add("--gcinfo");
}
if (config.Tier0)
{
commandArgs.Add("--tier0");
diffString += " [tier0]";
}
if (config.GenerateDebugInfo)
{
commandArgs.Add("--debuginfo");
}
if (config.Verbose)
{
commandArgs.Add("--verbose");
}
if (config.AltJit != null)
{
commandArgs.Add("--altjit");
commandArgs.Add(config.AltJit);
}
if ((config.DoCommand == Commands.PmiDiff) && config.Cctors)
{
commandArgs.Add("--cctors");
diffString += " [invoking .cctors]";
}
DateTime startTime = DateTime.Now;
List<AssemblyInfo> assemblyWorkList = GenerateAssemblyWorklist(config);
DasmResult dasmResult = diffTool.RunDasmTool(commandArgs, assemblyWorkList);
Console.WriteLine($"Completed {diffString} in {(DateTime.Now - startTime).TotalSeconds:F2}s");
string basePath = Path.Combine(config.OutputPath, "base");
string diffPath = Path.Combine(config.OutputPath, "diff");
Console.WriteLine($"Diffs (if any) can be viewed by comparing: {basePath} {diffPath}");
Console.WriteLine("");
Console.WriteLine($"git diff --no-index --diff-filter=M --exit-code --numstat {diffPath} {basePath}");
Console.WriteLine("");
// Analyze completed run.
if (config.DoAnalyze && config.DoDiffCompiles && config.DoBaseCompiles)
{
List<string> analysisArgs = new List<string>();
analysisArgs.Add("--base");
analysisArgs.Add(Path.Combine(config.OutputPath, "base"));
analysisArgs.Add("--diff");
analysisArgs.Add(Path.Combine(config.OutputPath, "diff"));
analysisArgs.Add("--count");
analysisArgs.Add(config.Count.ToString());
analysisArgs.Add("--recursive");
analysisArgs.Add("--metrics");
analysisArgs.Add(config.Metric);
analysisArgs.Add("--note");
string jitName = config.AltJit ?? "default jit";
analysisArgs.Add($"\"{diffString} for {config.Arch} {jitName}\"");
if (config.tsv)
{
analysisArgs.Add("--tsv");
analysisArgs.Add(Path.Combine(config.OutputPath, "diffs.tsv"));
}
if (config.Verbose)
{
Console.WriteLine("Analyze command: {0} {1}",
s_analysisTool, String.Join(" ", analysisArgs));
}
Console.WriteLine($"Analyzing {config.Metric} diffs...");
startTime = DateTime.Now;
ProcessResult analyzeResult = Utility.ExecuteProcess(s_analysisTool, analysisArgs);
Console.WriteLine($"Completed analysis in {(DateTime.Now - startTime).TotalSeconds:F2}s");
}
// Report any failures to generate asm at the very end (again). This is so
// this information doesn't get buried in previous output.
if (!dasmResult.Success)
{
Console.Error.WriteLine("");
Console.Error.WriteLine("Warning: Failures detected generating asm: {0} base, {1} diff{2}",
dasmResult.BaseErrors, dasmResult.DiffErrors, (dasmResult.CaughtException ? ", exception occurred" : ""));
return 1; // failure result
}
else
{
return 0; // success result
}
}
private static int CompareFrameworkAssemblies(AssemblyInfo assemblyInfo1, AssemblyInfo assemblyInfo2)
{
string assembly1 = assemblyInfo1.Path;
if (assembly1 == CoreLibAssemblyName)
{
return -1;
}
string assembly2 = assemblyInfo2.Path;
if (assembly2 == CoreLibAssemblyName)
{
return 1;
}
long length1 = new FileInfo(assembly1).Length;
long length2 = new FileInfo(assembly2).Length;
if (length2 < length1)
{
return -1;
}
else if (length1 < length2)
{
return 1;
}
else
{
return 0;
}
}
public static List<AssemblyInfo> GenerateAssemblyWorklist(Config config)
{
List<AssemblyInfo> assemblyInfoList = new List<AssemblyInfo>();
foreach (string assembly in config.AssemblyList)
{
if (Directory.Exists(assembly))
{
const bool recursive = true;
const string searchPattern = "*";
List<AssemblyInfo> directoryAssemblyInfoList = IdentifyAssemblies(assembly, assembly, config, recursive, searchPattern);
assemblyInfoList.AddRange(directoryAssemblyInfoList);
}
else if (File.Exists(assembly))
{
AssemblyInfo info = new AssemblyInfo
{
Path = assembly,
OutputPath = ""
};
assemblyInfoList.Add(info);
}
else
{
Console.Error.WriteLine($"Warning: can't find specified assembly or directory {assembly}");
}
}
// CoreLib and the frameworks add specific files, not directories.
// These files will all be put in the same output directory. This
// works because they all have unique names, and live in the same
// source directory already.
if (config.CoreLib || config.DoFrameworks)
{
const bool recursive = false;
string searchPattern = config.DoFrameworks ? "*" : CoreLibAssemblyName;
List<AssemblyInfo> directoryAssemblyInfoList = IdentifyAssemblies(config.CoreRoot, config.CoreRoot, config, recursive, searchPattern);
directoryAssemblyInfoList.Sort(CompareFrameworkAssemblies);
// Add info generated at this directory
assemblyInfoList.AddRange(directoryAssemblyInfoList);
}
// The tests are in a tree hierarchy of directories. We will output these to a tree
// structure matching their source tree structure, to avoid name conflicts.
if (config.Benchmarks || config.DoTestTree)
{
string basepath = config.Benchmarks ? Utility.CombinePath(config.TestRoot, s_benchmarksPath) : config.TestRoot;
foreach (var dir in config.Benchmarks ? s_benchmarkDirectories : s_testDirectories)
{
string fullPathDir = Path.Combine(basepath, dir);
if (!Directory.Exists(fullPathDir))
{
Console.Error.WriteLine("Warning: can't find test directory {0}", fullPathDir);
continue;
}
// For the directory case create a stack and recursively find any
// assemblies for compilation.
const bool recursive = true;
const string searchPattern = "*";
List<AssemblyInfo> directoryAssemblyInfoList = IdentifyAssemblies(basepath, fullPathDir, config, recursive, searchPattern);
// Add info generated at this directory
assemblyInfoList.AddRange(directoryAssemblyInfoList);
}
}
return assemblyInfoList;
}
// Recursively search for assemblies from a path given by `rootPath`.
// `basePath` specifies the root directory for the purpose of constructing a relative output path.
// It must be a prefix of `rootPath`.
private static List<AssemblyInfo> IdentifyAssemblies(string basePath, string rootPath, Config config, bool recursive, string searchPattern)
{
List<AssemblyInfo> assemblyInfoList = new List<AssemblyInfo>();
string fullBasePath = Path.GetFullPath(basePath).TrimEnd(Path.DirectorySeparatorChar);
string fullRootPath = Path.GetFullPath(rootPath).TrimEnd(Path.DirectorySeparatorChar);
// Get files that could be assemblies, but discard currently ngen'd assemblies.
SearchOption searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var subFiles = Directory.EnumerateFiles(fullRootPath, searchPattern, searchOption)
.Where(s => (s.EndsWith(".exe") || s.EndsWith(".dll")) && !s.Contains(".ni."));
foreach (var filePath in subFiles)
{
if (config.Verbose)
{
Console.WriteLine("Scanning: {0}", filePath);
}
// Skip assembly with broken references; this can be removed once we eliminate
// this obsolete assembly from the build.
if (Path.GetFileName(filePath).ToLower() == "xunit.performance.api.dll")
{
continue;
}
// Skip if not an assembly
if (!Utility.IsAssembly(filePath))
{
continue;
}
string directoryName = Path.GetDirectoryName(filePath);
string fullDirectoryName = Path.GetFullPath(directoryName);
string outputPath = fullDirectoryName.Substring(fullBasePath.Length).TrimStart(Path.DirectorySeparatorChar);
AssemblyInfo info = new AssemblyInfo
{
Path = filePath,
OutputPath = outputPath
};
assemblyInfoList.Add(info);
}
return assemblyInfoList;
}
}
public class CrossgenDiffTool : DiffTool
{
public CrossgenDiffTool(Config config) : base(config)
{
m_name = "Crossgen";
m_commandName = s_asmToolPrejit;
}
protected override List<string> ConstructArgs(List<string> commandArgs, string clrPath)
{
List<string> dasmArgs = commandArgs.ToList();
dasmArgs.Add("--crossgen");
if (m_config.HasCrossgenExe)
{
dasmArgs.Add(m_config.CrossgenExe);
}
else
{
var crossgenPath = Path.Combine(m_config.CoreRoot, GetCrossgenExecutableName(m_config.PlatformMoniker));
if (!File.Exists(crossgenPath))
{
Console.Error.WriteLine("crossgen not found at {0}", crossgenPath);
return null;
}
dasmArgs.Add(crossgenPath);
}
string jitName;
if (m_config.AltJit != null)
{
jitName = m_config.AltJit;
}
else
{
jitName = GetJitLibraryName(m_config.PlatformMoniker);
}
var jitPath = Path.Combine(clrPath, jitName);
if (!File.Exists(jitPath))
{
Console.Error.WriteLine("JIT not found at {0}", jitPath);
return null;
}
dasmArgs.Add("--jit");
dasmArgs.Add(jitPath);
if (m_config.NoDiffable)
{
dasmArgs.Add("--nodiffable");
}
return dasmArgs;
}
}
public class PmiDiffTool : DiffTool
{
string m_corerunPath;
string m_defaultJitName;
string m_testJitName;
public PmiDiffTool(Config config) : base(config)
{
m_name = "PMI";
m_commandName = s_asmToolJit;
m_corerunPath = Path.Combine(m_config.CoreRoot, GetCorerunExecutableName(m_config.PlatformMoniker));
m_defaultJitName = GetJitLibraryName(m_config.PlatformMoniker);
if (m_config.AltJit != null)
{
m_testJitName = m_config.AltJit;
}
else
{
m_testJitName = m_defaultJitName;
}
}
protected override List<string> ConstructArgs(List<string> commandArgs, string clrPath)
{
List<string> dasmArgs = commandArgs.ToList();
dasmArgs.Add("--corerun");
if (!File.Exists(m_corerunPath))
{
Console.Error.WriteLine($"corerun not found at {m_corerunPath}");
return null;
}
dasmArgs.Add(m_corerunPath);
var jitPath = Path.Combine(clrPath, m_testJitName);
if (!File.Exists(jitPath))
{
Console.Error.WriteLine($"JIT not found at {jitPath}");
return null;
}
dasmArgs.Add("--jit");
dasmArgs.Add(jitPath);
// jit-diffs will handle installing the right jit
dasmArgs.Add("--nocopy");
if (m_config.NoDiffable)
{
dasmArgs.Add("--nodiffable");
}
return dasmArgs;
}
void InstallBaseJit()
{
string existingJitPath = Path.Combine(m_config.CoreRoot, m_testJitName);
string backupJitPath = Path.Combine(m_config.CoreRoot, "backup-" + m_testJitName);
string testJitPath = Path.Combine(m_config.BasePath, m_testJitName);
if (File.Exists(existingJitPath))
{
if (m_config.Verbose)
{
Console.WriteLine($"Saving off existing jit: {existingJitPath} ==> {backupJitPath}");
}
File.Copy(existingJitPath, backupJitPath, true);
}
if (m_config.Verbose)
{
Console.WriteLine($"Copying in the test jit: {testJitPath} ==> {existingJitPath}");
}
File.Copy(testJitPath, existingJitPath, true);
}
void InstallDiffJit()
{
string exitingJitPath = Path.Combine(m_config.CoreRoot, m_testJitName);
string backupJitPath = Path.Combine(m_config.CoreRoot, "backup-" + m_testJitName);
string testJitPath = Path.Combine(m_config.DiffPath, m_testJitName);
if (File.Exists(exitingJitPath))
{
if (m_config.Verbose)
{
Console.WriteLine($"Saving off existing jit: {exitingJitPath} ==> {backupJitPath}");
}
File.Copy(exitingJitPath, backupJitPath, true);
}
if (m_config.Verbose)
{
Console.WriteLine($"Copying in the test jit: {testJitPath} ==> {exitingJitPath}");
}
File.Copy(testJitPath, exitingJitPath, true);
}
void RestoreDefaultJit()
{
string existingJitPath = Path.Combine(m_config.CoreRoot, m_testJitName);
string backupJitPath = Path.Combine(m_config.CoreRoot, "backup-" + m_testJitName);
if (File.Exists(backupJitPath))
{
if (m_config.Verbose)
{
Console.WriteLine($"Restoring existing jit: {backupJitPath} ==> {existingJitPath}");
}
File.Copy(backupJitPath, existingJitPath, true);
}
}
// Because pmi modifies the test overlay, we can't run base and diff tasks in an interleaved manner.
protected override void StartDasmWorkBaseDiff(List<string> commandArgs, List<AssemblyInfo> assemblyWorkList)
{
var progressBar = new ProgressBar();
if (m_config.DoBaseCompiles)
{
try
{
InstallBaseJit();
foreach (var assemblyInfo in assemblyWorkList)
{
StartDasmWorkOne(DasmWorkKind.Base, commandArgs, "base", m_config.BasePath, assemblyInfo);
}
progressBar.AwaitTasksAndShowProgress(assemblyWorkList, m_config, DasmWorkTasks, !m_config.DoDiffCompiles);
}
finally
{
RestoreDefaultJit();
}
}
if (m_config.DoDiffCompiles)
{
try
{
InstallDiffJit();
foreach (var assemblyInfo in assemblyWorkList)
{
StartDasmWorkOne(DasmWorkKind.Diff, commandArgs, "diff", m_config.DiffPath, assemblyInfo);
}
progressBar.AwaitTasksAndShowProgress(assemblyWorkList, m_config, DasmWorkTasks, true);
}
finally
{
RestoreDefaultJit();
}
}
}
}
}
}