Esempio n. 1
0
        private static double Learn(ImageBatch imb, LabelBatch lab, int x, Net net)
        {
            int    correctNum = 0;
            double costSum    = 0;

            for (int i = x * MINIBATCH_SIZE; i < x * MINIBATCH_SIZE + MINIBATCH_SIZE; i++)
            {
                formChanger.ChangeImage(imb[i].GetBitmap(), lab[i] + "     (" + (i + 1) + "/" + imb.Count() + ")");
                net.LoadSource(imb[i], lab[i]);               //载入样本
                var isCorrect = net.BeginReason(out var say); //正推
                var cost      = net.Evaluation();             //计算cost
                costSum += cost;
                formChanger.AddNeuronNote(net, lab[i], say, cost);
                net.Recall();//反向传播
                if (isCorrect)
                {
                    correctNum++;
                }
                PrintInForm(isCorrect, say, cost);
            }

            var averageCost = costSum / MINIBATCH_SIZE;

            formChanger.AddCost(averageCost, Convert.ToDouble(correctNum) / MINIBATCH_SIZE);
            net.Update(0.1, Net.UpdateOptimizer.SGD);
            ResultWriter.WriteResult(net);
            PrintInConsole(averageCost, correctNum);
            return(averageCost);
        }
Esempio n. 2
0
        public override void QueryHandler(NameRequestReader request, ResultWriter responseBuff)
        {
            try
            {
                int slave_count = Global.SlaveCount;
                Global.CloudStorage.SearchToMySlave(Global.CloudStorage.GetSlaveIdByCellId(1),
                                                    new NameRequestWriter(request.hop, request.name, request.neighbours));

                int reports_total = ReportsCount(slave_count);
                Console.WriteLine("Waiting for {0} reports", reports_total);
                //waiting for 40 reports
                while (report_num != reports_total)
                {
                    Thread.Sleep(1000);
                }
                responseBuff.matchPersons = matches.ToList <long>();
                report_num = 0;
                matches.Clear();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
 public static void ClassInitilize(TestContext context)
 {
     tracer = new Tracer();
     TestMethod_1();
     traceResult  = tracer.GetTraceResult();
     resultWriter = new ResultWriter();
 }
Esempio n. 4
0
        IItem IReadOnlyItem.Clone()
        {
            var writer = new ResultWriter(this.AmlContext, null, null);

            Xml.WriteTo(writer);
            return(writer.Result.AssertItem());
        }
Esempio n. 5
0
        /// <summary>
        /// Writes <paramref name="detectables"/> sequentially to file with
        /// name <paramref name="fileName"/>.
        /// </summary>
        /// <param name="detectables">the detectables to write</param>
        /// <param name="fileName">the name of the file to write to</param>
        /// <typeparam name="T">the type of detectables to write</typeparam>
        internal static void WriteDetectables <T>(IList <T> detectables, string fileName, IProgressReporter progressReporter, ref long handledBytes, long totalBytes) where T : IDataPacket
        {
            if (detectables == null)
            {
                throw new ArgumentNullException("detectables");
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }
            using (IDataReaderPool dataReaderPool = CreateDataReaderPool())
                using (ResultWriter writer = new ResultWriter(File.Create(fileName), dataReaderPool))
                {
                    foreach (T detectable in detectables)
                    {
                        IDataPacket dataPacket;

                        if (detectable is ICodecStream)
                        {
                            // It's a codec stream
                            dataPacket = DataBlockScanner.GetData(detectable as ICodecStream, progressReporter, dataReaderPool);
                        }
                        else
                        {
                            // It's a container stream
                            dataPacket = detectable;
                        }

                        writer.WriteDataPacket(dataPacket, progressReporter, ref handledBytes, totalBytes);
                    }
                }
        }
Esempio n. 6
0
        public override void QueryHandler(NameRequestReader request, ResultWriter responseBuff)
        {
            try
            {
                int slave_count = Global.SlaveCount;
                Global.CloudStorage.SearchToSlave(Global.CloudStorage.GetSlaveIDByCellID(1),
                    new NameRequestWriter(request.hop, request.name, request.neighbours));

                int reports_total = ReportsCount(slave_count);
                Console.WriteLine("Waiting for {0} reports", reports_total);
                //waiting for 40 reports
                while (report_num != reports_total)
                {
                    Thread.Sleep(1000);
                }
                responseBuff.matchPersons = matches.ToList<long>();
                report_num = 0;
                matches.Clear();

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Esempio n. 7
0
 private static void WriteFailures(IEnumerable <FailedModule> failedModules, ResultWriter resultWriter)
 {
     foreach (var failedModule in failedModules)
     {
         resultWriter.WriteFailed(failedModule);
     }
 }
 public ExecutePage(Memory memory, ResultWriter resultWriter, Action <TestCounts> handleCounts, Func <Memory, CellProcessor> newService)
 {
     this.memory       = memory;
     this.resultWriter = resultWriter;
     this.handleCounts = handleCounts;
     this.newService   = newService;
 }
        static void Main(string[] args)
        {
            try
            {
                if (!args.Any())
                {
                    throw new ArgumentException("Error: no file provided");
                }

                var content = InputReader.ReadFile(args[0]);

                var jsonRectangles = Parser.ParseJson(content);

                var rectangles = RectangleListBuilder.BuildRectangles(jsonRectangles);

                var intersections = IntersectionCalculator.CalculateIntersections(rectangles);

                ResultWriter.Display(rectangles, intersections);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.Message);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Выполняет чтение, обработку текста и запись результатов
        /// </summary>
        /// <returns>Результат сохранения</returns>
        public Result Execute()
        {
            var text             = Source.GetText();
            var processingResult = TextProcessor.Process(text);

            return(ResultWriter.Write(processingResult));
        }
Esempio n. 11
0
	    public void Run(StoryTestSuite theSuite, string theSelectedFile) {
            resultWriter = CreateResultWriter();
            if (!string.IsNullOrEmpty(theSelectedFile)) theSuite.Select(theSelectedFile);

	        RunFolder(theSuite, memory.GetItem<Settings>().DryRun);

            resultWriter.WriteFinalCount(TestCounts);
            resultWriter.Close();
	    }
 private void ResetResultsOutput(RunTransactionsButtonClicked obj)
 {
     ReferenceNumber = string.Empty;
     App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
     {
         TransactionOutputList.Clear();
     });
     _stringBuilder.Clear();
     _writer = new ResultWriter();
 }
Esempio n. 13
0
        public static void Main(string[] args)
        {
            Faker          faker          = new Faker();
            Class1         class1         = faker.Create <Class1>();
            ResultWriter   resultWriter   = new ResultWriter();
            JSONSerializer jsonSerializer = new JSONSerializer();

            Console.Write("\n\n\n");
            Console.ReadLine();
        }
Esempio n. 14
0
        public void Run(StoryTestSuite theSuite, string theSelectedFile)
        {
            resultWriter = CreateResultWriter();
            if (theSelectedFile.Length > 0) theSuite.Select(theSelectedFile);

            RunFolder(theSuite);

            resultWriter.WriteFinalCount(TestCounts);
            resultWriter.Close();
        }
Esempio n. 15
0
        public void WriteMatch_Verbose_WritesOutput()
        {
            var output = new List <string>();
            var a      = new ModuleStub(TestData.fullNameA, "A");
            var b      = new ModuleStub(TestData.fullNameB, "B");
            var cut    = new ResultWriter(s => output.Add(s));

            cut.WriteMatch((a, b), true);

            Assert.Equal("A.FullName (42.0.0) has a reference to B.FullName (1.0.0)", output.Single());
        }
Esempio n. 16
0
        public void Run(StoryTestSuite theSuite, string theSelectedFile)
        {
            resultWriter = CreateResultWriter();
            if (theSelectedFile.Length > 0)
            {
                theSuite.Select(theSelectedFile);
            }

            RunFolder(theSuite);

            resultWriter.WriteFinalCount(TestCounts);
            resultWriter.Close();
        }
Esempio n. 17
0
        public void Run(StoryTestSuite theSuite, string theSelectedFile)
        {
            resultWriter = CreateResultWriter();
            if (!string.IsNullOrEmpty(theSelectedFile))
            {
                theSuite.Select(theSelectedFile);
            }

            RunFolder(theSuite, memory.GetItem <Settings>().DryRun);

            resultWriter.WriteFinalCount(TestCounts);
            resultWriter.Close();
        }
Esempio n. 18
0
        static void WriteResult()
        {
            ResultWriter   resultWriter   = new ResultWriter();
            XmlSerializer  xmlSerializer  = new XmlSerializer();
            JsonSerializer jsonSerializer = new JsonSerializer();
            TxtWriter      txtWriter      = new TxtWriter();
            TraceResult    result         = tracer.GetTraceResult();

            resultWriter.ResultInConsole(txtWriter, result);
            resultWriter.ResultInFile(txtWriter, result, "result");
            resultWriter.ResultInFile(jsonSerializer, result, "result");
            resultWriter.ResultInFile(xmlSerializer, result, "result");
        }
Esempio n. 19
0
        /// <summary>
        /// Writes <paramref name="results"/> recursively to file with
        /// name <paramref name="fileName"/>.
        /// </summary>
        /// <param name="results">the results to write</param>
        /// <param name="fileName">the name of the file to write to/param>
        internal static void WriteResults(IResultNode[] results, string fileName)
        {
            long dummy = 0L;

            using (IDataReaderPool dataReaderPool = TestFramework.CreateDataReaderPool())
                using (ResultWriter writer = new ResultWriter(File.Create(fileName), dataReaderPool))
                {
                    foreach (IResultNode result in results)
                    {
                        writer.WriteResult(result, null, ref dummy, 0L);
                    }
                }
        }
Esempio n. 20
0
        /// <summary>
        /// Validate arguments.
        /// </summary>
        private void ValidateArguments()
        {
            if (ValidateArgumentsEx())
            {
                if (Threads <= 0)
                {
                    throw new Exception("Threads must be positive: " + Threads);
                }

                if (Warmup < 0)
                {
                    throw new Exception("Warmup cannot be negative: " + Warmup);
                }

                if (Duration < 0)
                {
                    throw new Exception("Duration cannot be negative: " + Duration);
                }

                if (BatchSize <= 0)
                {
                    throw new Exception("BatchSize must be positive: " + BatchSize);
                }

                if (MaxErrors < 0)
                {
                    throw new Exception("MaxErrors cannot be negative: " + MaxErrors);
                }

                if (ResultWriter == null || !ResultWriter.ToLower().Equals(ResultWriterConsole) &&
                    !ResultWriter.ToLower().Equals(ResultWriterFile))
                {
                    throw new Exception("Invalid ResultWriter: " + ResultWriter);
                }

                if (ResultWriter.ToLower().Equals(ResultWriterFile) && ResultFolder == null)
                {
                    throw new Exception("ResultFolder must be set for file result writer.");
                }

                if (ResultBucketCount <= 0)
                {
                    throw new Exception("ResultBucketCount must be positive: " + ResultBucketCount);
                }

                if (ResultBucketInterval <= 0)
                {
                    throw new Exception("ResultBucketInterval must be positive: " + ResultBucketInterval);
                }
            }
        }
Esempio n. 21
0
        public static AbstractWriter GetWriter(ResultWriter writer)
        {
            switch (writer)
            {
            case ResultWriter.Console:
                return(new ConsoleWriter());

            case ResultWriter.File:
                return(new FileWriter());

            default:
                throw new ArgumentOutOfRangeException($"Writer {writer.ToString()} is not supported");
            }
        }
Esempio n. 22
0
        public void Run(StoryTestSuite theSuite, string theSelectedFile)
        {
            var now = DateTime.Now;
            resultWriter = CreateResultWriter();
            if (!string.IsNullOrEmpty(theSelectedFile)) theSuite.Select(theSelectedFile);

            RunFolder(theSuite, memory.GetItem<Settings>().DryRun);

            resultWriter.WriteFinalCount(TestCounts);
            resultWriter.Close();

            if (!memory.GetItem<Settings>().DryRun)
                myReporter.Write(string.Format("\n{0}, time: {1}\n", TestCounts.Description, DateTime.Now - now));
        }
Esempio n. 23
0
 private void CreateResultWriter(string fileName, string outputType, FolderModel folders)
 {
     if (string.IsNullOrEmpty(fileName))
     {
         return;
     }
     if (outputType == "xml")
     {
         resultWriter = new XmlResultWriter(fileName, folders);
     }
     else
     {
         resultWriter = new TextResultWriter(fileName, folders);
     }
 }
Esempio n. 24
0
 public void ExecuteStoryPage(Action <StoryPageName, StoryTestString, Action <StoryTestString, TestCounts>, Action> executor, ResultWriter resultWriter, Action <TestCounts> handler)
 {
     elapsedTime       = new ElapsedTime();
     this.resultWriter = resultWriter;
     this.handler      = handler;
     if (HasTestName)
     {
         executor(myPath, DecoratedContent, WriteFile, HandleNoTest);
         return;
     }
     if (myPath.IsSuiteSetUp || myPath.IsSuiteTearDown)
     {
         executor(myPath, PlainContent, WriteFile, HandleNoTest);
         return;
     }
     HandleNoTest();
 }
Esempio n. 25
0
 public override void QueryHandler(QueryRequestReader request, ResultWriter responseBuff)
 {
     try
     {
         Global.CloudStorage.SearchToMySlave(Global.CloudStorage.GetSlaveIdByCellId(1),
                                             new QueryRequestWriter(/*具体参数自己定义request.hop, request.name, request.neighbours*/)); //分给slave的
         reports_total = slave_count;                                                                                            //计算总共收到的report的数目
         //Console.WriteLine("Waiting for {0} reports", reports_total);
         while (report_num != reports_total)                                                                                     //等待所有结果都出来
         {
             Thread.Sleep(1000);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
     }
 }
        public void Run(StoryTestSuite theSuite, string theSelectedFile)
        {
            var now = DateTime.Now;

            resultWriter = CreateResultWriter();
            if (!string.IsNullOrEmpty(theSelectedFile))
            {
                theSuite.Select(theSelectedFile);
            }

            RunFolder(theSuite, memory.GetItem <Settings>().DryRun);

            resultWriter.WriteFinalCount(TestCounts);
            resultWriter.Close();

            if (!memory.GetItem <Settings>().DryRun)
            {
                myReporter.Write(string.Format("\n{0}, time: {1}\n", TestCounts.Description, DateTime.Now - now));
            }
        }
Esempio n. 27
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                throw new ArgumentException("No input provided", nameof(args));
            }

            var counter = new LetterCounter();

            var result = counter.Count(args[0]);

            var consoleTable = new ConsoleTable();

            consoleTable.Options.EnableCount = false;
            var resultWriter = new ResultWriter(consoleTable);

            resultWriter.Write(result);

            Console.WriteLine(
                $"The text has been processed.{Environment.NewLine}Total letters counted: {args[0].Length}");
        }
Esempio n. 28
0
        static void Main(string[] args)
        {
            Faker faker = new Faker();

            FieldValueGenerator.SetFaker(faker);
            FieldValueGenerator.DTOAdd(typeof(Foo <string>));
            FieldValueGenerator.DTOAdd(typeof(Bar <char>));
            FieldValueGenerator.DTOAdd(typeof(Bar <byte>));

            Foo <string> foo = faker.Create <Foo <string> >();
            Bar <bool>   bar = faker.Create <Bar <bool> >();

            ResultWriter   newWriter     = new ResultWriter();
            JSONSerializer newSerializer = new JSONSerializer();

            newWriter.write(newSerializer.serialize(foo));
            Console.Write("\n\n\n");

            newWriter.write(newSerializer.serialize(bar));
            Console.ReadLine();
        }
Esempio n. 29
0
        private static void BeginLearning(int startPos)
        {
            var imageBatch = new ImageBatch(DataReader.ReadTrainImage());
            var labelBatch = new LabelBatch(DataReader.ReadTrainLabel());
            var net        = ResultWriter.ReadResult();

            //net.InitMomentumLists();
            for (int x = startPos / MINIBATCH_SIZE; x < (60000 / MINIBATCH_SIZE); x++)
            {
                ResultWriter.WriteLog("start:" + x * MINIBATCH_SIZE + " to " + (x * MINIBATCH_SIZE + MINIBATCH_SIZE) + "\n");
                for (; ;)
                {
                    var averageCost = Learn(imageBatch, labelBatch, x, net);//学习minibatch的一份
                    if (averageCost < 0.01)
                    {
                        ResultWriter.WriteLog("cost:" + averageCost + "\n");
                        break;
                    }
                }
            }
        }
Esempio n. 30
0
        public void RunEvolution()
        {
            var watch = Stopwatch.StartNew();

            ResultWriter.WriteInformationHeader();

            var population = new Population(Rules.StartPopulationData).Animals;

            ResultWriter.WriteInformation(population, 1);

            for (int i = 0; i < Rules.NumberOfGenerations - 1; i++)
            {
                population = createNewGeneration(population, true);
                ResultWriter.WriteInformation(population, i + 2);
            }

            watch.Stop();
            var seconds = Math.Round(watch.ElapsedMilliseconds / 1000m, 2);

            ResultWriter.WriteEvolutionFinishedMessage(seconds);
            Console.ReadKey();
        }
Esempio n. 31
0
 public void ExecuteStoryPage(Action<StoryPageName, StoryTestString, Action<StoryTestString, TestCounts>, Action> executor, ResultWriter resultWriter, Action<TestCounts> handler)
 {
     elapsedTime = new ElapsedTime();
     this.resultWriter = resultWriter;
     this.handler = handler;
     if (HasTestName) {
         executor(myPath, DecoratedContent, WriteFile, HandleNoTest);
         return;
     }
     if (myPath.IsSuiteSetUp || myPath.IsSuiteTearDown) {
         executor(myPath, PlainContent, WriteFile, HandleNoTest);
         return;
     }
     HandleNoTest();
 }
Esempio n. 32
0
 private void CreateResultWriter(string fileName, string outputType, FolderModel folders)
 {
     if (string.IsNullOrEmpty(fileName)) return;
     if (outputType == "xml")
         resultWriter = new XmlResultWriter(fileName, folders);
     else
         resultWriter = new TextResultWriter(fileName, folders);
 }
Esempio n. 33
0
 public ExecutePage(Memory memory, ResultWriter resultWriter,  Action<TestCounts> handleCounts) {
     this.memory = memory;
     this.resultWriter = resultWriter;
     this.handleCounts = handleCounts;
 }
Esempio n. 34
0
 public ExecutePage(Memory memory, ResultWriter resultWriter,  Action<TestCounts> handleCounts, Func<Memory, CellProcessor> newService)
 {
     this.memory = memory;
     this.resultWriter = resultWriter;
     this.handleCounts = handleCounts;
     this.newService = newService;
 }
Esempio n. 35
0
        public async Task <byte[]> QueryAsync(AuthData authData, Dictionary <string, string> queryString)
        {
            if (!queryString.ContainsKey("query"))
            {
                throw new Exception("get request must include 1 'query' query string parameter",
                                    new ArgumentException("query"));
            }

            var cancel = new CancellationToken();

            logger.LogInformation("Begin request at " + DateTime.Now);

            var server   = settings.DataSource;
            var database = settings.Database;

            string constr = string.Empty;

            switch (authData.Scheme)
            {
            case AuthScheme.BASIC:
                constr =
                    $"Data Source={server};User Id={authData.UPN};Password={authData.PasswordOrToken};Catalog={database};Persist Security Info=True; Impersonation Level=Impersonate";
                break;

            case AuthScheme.BEARER:
                constr =
                    $"Data Source={server};Password={authData.PasswordOrToken};Catalog={database};Persist Security Info=True; Impersonation Level=Impersonate";
                break;

            case AuthScheme.NONE:
                break;

            default:
                throw new InvalidOperationException($"unexpected state authData.Scheme={authData.Scheme}");
            }

            //get gzip setting - by default false, but we can change that with setting header file
            bool gzip = !queryString.ContainsKey("gzip") || bool.Parse(queryString["gzip"]);
            //if (req.Headers.AcceptEncoding.Any(h => h.Value == "gzip" || h.Value == "*"))
            //{
            //    gzip = true;
            //}

            //IF using POST method
            // var req = new HttpRequestMessage();
            // req.Headers.Add("Authorization", $"bearer {authData.PasswordOrToken}");
            //var query = req.Method == HttpMethod.Get ? queryString["query"] : await req.Content.ReadAsStringAsync();
            var query = queryString["query"];

            var con = ConnectionPool.Instance.GetConnection(constr, authData);

            var cmd = con.Connection.CreateCommand();

            cmd.CommandText = query;

            object queryResults;

            try
            {
                cmd.CommandTimeout = 2 * 60;
                cancel.Register(() =>
                {
                    cmd.Cancel();
                    con.Connection.Dispose();
                    logger.LogInformation("QueryAsync Execution Canceled!");
                });
                queryResults = cmd.Execute();
            }
            catch (Exception ex)
            {
                throw new Exception($"Server error - command coundnt execute! {ex.Message}");
            }

            //var indent = true;

            var content = new PushStreamContent(async(responseStream, content, transportContext) =>
            {
                try
                {
                    Stream encodingStream = responseStream;
                    if (gzip)
                    {
                        encodingStream = new GZipStream(responseStream, CompressionMode.Compress, false);
                    }

                    await using (responseStream)
                        await using (encodingStream)
                        {
                            await ResultWriter.WriteResultsToStream(queryResults, encodingStream, cancel);

                            ConnectionPool.Instance.ReturnConnection(con);
                            await encodingStream.FlushAsync(cancel);
                            await responseStream.FlushAsync(cancel);
                        }
                }
                catch (Exception ex)
                {
                    con.Connection.Dispose(); //do not return to pool
                    throw new Exception($"Connection pool error occured - {ex.Message}");
                }
            }, "application/json");

            var stream = await content.ReadAsStreamAsync();

            var ms = new MemoryStream();

            if (gzip)
            {
                await using var gs = new GZipStream(stream, CompressionMode.Decompress);
                await gs.CopyToAsync(ms, cancel);
            }
            else
            {
                await stream.CopyToAsync(ms, cancel);
            }

            ms.Position = 0;
            var bytes = ms.ToArray();

            return(bytes);
        }
Esempio n. 36
0
        /// <summary>
        /// Run the benchmark.
        /// </summary>
        public void Run()
        {
            PrintDebug("Started benchmark: " + this);

            ValidateArguments();

            if (ResultWriter.ToLower().Equals(ResultWriterConsole))
            {
                _writer = new BenchmarkConsoleResultWriter();
            }
            else
            {
                _writer = new BenchmarkFileResultWriter();
            }

            OnStarted();

            PrintDebug("Benchmark setup finished.");

            try
            {
                _descs = new List <BenchmarkOperationDescriptor>();

                GetDescriptors(_descs);

                if (_descs.Count == 0)
                {
                    throw new Exception("No tasks provided for benchmark.");
                }

                // Initialize writer.
                var opNames = new List <string>(_descs.Select(desc => desc.Name));

                PrintDebug(() =>
                {
                    var sb = new StringBuilder("Operations: ");

                    foreach (var opName in opNames)
                    {
                        sb.Append(opName).Append(" ");
                    }

                    return(sb.ToString());
                });

                _writer.Initialize(this, opNames);

                PrintDebug("Initialized result writer.");

                // Start worker threads.
                _tasks = new List <BenchmarkTask>(Threads);

                PrintDebug("Starting worker threads: " + Threads);

                for (var i = 0; i < Threads; i++)
                {
                    var task = new BenchmarkTask(this, _descs);

                    _tasks.Add(task);

                    new Thread(task.Run).Start();
                }

                PrintDebug("Waiting worker threads to start: " + Threads);

                // Await for all threads to start in spin loop.
                while (Thread.VolatileRead(ref _readyThreads) < Threads)
                {
                    Thread.Sleep(10);
                }

                PrintDebug("Worker threads started: " + Threads);

                // Start throughput writer thread.
                var writerThread = new Thread(new ThroughputTask(this).Run)
                {
                    IsBackground = true
                };

                writerThread.Start();

                PrintDebug("Started throughput writer thread.");

                // Start warmup thread if needed.
                if (Warmup > 0)
                {
                    var thread = new Thread(new WarmupTask(this, Warmup).Run)
                    {
                        IsBackground = true
                    };

                    thread.Start();

                    PrintDebug("Started warmup timeout thread: " + Warmup);
                }
                else
                {
                    _warmup = false;
                }

                _barrier = new Barrier(Threads, b =>
                {
                    Console.WriteLine("Warmup finished.");

                    _totalWatch.Start();
                });

                // Start timeout thread if needed.
                if (Duration > 0)
                {
                    if (Operations > 0)
                    {
                        PrintDebug("Duration argument is ignored because operations number is set: " +
                                   Operations);
                    }
                    else
                    {
                        var thread = new Thread(new TimeoutTask(this, Warmup + Duration).Run)
                        {
                            IsBackground = true
                        };

                        thread.Start();

                        PrintDebug("Started duration timeout thread: " + Duration);
                    }
                }

                // Let workers start execution.
                _start = true;

                // Await workers completion.
                PrintDebug("Awaiting worker threads completion.");

                Monitor.Enter(this);

                try
                {
                    while (_finishedThreads < Threads)
                    {
                        Monitor.Wait(this);
                    }
                }
                finally
                {
                    Monitor.Exit(this);
                }

                PrintDebug("Worker threads completed.");
            }
            finally
            {
                OnFinished();

                _totalWatch.Stop();

                PrintDebug("Tear down invoked.");

                if (PrintThroughputInfo())
                {
                    var avgThroughput = _totalWatch.ElapsedMilliseconds == 0
                        ? 0
                        : _curOps * 1000 / _totalWatch.ElapsedMilliseconds;

                    var avgLatency = _curOps == 0
                        ? 0
                        : (double)_totalWatch.ElapsedMilliseconds * Threads / _curOps;

                    Console.WriteLine("Finishing benchmark [name=" + GetType().Name +
                                      ", time=" + _totalWatch.ElapsedMilliseconds +
                                      "ms, ops=" + _curOps +
                                      ", threads=" + Threads +
                                      ", avgThroughput=" + avgThroughput +
                                      ", avgLatency=" + string.Format("{0:0.000}ms", avgLatency) + ']');
                }
                else
                {
                    Console.WriteLine("Finishing benchmark [name=" + GetType().Name +
                                      ", time=" + _totalWatch.ElapsedMilliseconds +
                                      "ms, ops=" + Operations +
                                      ", threads=" + Threads + ']');
                }
            }

            _percentiles = new Dictionary <string, long[]>(_descs.Count);

            foreach (var desc in _descs)
            {
                _percentiles[desc.Name] = new long[ResultBucketCount];
            }

            foreach (var task in _tasks)
            {
                task.CollectPercentiles(_percentiles);
            }

            foreach (var percentile in _percentiles)
            {
                _writer.WritePercentiles(percentile.Key, ResultBucketInterval, percentile.Value);
            }

            _writer.Commit();

            PrintDebug("Results committed to output writer.");
        }
Esempio n. 37
0
        public static int Run(string[] args)
        {
            var app = new CommandLineApplication();

            app.HelpOption();

            var argumentFindReference = app.Argument(
                "assemblyname",
                "the name of the assembly to look for references to. " +
                "Case insensitive, matches if the FullName of the referenced assembly is equal to the argument.");

            var optionDirectory = app.Option(
                "-d|--directory <DIRECTORY>",
                "the root directory to search through (default: working directory)",
                CommandOptionType.SingleValue);
            var optionRecurse = app.Option("-r|--recursive", "search directory recursively", CommandOptionType.NoValue);
            var optionVerbose = app.Option("-v|--verbose", "write verbose output to stdout", CommandOptionType.NoValue);
            var optionRegex   = app.Option("-e|--regex", "use assemblyname argument as regex pattern", CommandOptionType.NoValue);

            app.OnExecute(
                () =>
            {
                var findReferenceName = argumentFindReference.Value;
                if (string.IsNullOrWhiteSpace(findReferenceName))
                {
                    Write($"Specify which reference to find with the [{argumentFindReference.Name}] argument");
                    app.ShowHelp();
                    return;
                }

                _isVerbose       = optionVerbose.HasValue();
                var searchOption = optionRecurse.HasValue() ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
                var directory    = optionDirectory.HasValue() ? optionDirectory.Value() : Directory.GetCurrentDirectory();
                var useRegex     = optionRegex.HasValue();

                WriteVerbose($"Loading DLLs from '{directory}'{(searchOption == SearchOption.AllDirectories ? " recursively" : string.Empty)}");

                using (var finder = new ReferenceFinder(
                           new SystemIOWrapper(),
                           new ModuleLoader(),
                           options =>
                {
                    options.Directory = directory;
                    options.FindReferenceName = findReferenceName;
                    options.SearchOption = searchOption;
                    options.UseRegex = useRegex;
                }))
                {
                    var matches = finder.FindReferences(out var failedModules);

                    var resultWriter = new ResultWriter(Write);

                    if (_isVerbose)
                    {
                        WriteFailures(failedModules, resultWriter);
                    }

                    foreach (var match in matches)
                    {
                        resultWriter.WriteMatch(match, _isVerbose);
                    }
                }
            });

            return(app.Execute(args));
        }
Esempio n. 38
0
        public override void QueryHandler(NodeSetReader nsr, ResultWriter result)
        {
            //Console.WriteLine("begin here.");
            NodeSet ns = new NodeSet();

            updatesl = false;
            ns       = FindSameLabel(nsr.headid);
            if (updatesl == true)
            {
                result.samelabel.Add(ns);          //将结果加入到总的Samelabel中
            }
            for (int i = 0; i < ns.set.Count; i++) //对头的匹配节点做处理,只有id为当前slaveid的节点留下
            {
                if (Global.CloudStorage.GetSlaveIdByCellId(ns.set[i]) != myid)
                {
                    //Console.WriteLine("{0}'s id : {1}", ns.set[i], Global.CloudStorage.GetSlaveIdByCellId(ns.set[i]));
                    ns.set.Remove(ns.set[i]);
                    i--;
                    //Console.WriteLine("-----{0}'s id : {1}", ns.set[i],Global.CloudStorage.GetSlaveIdByCellId(ns.set[i]));
                }
            }
            Boolean        notFound   = false;
            List <NodeSet> tmpResult  = new List <NodeSet>();
            List <NodeSet> tmpResult2 = new List <NodeSet>();

            //Console.WriteLine("shit1");
            foreach (long tmp in ns.set)//每次去取一个具有相同label的根结点
            {
                //Console.WriteLine("God bless me! {0}",tmp);
                //Console.WriteLine(tmp.id);
                tmpResult.Clear();
                tmpResult2.Clear();
                NodeSet tmpns = new NodeSet();//一个暂时变量,暂时保存某一个查到的匹配到的子图
                tmpns.set       = new List <long>();
                tmpns.headid    = tmp;
                tmpns.headlabel = nsr.headlabel;
                tmpns.set.Add(tmp);
                tmpResult2.Add(tmpns);
                //Console.ReadLine();
                //tmpns.addNode(tmp);
                notFound = false;
                nsr.set.ForEach((qn) =>//取Q中每一个儿子节点与上一行取出的节点的儿子节点作比对(nsr为proxy传过来的需要查询的图)
                {
                    if (notFound == true)
                    {
                        return;
                    }
                    notFound = true;
                    tmpResult.Clear();
                    //Console.WriteLine("query:{0}", qn);
                    updatesl    = false;
                    NodeSet fsl = new NodeSet();
                    fsl         = FindSameLabel(qn);
                    if (updatesl == true)
                    {
                        result.samelabel.Add(fsl);                          //将结果加入到总的Samelabel中
                    }
                    using (var testhead = Global.LocalStorage.UseNode(tmp)) //tmp为一个具有相同label的根结点----------注意这里需要给对应的slave处理,记得改
                    {
                        testhead.neighbors.ForEach((n) =>                   //搜索一下取出的根节点的儿子中是否存在与qn其中一个儿子节点相匹配的节点
                        {
                            //Console.WriteLine("test n{0}", n);
                            foreach (int i in fsl.set)
                            {
                                if (i == n)
                                {
                                    notFound = false;
                                    foreach (NodeSet tmpns2 in tmpResult2)
                                    {
                                        NodeSet tmpns3 = NodeSetCopy(tmpns2);
                                        tmpns3.set.Add(n);
                                        tmpResult.Add(tmpns3);
                                    }
                                }
                            }
                        }
                                                   );
                    }

                    if (notFound == true)
                    {
                        //if (tmp == 3932)
                        //{
                        //    Console.WriteLine("not found");
                        //}
                        return;
                    }
                    tmpResult2.Clear();
                    foreach (NodeSet tmpns4 in tmpResult)
                    {
                        // tmpns4.show();
                        tmpResult2.Add(tmpns4);
                    }
                }
                                );
                //Console.WriteLine("************************************************");
                if (notFound == false)
                {
                    foreach (NodeSet tmpns5 in tmpResult)
                    {
                        //Console.WriteLine("find one");
                        result.set.Add(tmpns5);
                        //Q[i].showResult();
                    }
                }
            }
            //result.set.ForEach((tmp1) =>
            //{
            //    Console.WriteLine(tmp1.headid);
            //    tmp1.set.ForEach((tmp2) =>
            //    {
            //        Console.Write("{0} ", tmp2);
            //    }
            //    );
            //    Console.WriteLine();
            //}
            //       );
            //result.samelabel.ForEach((tmp1) =>
            //{
            //    Console.WriteLine(tmp1.headid);
            //    tmp1.set.ForEach((tmp2) =>
            //    {
            //        Console.Write("{0} ", tmp2);
            //    }
            //    );
            //    Console.WriteLine();
            //}
            //       );
            // Console.ReadLine();
            //Global.CloudStorage.UpdateSameLabelSetToGraphProxy(0, new SameLabelWriter(result.samelabel));
        }
Esempio n. 39
0
 public ExecutePage(Configuration configuration, ResultWriter resultWriter,  Action<TestCounts> handleCounts)
 {
     this.configuration = configuration;
     this.resultWriter = resultWriter;
     this.handleCounts = handleCounts;
 }