A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
gnuplot-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mitch Watrous (watrous@u.washington.edu)
18 */
19
20#ifndef GNUPLOT_HELPER_H
21#define GNUPLOT_HELPER_H
22
23#include "ns3/gnuplot-aggregator.h"
24#include "ns3/object-factory.h"
25#include "ns3/probe.h"
26#include "ns3/ptr.h"
27#include "ns3/time-series-adaptor.h"
28
29#include <map>
30#include <string>
31#include <utility>
32
33namespace ns3
34{
35
36/**
37 * \ingroup gnuplot
38 * \brief Helper class used to make gnuplot plots.
39 **/
41{
42 public:
43 /**
44 * Constructs a gnuplot helper that will create a space separated
45 * gnuplot data file named "gnuplot-helper.dat", a gnuplot control
46 * file named "gnuplot-helper.plt", and a shell script to generate
47 * the gnuplot named "gnuplot-helper.sh" unless it is later
48 * configured otherwise.
49 */
51
52 /**
53 * \param outputFileNameWithoutExtension name of gnuplot related files to
54 * write with no extension
55 * \param title plot title string to use for this plot.
56 * \param xLegend the legend for the x horizontal axis.
57 * \param yLegend the legend for the y vertical axis.
58 * \param terminalType terminal type setting string for output. The
59 * default terminal type is "png"
60 *
61 * Constructs a gnuplot helper that will create a space separated
62 * gnuplot data file named outputFileNameWithoutExtension + ".dat",
63 * a gnuplot control file named outputFileNameWithoutExtension +
64 * ".plt", and a shell script to generate the gnuplot named
65 * outputFileNameWithoutExtension + ".sh".
66 */
67 GnuplotHelper(const std::string& outputFileNameWithoutExtension,
68 const std::string& title,
69 const std::string& xLegend,
70 const std::string& yLegend,
71 const std::string& terminalType = "png");
72
73 virtual ~GnuplotHelper();
74
75 /**
76 * \param outputFileNameWithoutExtension name of gnuplot related files to
77 * write with no extension
78 * \param title plot title string to use for this plot.
79 * \param xLegend the legend for the x horizontal axis.
80 * \param yLegend the legend for the y vertical axis.
81 * \param terminalType terminal type setting string for output. The
82 * default terminal type is "png"
83 *
84 * Configures plot related parameters for this gnuplot helper so
85 * that it will create a space separated gnuplot data file named
86 * outputFileNameWithoutExtension + ".dat", a gnuplot control file
87 * named outputFileNameWithoutExtension + ".plt", and a shell script
88 * to generate the gnuplot named outputFileNameWithoutExtension +
89 * ".sh".
90 */
91 void ConfigurePlot(const std::string& outputFileNameWithoutExtension,
92 const std::string& title,
93 const std::string& xLegend,
94 const std::string& yLegend,
95 const std::string& terminalType = "png");
96
97 /**
98 * \param typeId the type ID for the probe used when it is created.
99 * \param path Config path for underlying trace source to be probed
100 * \param probeTraceSource the probe trace source to access.
101 * \param title the title to be associated to this dataset
102 * \param keyLocation the location of the key in the plot.
103 *
104 * Plots a dataset generated by hooking the ns-3 trace source with a
105 * probe, and then plot the values from the probeTraceSource. The dataset
106 * will have the provided title, and will consist of the 'newValue'
107 * at each timestamp.
108 *
109 * This method will create one or more probes according to the TypeId
110 * provided, connect the probe(s) to the trace source specified by
111 * the config path, and hook the probeTraceSource(s) to the downstream
112 * aggregator.
113 *
114 * If the config path has more than one match in the system
115 * (e.g. there is a wildcard), then one dataset for each match will
116 * be plotted. The dataset titles will be suffixed with the matched
117 * characters for each of the wildcards in the config path,
118 * separated by spaces. For example, if the proposed dataset title
119 * is the string "bytes", and there are two wildcards in the path,
120 * then dataset titles like "bytes-0 0" or "bytes-12 9" will be
121 * possible as labels for the datasets that are plotted.
122 */
123 void PlotProbe(const std::string& typeId,
124 const std::string& path,
125 const std::string& probeTraceSource,
126 const std::string& title,
128
129 /**
130 * \param adaptorName the timeSeriesAdaptor's name.
131 *
132 * \brief Adds a time series adaptor to be used to make the plot.
133 */
134 void AddTimeSeriesAdaptor(const std::string& adaptorName);
135
136 /**
137 * \param probeName the probe's name.
138 * \return Ptr to probe
139 * \brief Gets the specified probe.
140 */
141 Ptr<Probe> GetProbe(std::string probeName) const;
142
143 /**
144 * \return Ptr to GnuplotAggregator object
145 * \brief Gets the aggregator.
146 *
147 * This function is non-const because an aggregator may be lazily
148 * created by this method.
149 */
151
152 private:
153 /**
154 * \param typeId the type ID for the probe used when it is created.
155 * \param probeName the probe's name.
156 * \param path Config path to access the probe.
157 *
158 * \brief Adds a probe to be used to make the plot.
159 */
160 void AddProbe(const std::string& typeId, const std::string& probeName, const std::string& path);
161
162 /**
163 * \brief Constructs the aggregator.
164 */
165 void ConstructAggregator();
166
167 /**
168 * \param typeId the type ID for the probe used when it is created.
169 * \param matchIdentifier this string is used to make the probe's
170 * context be unique.
171 * \param path Config path to access the probe.
172 * \param probeTraceSource the probe trace source to access.
173 * \param title the title to be associated to this dataset.
174 *
175 * \brief Connects the probe to the aggregator.
176 */
177 void ConnectProbeToAggregator(const std::string& typeId,
178 const std::string& matchIdentifier,
179 const std::string& path,
180 const std::string& probeTraceSource,
181 const std::string& title);
182
183 /// Used to create the probes and collectors as they are added.
185
186 /// The aggregator used to make the plots.
188
189 /// Maps probe names to probes.
190 std::map<std::string, std::pair<Ptr<Probe>, std::string>> m_probeMap;
191
192 /// Maps time series adaptor names to time series adaptors.
193 std::map<std::string, Ptr<TimeSeriesAdaptor>> m_timeSeriesAdaptorMap;
194
195 /// Number of plot probes that have been created.
197
198 /// The name of the output file to created without its extension.
200
201 /// Title string to use for this plot.
202 std::string m_title;
203
204 /// Legend for the x axis.
205 std::string m_xLegend;
206
207 /// Legend for the y axis.
208 std::string m_yLegend;
209
210 /// Terminal type for the plot.
211 std::string m_terminalType;
212
213}; // class GnuplotHelper
214
215} // namespace ns3
216
217#endif // GNUPLOT_HELPER_H
KeyLocation
The location of the key in the plot.
Helper class used to make gnuplot plots.
void ConfigurePlot(const std::string &outputFileNameWithoutExtension, const std::string &title, const std::string &xLegend, const std::string &yLegend, const std::string &terminalType="png")
std::string m_title
Title string to use for this plot.
GnuplotHelper()
Constructs a gnuplot helper that will create a space separated gnuplot data file named "gnuplot-helpe...
void AddTimeSeriesAdaptor(const std::string &adaptorName)
Adds a time series adaptor to be used to make the plot.
Ptr< GnuplotAggregator > m_aggregator
The aggregator used to make the plots.
Ptr< Probe > GetProbe(std::string probeName) const
Gets the specified probe.
std::string m_terminalType
Terminal type for the plot.
std::string m_outputFileNameWithoutExtension
The name of the output file to created without its extension.
uint32_t m_plotProbeCount
Number of plot probes that have been created.
virtual ~GnuplotHelper()
ObjectFactory m_factory
Used to create the probes and collectors as they are added.
std::string m_yLegend
Legend for the y axis.
std::map< std::string, Ptr< TimeSeriesAdaptor > > m_timeSeriesAdaptorMap
Maps time series adaptor names to time series adaptors.
void AddProbe(const std::string &typeId, const std::string &probeName, const std::string &path)
Adds a probe to be used to make the plot.
void PlotProbe(const std::string &typeId, const std::string &path, const std::string &probeTraceSource, const std::string &title, GnuplotAggregator::KeyLocation keyLocation=GnuplotAggregator::KEY_INSIDE)
void ConnectProbeToAggregator(const std::string &typeId, const std::string &matchIdentifier, const std::string &path, const std::string &probeTraceSource, const std::string &title)
Connects the probe to the aggregator.
std::map< std::string, std::pair< Ptr< Probe >, std::string > > m_probeMap
Maps probe names to probes.
void ConstructAggregator()
Constructs the aggregator.
std::string m_xLegend
Legend for the x axis.
Ptr< GnuplotAggregator > GetAggregator()
Gets the aggregator.
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.