public Task Start(CancellationToken token)
        {
            var random = new Random();

            var numberOfSteps = 7;

            var overProgressOptions = new ProgressBarOptions
            {
                BackgroundColor = ConsoleColor.DarkGray,
            };

            using (var pbar = new ProgressBar(numberOfSteps, "overal progress", overProgressOptions))
            {
                var stepBarOptions = new ProgressBarOptions
                {
                    ForeGroundColor = ConsoleColor.Cyan,
                    ForeGroundColorDone = ConsoleColor.DarkGreen,
                    ProgressCharacter = '─',
                    BackgroundColor = ConsoleColor.DarkGray,
                    CollapseWhenFinished = false,

                } ;
                Parallel.For(0, numberOfSteps, (i) =>
                {
                    var workBarOptions = new ProgressBarOptions
                    {
                        ForeGroundColor = ConsoleColor.Yellow,
                        ProgressCharacter = '─',
                        BackgroundColor = ConsoleColor.DarkGray,
                    };
                    var childSteps = random.Next(1, 5);
                    using (var childProgress = pbar.Spawn(childSteps, $"step {i} progress", stepBarOptions))
                        Parallel.For(0, childSteps, (ci) =>
                        {
                            var childTicks = random.Next(50, 250);
                            using (var innerChildProgress = childProgress.Spawn(childTicks, $"step {i}::{ci} progress", workBarOptions))
                            {
                                for (var r = 0; r < childTicks; r++)
                                {
                                    innerChildProgress.Tick();
                                    Program.BusyWait(50);
                                }
                            }
                            childProgress.Tick();
                        });

                    pbar.Tick();
                });
            }
            return Task.FromResult(1);
        }
 public Task Start(CancellationToken token)
 {
     var ticks = 5;
     var updateOnTicksOnlyOptions = new ProgressBarOptions {DisplayTimeInRealTime = false};
     using (var pbar = new ProgressBar(ticks, "only update time on ticks", updateOnTicksOnlyOptions))
     {
         for (var i = 0; i < ticks; i++)
         {
             pbar.Tick("only update time on ticks, current: " + i);
             Thread.Sleep(1750);
         }
     }
     return Task.FromResult(1);
 }
        private static void InnerInnerProgressBars(ChildProgressBar pbar)
        {
            var progressBarOption = new ProgressBarOptions { ForeGroundColor = ConsoleColor.Yellow };
            var innerProgressBars = Enumerable.Range(0, new Random().Next(1, 3))
                .Select(s => pbar.Spawn(new Random().Next(5, 10), $"inner bar {s}", progressBarOption))
                .ToList();
            if (!innerProgressBars.Any()) return;

            var maxTicks = innerProgressBars.Max(p => p.MaxTicks);

            for (var ii = 0; ii < maxTicks; ii++)
            {
                foreach (var p in innerProgressBars)
                    p.Tick();
            }
            foreach (var p in innerProgressBars) p.Dispose();
        }
        private static string appendRows(List <DataTableColumn> columns)
        {
            var rowsCount  = columns[0].Values.Count;
            var rowsString = "";

            int totalTicks = rowsCount;
            var options    = new ProgressBarOptions {
                ProgressCharacter   = '─',
                ProgressBarOnBottom = true
            };

            using (var pbar = new ProgressBar(totalTicks, "progress", options)) {
                for (var i = 0; i < rowsCount; i++)
                {
                    foreach (var col in columns)
                    {
                        var value = col.Values[i];
                        if (string.IsNullOrEmpty(value))
                        {
                            rowsString += "'',";
                            continue;
                        }

                        if (value.Contains("-"))
                        {
                            rowsString += "'" + value + "',";
                            continue;
                        }

                        switch (col.Type)
                        {
                        case DataType.Boolean:
                            rowsString += value + ",";
                            break;

                        case DataType.Datetime:
                            rowsString += "'" + value + "',";
                            break;

                        case DataType.Double:
                            rowsString += value + ",";
                            break;

                        case DataType.Int:
                            rowsString += value + ",";
                            break;

                        case DataType.String:
                            rowsString += "'" + value + "',";
                            break;
                        }
                        ;
                    }

                    pbar.Tick();
                    rowsString += Environment.NewLine;
                    if (rowsString.Length > 2095000)
                    {
                        break;
                    }
                }
            }

            rowsString = rowsString.Substring(0, rowsString.Length - 3);
            return(rowsString);
        }
示例#5
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();
        }
