Exemplo n.º 1
0
        public ComputerSpecifications()
        {
            var info = MachineInformationGatherer.GatherInformation();

            MemoryMBytes = (ulong)info.RAMSticks.Select(i => (long)i.Capacity).Sum();
            NumberOfLogicalProcessors = Environment.ProcessorCount;

            OperatingSystem            = info.OperatingSystem.Platform.ToString();
            OperatingSystemVersion     = info.OperatingSystem.VersionString;
            OperatingSystemServicePack = info.OperatingSystem.ServicePack;

            NumberOfProcessors = Environment.ProcessorCount;

            ProcessorName          = info.Cpu.Name;
            ProcessorDescription   = info.Cpu.Vendor;
            ProcessorClockSpeedMhz = (int)info.Cpu.MaxClockSpeed;
            L1KBytes            = info.Cpu.Caches.First(c => c.Level == Cache.CacheLevel.LEVEL1).Capacity;
            L2KBytes            = info.Cpu.Caches.First(c => c.Level == Cache.CacheLevel.LEVEL2).Capacity;
            L3KBytes            = info.Cpu.Caches.First(c => c.Level == Cache.CacheLevel.LEVEL3).Capacity;
            NumberOfCores       = info.Cpu.PhysicalCores;
            ClrVersion          = RuntimeInformation.GetClrVersion();
            Architecture        = GetArchitecture();
            HasAttachedDebugger = Debugger.IsAttached;
            HasRyuJit           = RuntimeInformation.HasRyuJit();
            Configuration       = RuntimeInformation.GetConfiguration();
        }
Exemplo n.º 2
0
        public static async Task <UploadedResponse> UploadResults()
        {
            try
            {
                var machineInformation = MachineInformationGatherer.GatherInformation(false);

                if (!CheckValidSave(machineInformation))
                {
                    return(null);
                }

                save.MachineInformation = machineInformation;

                var response = await ResultUploader.UploadResult(save).ConfigureAwait(false);

                save.UUID     = response.UUID;
                save.Uploaded = response.Uploaded;

                return(response);
            }
            catch (HttpRequestException)
            {
                // Intentionally left empty
            }

            return(null);
        }
Exemplo n.º 3
0
 public CurrentProfile()
 {
     _machineInformation = MachineInformationGatherer.GatherInformation();
     ListBenchmarks      = new List <BenchmarkResult>();
     Cpu         = _machineInformation.Cpu;
     Gpus        = _machineInformation.Gpus;
     Motherboard = _machineInformation.SmBios;
     RAMSticks   = _machineInformation.RAMSticks;
 }
Exemplo n.º 4
0
        private static void LoadSave()
        {
            try
            {
                if (File.Exists("./save.json"))
                {
                    save = JsonConvert.DeserializeObject <Save>(File.ReadAllText("./save.json"));

                    File.Delete("./save.json");

                    SaveResults();
                }

                if (File.Exists("./save.benchmark"))
                {
                    save = JsonConvert.DeserializeObject <Save>(
                        Encoding.UTF8.GetString(Convert.FromBase64String(File.ReadAllText("./save.benchmark"))));

                    File.Delete("./save.benchmark");

                    SaveResults();
                }

                if (File.Exists(SAVE_FILE))
                {
                    save = JsonConvert.DeserializeObject <Save>(
                        Encoding.UTF8.GetString(Convert.FromBase64String(File.ReadAllText(SAVE_FILE))));
                }
            }
            catch
            {
                Console.WriteLine("Exception occured accessing your save. Repairing....");
            }

            if (save == null)
            {
                save = new Save
                {
                    MachineInformation = MachineInformationGatherer.GatherInformation(),
                    Version            = Assembly.GetExecutingAssembly().GetName().Version,
                    DotNetVersion      = RuntimeInformation.FrameworkDescription
                };
            }
        }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.FirstChanceException += CurrentDomainOnFirstChanceException;
            Console.WriteLine(
                JsonConvert.SerializeObject(
                    MachineInformationGatherer.GatherInformation(logger: Logger),
                    new StringEnumConverter()
                )
            );

            foreach (var exception in exceptions)
            {
                Logger.LogCritical(exception, "First Chance");
            }

            if (exceptions.Count > 0)
            {
                throw new Exception("F**k");
            }
        }
