Пример #1
0
        public void ProfileMemoryFootprint()
        {
            Skip.If(!Config.ENABLE_PROFILING);
            PrintCurrentMemoryProfile("Before ");

            UserAgentAnalyzer uaa = UserAgentAnalyzer
                                    .NewBuilder()
                                    .HideMatcherLoadStats()
                                    .WithoutCache()
                                    .KeepTests()
                                    .Build();

            PrintCurrentMemoryProfile("Loaded ");

            uaa.InitializeMatchers();
            PrintCurrentMemoryProfile("Init   ");

            GC.Collect();
            PrintCurrentMemoryProfile("Post GC");

            uaa.SetCacheSize(1000);
            uaa.PreHeat();
            GC.Collect();
            PrintCurrentMemoryProfile("Cache 1K");

            uaa.SetCacheSize(10000);
            uaa.PreHeat();
            GC.Collect();
            PrintCurrentMemoryProfile("Cache 10K");

            uaa.DropTests();
            GC.Collect();
            PrintCurrentMemoryProfile("NoTest ");
        }
Пример #2
0
        public void CheckForMemoryLeaks()
        {
            Skip.If(!Config.ENABLE_PROFILING);
            UserAgentAnalyzer uaa = UserAgentAnalyzer
                                    .NewBuilder()
                                    .WithoutCache()
                                    //            .withField("OperatingSystemName")
                                    //            .withField("OperatingSystemVersion")
                                    //            .withField("DeviceClass")
                                    .HideMatcherLoadStats()
                                    .KeepTests()
                                    .Build();

            LOG.Info("Init complete");
            int iterationsDone    = 0;
            int iterationsPerLoop = 1000;

            for (int i = 0; i < 100; i++)
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                uaa.PreHeat(iterationsPerLoop, false);
                stopwatch.Stop();
                iterationsDone += iterationsPerLoop;

                long averageNanos = (stopwatch.ElapsedMilliseconds) / iterationsPerLoop;
                PrintMemoryUsage(iterationsDone, averageNanos);
            }
        }
Пример #3
0
        public void CheckAllPossibleFieldsFastSpeed()
        {
            Skip.If(!Config.ENABLE_PROFILING);
            LOG.Info("Create analyzer");
            Stopwatch         stopwatch = Stopwatch.StartNew();
            UserAgentAnalyzer uaa       = UserAgentAnalyzer
                                          .NewBuilder()
                                          .KeepTests()
                                          .DelayInitialization()
                                          .Build();

            stopwatch.Stop();
            long constructMsecs = stopwatch.ElapsedMilliseconds;;

            LOG.Info(string.Format("-- Construction time: {0}ms", constructMsecs));

            LOG.Info("List fieldnames");
            stopwatch.Restart();
            foreach (var n in uaa.GetAllPossibleFieldNamesSorted())
            {
                LOG.Info(n);
            }
            stopwatch.Stop();
            long listFieldNamesMsecs = stopwatch.ElapsedMilliseconds;

            LOG.Info(string.Format("-- List fieldnames: {0}ms", listFieldNamesMsecs));
            listFieldNamesMsecs.Should().BeLessThan(500, "Just listing the field names should only take a few ms");

            LOG.Info("Initializing the datastructures");
            stopwatch.Restart();
            uaa.InitializeMatchers();
            stopwatch.Stop();
            long initializeMsecs = stopwatch.ElapsedMilliseconds;

            LOG.Info(string.Format("-- Initialization: {0}ms", initializeMsecs));
            initializeMsecs.Should().BeGreaterThan(300, "The initialization should take several seconds");

            LOG.Info("Preheat");
            stopwatch.Restart();
            uaa.PreHeat();
            stopwatch.Stop();
            long preheatMsecs = stopwatch.ElapsedMilliseconds;

            LOG.Info(string.Format("-- Preheat : {0}ms", preheatMsecs));
        }