src/stats/examples/gnuplot-helper-example.cc
changeset 11027 e943837b17ad
parent 10978 754c8256c35c
child 11432 d2656819dd54
--- a/src/stats/examples/gnuplot-helper-example.cc	Tue Oct 14 13:29:05 2014 -0700
+++ b/src/stats/examples/gnuplot-helper-example.cc	Wed Oct 15 07:00:24 2014 -0700
@@ -34,10 +34,11 @@
 
 NS_LOG_COMPONENT_DEFINE ("GnuplotHelperExample");
 
-/*
- * This is our test object, an object that increments counters at
- * various times and emits one of them as a trace source.
- */
+//
+// This is our test object, an object that increments a counter according
+// to a Poisson process, and exports the (integer-valued) count as a
+// trace source.
+//
 class Emitter : public Object
 {
 public:
@@ -45,12 +46,10 @@
   Emitter ();
 private:
   void DoInitialize (void);
-  void Emit (void);
   void Count (void);
 
-  TracedValue<double> m_counter;  // normally this would be integer type
+  TracedValue<uint32_t> m_counter;
   Ptr<ExponentialRandomVariable> m_var;
-
 };
 
 NS_OBJECT_ENSURE_REGISTERED (Emitter);
@@ -80,19 +79,10 @@
 Emitter::DoInitialize (void)
 {
   NS_LOG_FUNCTION (this);
-  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Emit, this);
   Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Count, this);
 }
 
 void
-Emitter::Emit (void)
-{
-  NS_LOG_FUNCTION (this);
-  NS_LOG_DEBUG ("Emitting at " << Simulator::Now ().GetSeconds ());
-  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Emit, this);
-}
-
-void
 Emitter::Count (void)
 {
   NS_LOG_FUNCTION (this);
@@ -115,18 +105,6 @@
   Names::Add ("/Names/Emitter", emitter);
 
   //
-  // This Probe will be hooked to the Emitter's trace source object by
-  // accessing it by path name in the Config database.
-  //
-
-  Ptr<DoubleProbe> probe = CreateObject<DoubleProbe> ();
-  probe->SetName ("PathProbe");
-  Names::Add ("/Names/Probe", probe);
-
-  // Note, no return value is checked here.
-  probe->ConnectByPath ("/Names/Emitter/Counter");
-
-  //
   // This gnuplot helper will be used to produce output used to make
   // gnuplot plots.
   //
@@ -134,17 +112,19 @@
   // Create the gnuplot helper.
   GnuplotHelper plotHelper;
 
-  // Configure the plot.
+  // Configure the plot.  Arguments include file prefix, plot title,
+  // x-label, y-label, and output file type
   plotHelper.ConfigurePlot ("gnuplot-helper-example",
-                            "Emitter Counts vs. Time",
+                            "Emitter Count vs. Time",
                             "Time (Seconds)",
                             "Emitter Count",
                             "png");
 
-  // Plot the values generated by the probe.  The path that we provide
-  // helps to disambiguate the source of the trace.
-  plotHelper.PlotProbe ("ns3::DoubleProbe",
-                        "/Names/Probe/Output",
+  // Create a probe.  Because the trace source we are interested in is 
+  // of type uint32_t, we specify the type of probe to use by the first
+  // argument specifying its ns3 TypeId.
+  plotHelper.PlotProbe ("ns3::Uinteger32Probe",
+                        "/Names/Emitter/Counter",
                         "Output",
                         "Emitter Count",
                         GnuplotAggregator::KEY_INSIDE);