Exemplo n.º 6
0
        public static bool Init(Options options)
        {
            if (!Directory.Exists(SAVE_DIRECTORY))
            {
                var directory = Directory.CreateDirectory(SAVE_DIRECTORY);

                directory.Attributes |= FileAttributes.Hidden;
            }

            LoadSave();

            // Prune invalid results
            foreach (var resultsValue in save.Results.Values)
            {
                resultsValue.RemoveAll(item => item == null);
            }

            AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnProcessExit;

            // Skip checks if they only want to view their results
            if (!options.ListResults)
            {
                var machineInformation = MachineInformationGatherer.GatherInformation();

                if (!CheckValidSave(machineInformation))
                {
                    SaveResults($"save-{GetBootTime().ToBinary()}.old.benchmark");
                    save.Results.Clear();
                    save.MachineInformation = machineInformation;
                    save.Version            = Assembly.GetExecutingAssembly().GetName().Version;
                    save.DotNetVersion      = RuntimeInformation.FrameworkDescription;

                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        private static void Main(string[] args)
        {
            var saver = new ResultSaver();

            AppDomain.CurrentDomain.ProcessExit +=
                (sender, eventArgs) => CurrentDomainOnProcessExit(sender, eventArgs, saver);
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;

            var options = GetOptions(args);

            if (options is null)
            {
                return;
            }

            Console.WriteLine("Gathering hardware information...");
            var information = MachineInformationGatherer.GatherInformation();

            Console.WriteLine("OS:             {0}", information.OperatingSystem);
            Console.WriteLine("Processor:      {0}", information.Cpu.Name);
            Console.WriteLine("Architecture:   {0}", information.Cpu.Architecture);
            Console.WriteLine("Logical Cores:  {0}", information.Cpu.LogicalCores);
            Console.WriteLine("Physical Cores: {0}", information.Cpu.PhysicalCores);
            Console.WriteLine();
            Console.WriteLine("Starting Benchmark...");
            Console.WriteLine();

            var runner = new Runner(options, new NullLogger <Runner>());

            Console.WriteLine("Running the following benchmarks in approx. {1}: {0}",
                              string.Join(", ", runner.GetBenchmarksToRun().Select(benchmark => benchmark.GetName())),
                              Helper.FormatTime(runner.GetTotalTime()));
            Console.WriteLine();
            Console.WriteLine();

            using var ct = new CancellationTokenSource();
            var t = new Thread(() => DisplayProgressbar(ref runner, ref options, ct.Token));

            t.Start();

            runner.RunBenchmarks();
            ct.Cancel();
            t.Join();

            saver.CreateOrUpdateSaveForCurrentRun(information, runner.Results);
            var save = saver.GetSave("current");

            if (save is null)
            {
                return;
            }

            Console.WriteLine();
            Console.WriteLine(
                Util.FormatResults(new Dictionary <int, List <Result> >
            {
                { 1, save.SingleThreadedResults },
                { Environment.ProcessorCount, save.MultiThreadedResults }
            }));
            Console.WriteLine();
        }
Exemplo n.º 8
0
 protected BaseInformationsService()
 {
     _machineInformation = MachineInformationGatherer.GatherInformation();
 }
Exemplo n.º 9
0
 private static void Main(string[] args)
 {
     Console.WriteLine(JsonConvert.SerializeObject(MachineInformationGatherer.GatherInformation(),
                                                   new StringEnumConverter()));
 }
Exemplo n.º 10
0
        private static void Main(string[] args)
        {
            var options = new Options();

#if RELEASE
            Parser.Default.ParseArguments <Options>(args).WithParsed(opts =>
            {
                options = opts;

                if (opts == null)
                {
                    return;
                }

                if (opts.Threads == 0)
                {
                    if (opts.Multithreaded)
                    {
                        options.Threads = (uint)Environment.ProcessorCount;
                    }
                    else
                    {
                        options.Threads = 1;
                    }
                }
            });

            if (args.Contains("--help") || args.Contains("-h"))
            {
                return;
            }

            if (options.ClearSave)
            {
                ResultSaver.Clear();

                Console.WriteLine("Successfully cleared all saved data!");
                Console.ReadLine();

                return;
            }
#else
            options = new Options {
                Benchmark = "avx2int", Threads = 1, Runs = 1
            };
#endif

            if (!OptionParser.ParseOptions(options))
            {
                Console.ReadLine();

                return;
            }

            Console.WriteLine("Gathering hardware information...");

            var information = MachineInformationGatherer.GatherInformation();

            Console.WriteLine("OS:             {0}", information.OperatingSystem);
            Console.WriteLine("Processor:      {0}", information.Cpu.Name);
            Console.WriteLine("Architecture:   {0}", information.Cpu.Architecture);
            Console.WriteLine("Logical Cores:  {0}", information.Cpu.LogicalCores);
            Console.WriteLine("Physical Cores: {0}", information.Cpu.PhysicalCores);

            Console.WriteLine();

            if (options.Stress)
            {
                var cancellationTokenSource = new CancellationTokenSource();
                var consoleTask             = Task.Run(() =>
                {
                    Thread.CurrentThread.Priority = ThreadPriority.Highest;
                    Console.WriteLine("Press any key to stop the stress test.");
                    Console.ReadKey(true);

                    cancellationTokenSource.Cancel();
                });

                var stressTester = new StressTestRunner(options);
                stressTester.Prepare();
                var completed = stressTester.RunStressTest(cancellationTokenSource.Token);

                Task.WaitAll(consoleTask);

                Console.WriteLine("You've completed {0} benchmark iteration{1}; ~{2} per thread.", completed,
                                  completed == 1 ? "" : "s",
                                  Math.Round(completed / (double)options.Threads, 2));

                return;
            }

            Console.WriteLine("Starting Benchmark...");

            Console.WriteLine();

            ResultSaver.Init(options);

            var runner = new BenchmarkRunner(options, information);

            runner.Prepare();

            var poptions = new ProgressBarOptions
            {
                ForegroundColor      = ConsoleColor.Yellow,
                BackgroundColor      = ConsoleColor.DarkYellow,
                ProgressCharacter    = '─',
                ProgressBarOnBottom  = true,
                CollapseWhenFinished = false
            };

            using (var pbar = new ProgressBar((int)BenchmarkRunner.TotalOverall,
                                              $"Running Benchmark {options.Benchmark} on {options.Threads} threads {options.Runs} times", poptions))
            {
                using var ct = new CancellationTokenSource();
                var t = Task.Run(() =>
                {
                    Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

                    while (!ct.IsCancellationRequested)
                    {
                        lock (BenchmarkRunner.CurrentRunningBenchmark)
                        {
                            pbar.Tick(BenchmarkRunner.FinishedOverall,
                                      $"Overall. Currently running {BenchmarkRunner.CurrentRunningBenchmark} on {options.Threads} threads {options.Runs} times");
                        }

                        Thread.Sleep(200);
                    }
                }, ct.Token);

                try
                {
                    runner.RunBenchmark();
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);

                    return;
                }

                pbar.Tick((int)BenchmarkRunner.TotalOverall);

                ct.Cancel();
                pbar.Tick((int)BenchmarkRunner.TotalOverall);
                t.GetAwaiter().GetResult();
            }

            Console.WriteLine();

            Console.WriteLine(
                Util.FormatResults(new Dictionary <uint, List <Result> > {
                { options.Threads, runner.Results }
            }));

            Console.ReadLine();
        }