|
From: <dir...@us...> - 2009-07-23 12:28:31
|
Revision: 2102
http://shox.svn.sourceforge.net/shox/?rev=2102&view=rev
Author: dirk_held
Date: 2009-07-23 12:28:30 +0000 (Thu, 23 Jul 2009)
Log Message:
-----------
Add example code, using the StatUtil class, to describe, how statistics could be created.
Modified Paths:
--------------
trunk/conf/examples/statistics-Intro.txt
Modified: trunk/conf/examples/statistics-Intro.txt
===================================================================
--- trunk/conf/examples/statistics-Intro.txt 2009-07-23 12:01:27 UTC (rev 2101)
+++ trunk/conf/examples/statistics-Intro.txt 2009-07-23 12:28:30 UTC (rev 2102)
@@ -14,3 +14,80 @@
The history file is ommitted here, to save space and time.
*/
+Look at the class net.sf.shox.simulator.util.StatUtil. This class can be used, to write statistic values
+to the ShoX statistics-file, which can be displayed after the run is completed. All those statistics are
+assigned to node "1", no matter, which node uses this class. Actually should only one node use this class.
+Additionally could all values also be written to a CSV-file of your choice. To organize the creation of
+statistic-value creation, create a StatUtil-object, establish a timer, which is called once a second or
+so for one node, where a createStatistics(false) method is called. Call createStatistics(true) when the
+Finalize-event is processed in the method "protected final void processEvent(final Finalize end)" of your
+application. Thus add/correct the following lines to the appropriate places of your application-layer:
+
+ // were the variables are declared
+
+ private StatUtil su = null;
+
+ ...
+
+ // were they are initialized -> like in "protected final void processEvent(Initialize init)"
+
+ if (id.asInt() == 1) {
+ choose: su = new StatUtil(<the number of statistic values>);
+ or: su = new StatUtil(<the number of statistic values>, "statistics.csv or the like", ' ');
+ // you may choose another separating char, like ';', but not '_'
+
+ AppTimerEvent timer = new AppTimerEvent(getConfig().getSimulationSteps(1.0)); // interval = one second
+ sendEventSelf(timer);
+ }
+
+ ...
+
+ // near the beginning of "public void processWakeUpCall(final WakeUpCall wuc)"
+
+ if (wuc instanceof AppTimerEvent) {
+ createStatistics(false);
+ sendEventSelf(wuc);
+ } else ...
+
+ ...
+
+ // Add to "protected final void processEvent(final Finalize end)"
+
+ if (id.asInte() == 1) { // or the node with the highest id, if some global statistics are not yet created.
+ createStatistics(true);
+ }
+
+ ...
+
+ private void createStatistics(boolean finalize) {
+ // add your calls to create statistic-values here like...
+ // this tiny example adds four values, which needs to be added to the constructor of the su-object.
+
+ int i = 42;
+ su.statInt("int-label", i);
+
+ double x = 4711.0815;
+ su.statDouble("double-label", x);
+
+ x = 0.42;
+ su.statPercent("percent-label", x);
+
+ x = Util.now(); // it is a simulation-time value, no need to convert it to seconds.
+ su.statTime("time-label", x);
+
+ // this is of course not needed, if you did not add a CSV-file
+
+ if (finalize) {
+ su.closeCSVfile();
+ }
+ }
+
+ ...
+
+ // well, you need still a AppTimerEvent-class, like
+
+ public class AppTimerEvent extends WakeUpCall {
+ }
+
+ // or use the net.sf.shox.simulator.event.AppEvent-class directly and select by a type of your choice.
+
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|