示例#6
0
        /// <summary>
        /// Process the exportation
        /// </summary>
        /// <returns><see cref="Task"/></returns>
        public async Task Export()
        {
            try
            {
                var loggingTraceBegin =
                    $@"Export started at {
                            DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.fff",
                                CultureInfo.InvariantCulture)
                        }";
                _loggingService.Telemetry.TrackTrace(loggingTraceBegin);
                Console.WriteLine(loggingTraceBegin);
                var exports             = new[] { ExportType.Movies, ExportType.Shows };
                var overProgressOptions = new ProgressBarOptions
                {
                    BackgroundColor = ConsoleColor.DarkGray
                };
                using (var pbar = Schim.ProgressBar.Create(exports.Length * 2, "overall progress", overProgressOptions))
                {
                    foreach (var export in exports)
                    {
                        var stepBarOptions = new ProgressBarOptions
                        {
                            ForegroundColor     = ConsoleColor.Cyan,
                            ForegroundColorDone = ConsoleColor.DarkGreen,
                            ProgressCharacter   = '─',
                            BackgroundColor     = ConsoleColor.DarkGray,
                        };
                        using (var childProgress = pbar.Spawn(2,
                                                              $"step {export.ToFriendlyString().ToLowerInvariant()} progress", stepBarOptions))
                        {
                            // Load export
                            var imports = await _exportService.LoadExport(export, childProgress)
                            ;

                            pbar.Tick();
                            IImportService importService;
                            // Import the documents according to export type
                            switch (export)
                            {
                            case ExportType.Shows:
                                importService = new ImportShowService(
                                    new AssetsShowService(_loggingService, _fileService),
                                    _loggingService, _fileService);
                                break;

                            case ExportType.Movies:
                                importService = new ImportMovieService(
                                    new AssetsMovieService(_loggingService, _fileService),
                                    _loggingService, _fileService);
                                break;

                            default:
                                throw new NotImplementedException();
                            }

                            await importService.Import(imports, childProgress);

                            pbar.Tick();
                        }
                    }
                }

                await _cachingService.Flush();

                var loggingTraceEnd =
                    $@"Export ended at {
                            DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture)
                        }";
                _loggingService.Telemetry.TrackTrace(loggingTraceEnd);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                _loggingService.Telemetry.TrackException(ex);
            }
        }
示例#7
0
        private void Publish(Task task, CancellationToken cancellationToken)
        {
            var options = new ProgressBarOptions
            {
                ProgressCharacter    = '─',
                ProgressBarOnBottom  = true,
                CollapseWhenFinished = true
            };

            using (var pbar = new ProgressBar(settings.MessagesCount + 1,
                                              "Starting to publish messages...", options))
            {
                //Console.WriteLine("Starting to publish messages...");

                ackCount            = 0;
                nackCount           = 0;
                outstandingConfirms = new ConcurrentDictionary <ulong, string>();

                pbar.Tick("Connecting to RabbitMQ...");

                var factory = new ConnectionFactory {
                    UserName = settings.UserName, Password = settings.Password
                };
                using (var connection = factory.CreateConnection(settings.HostName.Split(",", StringSplitOptions.RemoveEmptyEntries)))
                    using (var channel = connection.CreateModel())
                    {
                        channel.ConfirmSelect();

                        channel.BasicAcks += (sender, ea) =>
                        {
                            ackCount += CountConfirms(ea.DeliveryTag, ea.Multiple);
                        };

                        channel.BasicNacks += (sender, ea) =>
                        {
                            nackCount += CountConfirms(ea.DeliveryTag, ea.Multiple);
                        };

                        channel.QueueDeclare(queue: settings.QueueName,
                                             durable: false,
                                             exclusive: false,
                                             autoDelete: false,
                                             arguments: null);

                        for (int i = 0; i < settings.MessagesCount; i++)
                        {
                            if (cancellationToken.IsCancellationRequested)
                            {
                                break;
                            }

                            string message = $"Message {i}";
                            var    body    = Encoding.UTF8.GetBytes(message);
                            outstandingConfirms.TryAdd(channel.NextPublishSeqNo, message);
                            channel.BasicPublish(exchange: settings.ExchangeName,
                                                 routingKey: settings.RoutingKey,
                                                 basicProperties: null,
                                                 body: body);

                            pbar.Tick($"Publishing message: {message}...");
                            //Console.WriteLine($"Publishing message: {message}");

                            Thread.Sleep(settings.SleepTimeBetweenPublishes);
                        }

                        channel.WaitForConfirmsOrDie(TimeSpan.FromMilliseconds(settings.PublishConfirmTimeout));

                        pbar.Tick(pbar.MaxTicks, $"Finished, ACK {ackCount}, NACK {nackCount}...");
                    }

                //Console.WriteLine("Messages published...");

                //Console.WriteLine("- Messages ACK {0}", ackCount);
                //Console.WriteLine("- Messages NACK {0}", nackCount);

                if (cancellationToken.IsCancellationRequested)
                {
                    throw new TaskCanceledException(task);
                }
            }
        }