Example #1
0
        static IEngine loadEngine(EngineLoadingMode _engineLoadingMode, out IEngineLoader engineLoader)
        {
            engineLoadingMode = _engineLoadingMode;
            switch (engineLoadingMode)
            {
            case EngineLoadingMode.LoadDirectlyUseNakedInterfaces:
            {
                engineLoader = null;                         // Not used
                IEngine engine  = null;
                int     hresult = InitializeEngine(FceConfig.GetDeveloperSN(), null, null, out engine);
                Marshal.ThrowExceptionForHR(hresult);
                assert(engine != null);
                return(engine);
            }

            case EngineLoadingMode.LoadAsInprocServer:
            {
                engineLoader = new FCEngine.InprocLoader();
                IEngine engine = engineLoader.Load(FceConfig.GetDeveloperSN(), "");
                assert(engine != null);
                return(engine);
            }

            case EngineLoadingMode.LoadAsWorkprocess:
            {
                engineLoader = new FCEngine.OutprocLoader();
                IEngine engine = engineLoader.Load(FceConfig.GetDeveloperSN(), "");
                assert(engine != null);
                return(engine);
            }
            }
            assert(false);
            engineLoader = null;
            return(null);
        }
 private void menuItemLoadWorkprocessMode_Click(object sender, System.EventArgs e)
 {
     engineLoadingMode = EngineLoadingMode.LoadAsWorkprocess;
 }
 private void menuItemLoadNakedMode_Click(object sender, System.EventArgs e)
 {
     engineLoadingMode = EngineLoadingMode.LoadDirectlyUseNakedInterfaces;
 }
 private void menuItemLoadInprocServerMode_Click(object sender, System.EventArgs e)
 {
     engineLoadingMode = EngineLoadingMode.LoadAsInprocServer;
 }
        private void command_RunTests(object sender, System.EventArgs e)
        {
            // Burnin tests: Run all snippers in all engine loading modes repeatedly

            InputDialog inputDialog = new InputDialog( "Run long tests", "Repeat count:", "1",
                new InputDialog.InputValidationMethod( checkRepeatCount ) );

            if( inputDialog.ShowDialog() == DialogResult.OK ) {
                int count = int.Parse( inputDialog.InputText );
                EngineLoadingMode _engineLoadingMode = engineLoadingMode;
                bool _reuseLoadedEngine = reuseLoadedEngine;
                try {
                    reuseLoadedEngine = true;
                    addToErrorsLog( "Load Engine directly and use naked interfaces" );
                    engineLoadingMode = EngineLoadingMode.LoadDirectlyUseNakedInterfaces;
                    runAllRepeatedly( count );
                    addToErrorsLog( "Load Engine as in-process server" );
                    engineLoadingMode = EngineLoadingMode.LoadAsInprocServer;
                    runAllRepeatedly( count );
                    addToErrorsLog( "Load Engine in a worker process" );
                    engineLoadingMode = EngineLoadingMode.LoadAsWorkprocess;
                    runAllRepeatedly( count );
                } finally {
                    engineLoadingMode = _engineLoadingMode;
                    reuseLoadedEngine = _reuseLoadedEngine;
                }
            }
        }
 static IEngine loadEngine( EngineLoadingMode _engineLoadingMode, out IEngineLoader engineLoader )
 {
     engineLoadingMode = _engineLoadingMode;
     switch( engineLoadingMode ) {
         case EngineLoadingMode.LoadDirectlyUseNakedInterfaces:
         {
             engineLoader = null; // Not used
             IEngine engine = null;
             int hresult = InitializeEngine( FceConfig.GetDeveloperSN(), null, null, out engine );
             Marshal.ThrowExceptionForHR( hresult );
             assert( engine != null );
             return engine;
         }
         case EngineLoadingMode.LoadAsInprocServer:
         {
             engineLoader = new FCEngine.InprocLoader();
             IEngine engine = engineLoader.Load( FceConfig.GetDeveloperSN(), "" );
             assert( engine != null );
             return engine;
         }
         case EngineLoadingMode.LoadAsWorkprocess:
         {
             engineLoader = new FCEngine.OutprocLoader();
             IEngine engine = engineLoader.Load( FceConfig.GetDeveloperSN(), "" );
             assert( engine != null );
             return engine;
         }
     }
     assert( false );
     engineLoader = null;
     return null;
 }
        public static void Run( Snippet snippet, int count, bool interactive, EngineLoadingMode engineLoadingMode, bool reuseLoadedEngine )
        {
            isInteractive = interactive;

            int totalTimeForAllIterationsExceptFirst = 0;
            int totalMemoryIncrementForAllIterationsExceptFirst = 0;
            int prevIterationMemory = 0;
            for( int i = 1; i <= count; i++ ) {
                try {
                    DateTime started = DateTime.Now;
                    if( engine == null  ) {
                        engine = loadEngine( engineLoadingMode, out engineLoader );
                    }
                    if( count > 1 ) {
                        initPerformanceCounters();
                        tracePerformanceBegin( "Iteration " + i.ToString() + "..." );
                    }
                    try {
                        snippet( engine );
                    } finally {
                        if( !reuseLoadedEngine ) {
                            unloadEngine( ref engine, ref engineLoader );
                        } else {
                            // If a scenario is run repeatedly (Ctrl-P) without the engine being recycled,
                            // a lot of native objects may be created in each cycle consuming a lot
                            // of native memory of which the garbage collector is unaware. This eventually
                            // might lead to memory problems. To prevent the build-up of not collected
                            // large memory objects we force the GC to collect here. This is NOT REQUIRED
                            // in most real-life scenarios.
                            GC.Collect();
                        }
                    }
                    if( count > 1 ) {
                        int elapsedTime = (int)(DateTime.Now - started).TotalMilliseconds;

                        int memory = 0;
                        try {
                            memory = (int) performanceCounter.NextValue();
                        } catch( Exception ) {
                            // Ignore. Zero memory will indicate that something went wrong
                        }

                        if( i >= 2 ) {
                            totalTimeForAllIterationsExceptFirst += elapsedTime;
                            totalMemoryIncrementForAllIterationsExceptFirst += memory - prevIterationMemory;
                        }
                        prevIterationMemory = memory;
                        traceMemory( memory );
                        tracePerformanceEnd( "OK (" + elapsedTime.ToString() + " ms, " + memory.ToString() + " bytes)" );
                    }
                } catch( AssertionFailedException e ) {
                    traceException( e.Message, e.Frame.GetFileName(), e.Frame.GetFileLineNumber() );
                } catch( Exception e ) {
                    traceExceptionEx( e.Message, 1 );
                }
            }
            if( count > 1 ) {
                tracePerformance( "Average time per iteration: " + ( totalTimeForAllIterationsExceptFirst / ( count - 1 ) ).ToString() + " ms" );
            }
        }
