Monitoring Simulations in AvroraAvrora allows users to add monitoring code to the simulation to report on program quantities as it runs or to collect statistics and generate a report once simulation is complete. Adding monitoring code that tracks program variables, function executions, packets transmitted over the radio, interrupts, and more, is possible--without even modifying a single line of Avrora's code! Avrora supports a flexible mechanism to allow users to specify a Java class of their own choosing (which could be their own class, for example) to instrument the program before it is run on the simulator.The simulate action supports a -monitors option that allows the user to specify a list of classes that add instrumentation to the program before it is run and generate a report after the simulation is complete. This option can accept either a "shortened" name that selects one of the built-in monitors, or can be the fully qualified name of a class. For a more complete list of monitors see the online help for monitors.
Creating Your First MonitorUsers can add their own monitoring to the simulation by writing a new subclass of the avrora.monitors.MonitorFactory class. The fully qualified name of your new class, such as mypackage.MyClass can be passed to the -monitors option. When the simulation is instantiated, an object of your class will be created, and for each node that is created in the simulation, the monitor will be given an opportunity to attach instrumentation by implementing the newMonitor() method. Users can implement their code in this method that instruments the node and creates a Monitor instance that will be associated with the node. When the simulation finishes, a textual report can be generated to the user. Here is a very simple MonitorFactory instance that illustrates how to create a basic monitor.
The MyMonitor class can then be loaded by passing its name to the -monitors option of the simulator. Here is the result of running a simulation with our new monitor.
Adding Instrumentation in a MonitorOnce a user is able to create his or her own monitor and add it to the simulation, it is possible to add instrumentation to the program to collect statistics or report events of interest during the simulation. For example, if we are interested in monitoring the time between interrupts, we can add instrumentation to the interrupt of interest. Our added code could be as simple as printing out the interrupt to the console during simulation, or it could collect statistics and generate a report at the end of the simulation.For more information, see:
|