Exemple #1
0
        public void Upgrade(ILogger logger, IDeploymentComponentFactory deploymentComponentFactory, NugetPackage installedPackage)
        {
            PerformanceLogger performanceLogger = new PerformanceLogger(logger);

            performanceLogger.Restart("Opening, Calculating and planing deployment component");
            using (ParallelReadableZipArchive upgradeZipArchive = Open(packagePathAndFileName))
            {
                if (upgradeZipArchive == null)
                {
                    throw new InvalidOperationException($"Source archive {packagePathAndFileName} not found.");
                }

                using (ParallelReadableZipArchive installedzipArchive = installedPackage?.Open())
                {
                    IReadOnlyCollection <ParallelReadableZipArchiveEntry> installedEntries = installedzipArchive?.Entries;
                    IReadOnlyCollection <ParallelReadableZipArchiveEntry> newEntries       = upgradeZipArchive.Entries;

                    IReadOnlyCollection <IDeploymentComponent> deploymentComponents = deploymentComponentFactory.CreateDeploymentComponents(this, installedPackage, installedEntries, newEntries);

                    performanceLogger.Stop();

                    performanceLogger.Restart("Execution of deployment activities");
                    UpgradeDeploymentComponents(deploymentComponents, newEntries);
                    performanceLogger.Stop();
                }
            }
        }
        public void CalculateMetricsTest()
        {
            var count  = 100;
            var logger = new PerformanceLogger();

            logger.Start();

            for (int i = 0; i < count; ++i)
            {
                logger.Start("Fast");
                logger.Stop("Fast");
                logger.Start("Slow");
                System.Threading.Thread.Sleep(1);
                logger.Stop("Slow");
            }
            logger.Stop();

            var metrics = logger.CalculateMetrics();

            Assert.AreEqual(2, metrics.Count);
            foreach (var m in metrics)
            {
                Assert.AreEqual(count, m.Value.Count);
                Assert.IsTrue(m.Value.PercentTotal >= 0);
                Assert.IsTrue(m.Value.PercentTotal <= 100);
            }
        }
        public void EfficientFrontierPerformanceTest()
        {
            // Create new portfolio
            var portf = new Portfolio("TestPortfolio");

            // Create instruments from data
            var instruments = from k in cov.Keys
                              select new Instrument(k, mean[k], cov[k]);

            portf.AddRange(instruments);

            // Add portfolio constraints
            portf.AddAllInvestedConstraint();
            portf.AddLongOnlyConstraint();
            double rf = 0.05;

            int runs = 100;

            for (int c = 0; c < runs; c++)
            {
                PerformanceLogger.Start("EfficientFrontierTests", "EfficientFrontierPerformanceTest", "Optimization.CalcEfficientFrontier");
                var res = PortfolioOptimizer.CalcEfficientFrontier(portf, rf, 50);
                Console.WriteLine(c);
                PerformanceLogger.Stop("EfficientFrontierTests", "EfficientFrontierPerformanceTest", "Optimization.CalcEfficientFrontier");
            }
            PerformanceLogger.WriteToCSV("performancedata.csv");
        }
        /*
         * In case of error during uprading return a modified nuget package
         * assume that that everything that should be removed is still there
         * in case of upgrade it might be harder because we can not be sure what happend before.
         * but the deployment action must handle this!
         */
        public void Upgrade(string packageId, Version packageVersion, string packageDownloadUri)
        {
            var loggerstate = new LoggerState
            {
                { nameof(packageId), packageId },
                { nameof(packageVersion), packageVersion },
                { nameof(packageDownloadUri), packageDownloadUri },
            };

            logger.LogInformation("Upgrading package '{0}' to version '{1}'", packageId, packageVersion);

            using (logger.BeginScope(loggerstate))
            {
                PerformanceLogger performanceLogger = new PerformanceLogger(logger);

                logger.LogInformation("Starting action on package xml list.");
                performanceLogger.Restart("Starting action on package xml list.");
                packageListRepository.StartActionOnPackage(packageId, packageVersion);
                performanceLogger.Stop();

                logger.LogInformation("Installing new package.");
                performanceLogger.Restart("Installing new package.");
                NugetPackage upgradePackage = nugetPackageRepository.InstallPackage(packageId, packageVersion, packageDownloadUri);
                performanceLogger.Stop();

                logger.LogInformation("Reading installed package.");
                performanceLogger.Restart("Reading installed package.");
                NugetPackage installedPackage = nugetPackageRepository.ReadInstalledPackage(packageId);
                logger.LogInformation("Installed Package: {0}", installedPackage?.PackageIdentifier);
                performanceLogger.Stop();

                logger.LogInformation("Upgrading package.");
                performanceLogger.Restart("Upgrading package.");
                upgradePackage.Upgrade(logger, deploymentComponentFactory, installedPackage);
                performanceLogger.Stop();

                logger.LogInformation("Archiving package.");
                performanceLogger.Restart("Archiving package.");
                nugetPackageRepository.ArchivePackage(packageId);
                performanceLogger.Stop();

                logger.LogInformation("Ending action on package xml list.");
                performanceLogger.Restart("Ending action on package xml list.");
                packageListRepository.EndActionOnPackage(packageId, packageVersion);
                performanceLogger.Stop();
            }
        }
        public void CanLoadTileDynamically()
        {
            // ARRANGE
            var logger = new PerformanceLogger();

            logger.Start();
            var componentRoot = TestHelper.GetGameRunner(_container);


            // ACT
            componentRoot.RunGame(TestHelper.BerlinTestFilePoint);
            logger.Stop();

            // ASSERT
            var tileLoader = _container.Resolve <ITileController>() as TileController;

            Assert.IsNotNull(tileLoader);
            Assert.AreEqual(1, GetSceneTileCount(tileLoader));

            Assert.Less(logger.Seconds, 3, "Loading took too long");
            // NOTE Actual value should be close to expected consumption for test data
            Assert.Less(logger.Memory, 100, "Memory consumption is too high!");
        }