Changeset 1637


Ignore:
Timestamp:
Jun 14, 2010, 3:29:25 PM (11 years ago)
Author:
kopal
Message:
  • added a benchmarking function to the ExecutionEngine
Location:
trunk/CrypPlugins/WorkspaceManager
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/WorkspaceManager/Execution/ExecutionEngine.cs

    r1627 r1637  
    4343        private WorkspaceModel workspaceModel;
    4444
     45        public long ExecutedPluginsCounter { get; set; }
     46        public bool BenchmarkPlugins { get; set; }
    4547        public long CheckInterval { get; set; }
    4648        public long GuiUpdateInterval { get; set; }
     
    8183                schedulers = new Scheduler[System.Environment.ProcessorCount*2];
    8284                for(int i=0;i<System.Environment.ProcessorCount*2;i++){
    83                     schedulers[i] = new WinFormsScheduler("Scheduler" + i);
     85                    schedulers[i] = new STAScheduler("Scheduler" + i);
    8486                }
    8587
     
    9799                schedulers[0].AddProtocol(checkExecutableProtocol);
    98100                checkExecutableProtocol.Start();
     101
     102                //The BenchmarkProtocl counts the amount of executed plugins per seconds and writes this to debug
     103                if (this.BenchmarkPlugins)
     104                {
     105                    BenchmarkProtocol benchmarkProtocol = new BenchmarkProtocol(schedulers[0], this.workspaceModel, this);
     106                    schedulers[0].AddProtocol(benchmarkProtocol);
     107                    benchmarkProtocol.Start();
     108                }
    99109
    100110                //Here we create for each PluginModel an own PluginProtocol
     
    120130        public void Stop()
    121131        {
     132            IsRunning = false;
    122133            //First stop all Gears4Net Schedulers
    123134            foreach (Scheduler scheduler in schedulers)
     
    129140            {
    130141                pluginModel.Plugin.Stop();
    131             }
    132             IsRunning = false;
     142            }           
    133143        }
    134144
     
    151161        }           
    152162    }
    153 
    154     /// <summary>
    155     /// Message send to scheduler for a Plugin to trigger the PreExecution
    156     /// </summary>
    157     public class MessagePreExecution : MessageBase
    158     {
    159         public PluginModel PluginModel;
    160     }
    161 
     163 
    162164    /// <summary>
    163165    /// Message send to scheduler for a Plugin to trigger the Execution
    164166    /// </summary>
    165167    public class MessageExecution : MessageBase
    166     {
    167         public PluginModel PluginModel;
    168     }
    169 
    170     /// <summary>
    171     /// Message send to scheduler for a Plugin to trigger the PostExecution
    172     /// </summary>
    173     public class MessagePostExecution : MessageBase
    174168    {
    175169        public PluginModel PluginModel;
     
    296290
    297291    /// <summary>
     292    /// A Protocol for checking if plugins are executable in time intervals
     293    /// </summary>
     294    public class BenchmarkProtocol : ProtocolBase
     295    {
     296        private WorkspaceModel workspaceModel;
     297        private ExecutionEngine executionEngine;
     298
     299        /// <summary>
     300        /// Create a new protocol. Each protocol requires a scheduler which provides
     301        /// a thread for execution.
     302        /// </summary>
     303        /// <param name="scheduler"></param>
     304        public BenchmarkProtocol(Scheduler scheduler, WorkspaceModel workspaceModel, ExecutionEngine executionEngine)
     305            : base(scheduler)
     306        {
     307            this.workspaceModel = workspaceModel;
     308            this.executionEngine = executionEngine;
     309        }
     310
     311        /// <summary>
     312        /// The main function of the protocol
     313        /// </summary>
     314        /// <param name="stateMachine"></param>
     315        /// <returns></returns>
     316        public override System.Collections.Generic.IEnumerator<ReceiverBase> Execute(AbstractStateMachine stateMachine)
     317        {
     318            while (this.executionEngine.IsRunning)
     319            {
     320                yield return Timeout(1000, HandleBenchmark);
     321            }
     322        }
     323
     324        /// <summary>
     325        /// Handler function for a message.
     326        /// This handler must not block, because it executes inside the thread of the scheduler.
     327        /// </summary>
     328        /// <param name="msg"></param>
     329        private void HandleBenchmark()
     330        {
     331            this.workspaceModel.WorkspaceManagerEditor.GuiLogMessage("Executing at about " + this.executionEngine.ExecutedPluginsCounter + " Plugins/s", NotificationLevel.Debug);
     332            this.executionEngine.ExecutedPluginsCounter = 0;
     333        }
     334
     335    }
     336
     337    /// <summary>
    298338    /// A Protocol for a PluginModel
    299339    /// </summary>
     
    331371            while (this.executionEngine.IsRunning)
    332372            {
    333                 yield return Receive<MessagePreExecution>(null, this.HandlePreExecute);
    334                 MessageExecution msg_exec = new MessageExecution();
    335                 msg_exec.PluginModel = this.pluginModel;
    336                 this.BroadcastMessageReliably(msg_exec);
    337                 yield return Receive<MessageExecution>(null, this.HandleExecute);
    338                 MessagePostExecution msg_post = new MessagePostExecution();
    339                 msg_post.PluginModel = this.pluginModel;
    340                 this.BroadcastMessageReliably(msg_post);
    341                 yield return Receive<MessagePostExecution>(null, this.HandlePostExecute);
    342             }
    343         }
    344 
    345         /// <summary>
    346         /// Call the pre execution function of the wrapped IPlugin
    347         /// </summary>
    348         /// <param name="msg"></param>
    349         private void HandlePreExecute(MessagePreExecution msg)
    350         {
    351             //executionEngine.GuiLogMessage("HandlePreExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
    352             msg.PluginModel.Plugin.PreExecution();
     373                yield return Receive<MessageExecution>(null, this.HandleExecute);             
     374            }
    353375        }
    354376
     
    359381        private void HandleExecute(MessageExecution msg)
    360382        {
     383            msg.PluginModel.Plugin.PreExecution();
     384
    361385            //executionEngine.GuiLogMessage("HandleExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
    362386            //Fill the plugins Inputs with data
     
    376400           
    377401            msg.PluginModel.Plugin.Execute();
    378                        
    379         }
    380 
    381         /// <summary>
    382         /// Call the post execution function of the wrapped IPlugin
    383         /// </summary>
    384         /// <param name="msg"></param>
    385         private void HandlePostExecute(MessagePostExecution msg)
    386         {
    387             //executionEngine.GuiLogMessage("HandlePostExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
     402
    388403            msg.PluginModel.Plugin.PostExecution();
    389                      
    390         }
     404
     405            if (this.executionEngine.BenchmarkPlugins)
     406            {
     407                this.executionEngine.ExecutedPluginsCounter++;                               
     408            }
     409        }
     410     
    391411    }
    392412}
  • trunk/CrypPlugins/WorkspaceManager/Model/PluginModel.cs

    r1617 r1637  
    223223            if (AtLeastOneInputSet || this.InputConnectors.Count == 0)
    224224            {
    225                 MessagePreExecution msg = new MessagePreExecution();
     225                MessageExecution msg = new MessageExecution();
    226226                msg.PluginModel = this;
    227227               
  • trunk/CrypPlugins/WorkspaceManager/WorkspaceManager.cs

    r1627 r1637  
    377377                    ExecutionEngine.GuiUpdateInterval = 100;
    378378                }
     379
     380                ExecutionEngine.BenchmarkPlugins = ((WorkspaceManagerSettings)this.Settings).BenchmarkPlugins;
     381
    379382                ExecutionEngine.Execute(WorkspaceModel);               
    380383            }
  • trunk/CrypPlugins/WorkspaceManager/WorkspaceManagerSettings.cs

    r1627 r1637  
    5555        }
    5656
     57        private bool benchmarkPlugins = false;
     58        [TaskPane("BenchmarkPlugins", "Should the WorkspaceManager benchmark the amount of executed plugins per second?", null, 1, false, DisplayLevel.Beginner, ControlType.CheckBox)]
     59        public bool BenchmarkPlugins
     60        {
     61            get
     62            {
     63                return benchmarkPlugins;
     64            }
     65            set
     66            {
     67                benchmarkPlugins = value;
     68                OnPropertyChanged("BenchmarkPlugins");
     69            }
     70        }
     71
    5772        #endregion
    5873
Note: See TracChangeset for help on using the changeset viewer.