2 using System
.Diagnostics
;
7 // Shut up CLS compliance warnings from Json.NET.
8 [assembly
: CLSCompliant (true)]
10 namespace Mono
.Profiling
.Tests
.Stress
{
12 // https://github.com/xamarin/benchmarker/blob/master/tools/libdbmodel/Benchmark.cs
14 public string Name { get; set; }
15 public string TestDirectory { get; set; }
16 public bool OnlyExplicit { get; set; }
17 public string[] CommandLine { get; set; }
18 public string[] ClientCommandLine { get; set; }
19 public string[] AOTAssemblies { get; set; }
21 public static Benchmark
Load (string file
)
23 return JsonConvert
.DeserializeObject
<Benchmark
> (File
.ReadAllText (file
));
27 static class Program
{
31 var depDir
= Path
.Combine ("..", "external", "benchmarker");
32 var benchDir
= Path
.Combine (depDir
, "benchmarks");
33 var testDir
= Path
.Combine (depDir
, "tests");
35 var benchmarks
= Directory
.EnumerateFiles (benchDir
, "*.benchmark")
36 .Select (Benchmark
.Load
)
37 .Where (b
=> !b
.OnlyExplicit
&& b
.ClientCommandLine
== null)
38 .OrderBy (b
=> b
.Name
)
41 var monoPath
= Path
.GetFullPath (Path
.Combine ("..", "..", "runtime", "mono-wrapper"));
42 var classDir
= Path
.GetFullPath (Path
.Combine ("..", "..", "mcs", "class", "lib", "net_4_x"));
44 var rand
= new Random ();
45 var cpus
= Environment
.ProcessorCount
;
50 var sw
= Stopwatch
.StartNew ();
52 for (var i
= 0; i
< benchmarks
.Length
; i
++) {
53 var bench
= benchmarks
[i
];
55 var sampleFreq
= rand
.Next (0, 1001);
56 var sampleMode
= rand
.Next (0, 2) == 1 ? "real" : "process";
57 var maxSamples
= rand
.Next (0, cpus
* 2000 + 1);
58 var heapShotFreq
= rand
.Next (0, 11);
59 var maxFrames
= rand
.Next (0, 33);
60 var allocMode
= rand
.Next (0, 2) == 1 ? "alloc" : "noalloc";
62 var profOptions
= $"sample=cycles/{sampleFreq},sampling-{sampleMode},maxsamples={maxSamples},heapshot={heapShotFreq}gc,maxframes={maxFrames},{allocMode},output=/dev/null";
64 var info
= new ProcessStartInfo
{
65 UseShellExecute
= false,
66 WorkingDirectory
= Path
.Combine (testDir
, bench
.TestDirectory
),
68 Arguments
= $"--debug --profile=log:{profOptions} " + string.Join (" ", bench
.CommandLine
),
71 info
.EnvironmentVariables
.Clear ();
72 info
.EnvironmentVariables
.Add ("MONO_PATH", classDir
);
74 var progress
= $"({i + 1}/{benchmarks.Length})";
76 Console
.ForegroundColor
= ConsoleColor
.Blue
;
77 Console
.WriteLine ($"[{sw.Elapsed.ToString ("G")}] {progress} Running {bench.Name} with profiler options: {profOptions}");
78 Console
.ResetColor ();
80 var sw2
= Stopwatch
.StartNew ();
82 using (var proc
= Process
.Start (info
)) {
88 if (proc
.ExitCode
!= 0)
93 Console
.ForegroundColor
= proc
.ExitCode
!= 0 ? ConsoleColor
.Red
: ConsoleColor
.Green
;
94 Console
.WriteLine ($"[{sw.Elapsed.ToString ("G")}] {progress} {bench.Name} took {sw2.Elapsed.ToString ("G")} and exited with code: {proc.ExitCode}");
95 Console
.ResetColor ();
101 Console
.ForegroundColor
= failures
!= 0 ? ConsoleColor
.Red
: ConsoleColor
.Green
;
102 Console
.WriteLine ($"[{sw.Elapsed.ToString ("G")}] Finished with {successes}/{benchmarks.Length} passing tests");
103 Console
.ResetColor ();