Example #8
0
        public static void Run(Snippet snippet, int count, bool interactive, EngineLoadingMode engineLoadingMode, bool reuseLoadedEngine)
        {
            isInteractive = interactive;

            int totalTimeForAllIterationsExceptFirst            = 0;
            int totalMemoryIncrementForAllIterationsExceptFirst = 0;
            int prevIterationMemory = 0;

            for (int i = 1; i <= count; i++)
            {
                try {
                    DateTime started = DateTime.Now;
                    if (engine == null)
                    {
                        engine = loadEngine(engineLoadingMode, out engineLoader);
                    }
                    if (count > 1)
                    {
                        initPerformanceCounters();
                        tracePerformanceBegin("Iteration " + i.ToString() + "...");
                    }
                    try {
                        snippet(engine);
                    } finally {
                        if (!reuseLoadedEngine)
                        {
                            unloadEngine(ref engine, ref engineLoader);
                        }
                        else
                        {
                            // If a scenario is run repeatedly (Ctrl-P) without the engine being recycled,
                            // a lot of native objects may be created in each cycle consuming a lot
                            // of native memory of which the garbage collector is unaware. This eventually
                            // might lead to memory problems. To prevent the build-up of not collected
                            // large memory objects we force the GC to collect here. This is NOT REQUIRED
                            // in most real-life scenarios.
                            GC.Collect();
                        }
                    }
                    if (count > 1)
                    {
                        int elapsedTime = (int)(DateTime.Now - started).TotalMilliseconds;

                        int memory = 0;
                        try {
                            memory = (int)performanceCounter.NextValue();
                        } catch (Exception) {
                            // Ignore. Zero memory will indicate that something went wrong
                        }

                        if (i >= 2)
                        {
                            totalTimeForAllIterationsExceptFirst            += elapsedTime;
                            totalMemoryIncrementForAllIterationsExceptFirst += memory - prevIterationMemory;
                        }
                        prevIterationMemory = memory;
                        traceMemory(memory);
                        tracePerformanceEnd("OK (" + elapsedTime.ToString() + " ms, " + memory.ToString() + " bytes)");
                    }
                } catch (AssertionFailedException e) {
                    traceException(e.Message, e.Frame.GetFileName(), e.Frame.GetFileLineNumber());
                } catch (Exception e) {
                    traceExceptionEx(e.Message, 1);
                }
            }
            if (count > 1)
            {
                tracePerformance("Average time per iteration: " + (totalTimeForAllIterationsExceptFirst / (count - 1)).ToString() + " ms");
            }
        }