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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mitch Watrous (watrous@u.washington.edu)
7 */
8
9#ifndef GNUPLOT_HELPER_H
10#define GNUPLOT_HELPER_H
11
12#include "ns3/gnuplot-aggregator.h"
13#include "ns3/object-factory.h"
14#include "ns3/probe.h"
15#include "ns3/ptr.h"
16#include "ns3/time-series-adaptor.h"
17
18#include <map>
19#include <string>
20#include <utility>
21
22namespace ns3
23{
24
25/**
26 * \ingroup gnuplot
27 * \brief Helper class used to make gnuplot plots.
28 **/
30{
31 public:
32 /**
33 * Constructs a gnuplot helper that will create a space separated
34 * gnuplot data file named "gnuplot-helper.dat", a gnuplot control
35 * file named "gnuplot-helper.plt", and a shell script to generate
36 * the gnuplot named "gnuplot-helper.sh" unless it is later
37 * configured otherwise.
38 */
40
41 /**
42 * \param outputFileNameWithoutExtension name of gnuplot related files to
43 * write with no extension
44 * \param title plot title string to use for this plot.
45 * \param xLegend the legend for the x horizontal axis.
46 * \param yLegend the legend for the y vertical axis.
47 * \param terminalType terminal type setting string for output. The
48 * default terminal type is "png"
49 *
50 * Constructs a gnuplot helper that will create a space separated
51 * gnuplot data file named outputFileNameWithoutExtension + ".dat",
52 * a gnuplot control file named outputFileNameWithoutExtension +
53 * ".plt", and a shell script to generate the gnuplot named
54 * outputFileNameWithoutExtension + ".sh".
55 */
56 GnuplotHelper(const std::string& outputFileNameWithoutExtension,
57 const std::string& title,
58 const std::string& xLegend,
59 const std::string& yLegend,
60 const std::string& terminalType = "png");
61
62 virtual ~GnuplotHelper();
63
64 /**
65 * \param outputFileNameWithoutExtension name of gnuplot related files to
66 * write with no extension
67 * \param title plot title string to use for this plot.
68 * \param xLegend the legend for the x horizontal axis.
69 * \param yLegend the legend for the y vertical axis.
70 * \param terminalType terminal type setting string for output. The
71 * default terminal type is "png"
72 *
73 * Configures plot related parameters for this gnuplot helper so
74 * that it will create a space separated gnuplot data file named
75 * outputFileNameWithoutExtension + ".dat", a gnuplot control file
76 * named outputFileNameWithoutExtension + ".plt", and a shell script
77 * to generate the gnuplot named outputFileNameWithoutExtension +
78 * ".sh".
79 */
80 void ConfigurePlot(const std::string& outputFileNameWithoutExtension,
81 const std::string& title,
82 const std::string& xLegend,
83 const std::string& yLegend,
84 const std::string& terminalType = "png");
85
86 /**
87 * \param typeId the type ID for the probe used when it is created.
88 * \param path Config path for underlying trace source to be probed
89 * \param probeTraceSource the probe trace source to access.
90 * \param title the title to be associated to this dataset
91 * \param keyLocation the location of the key in the plot.
92 *
93 * Plots a dataset generated by hooking the ns-3 trace source with a
94 * probe, and then plot the values from the probeTraceSource. The dataset
95 * will have the provided title, and will consist of the 'newValue'
96 * at each timestamp.
97 *
98 * This method will create one or more probes according to the TypeId
99 * provided, connect the probe(s) to the trace source specified by
100 * the config path, and hook the probeTraceSource(s) to the downstream
101 * aggregator.
102 *
103 * If the config path has more than one match in the system
104 * (e.g. there is a wildcard), then one dataset for each match will
105 * be plotted. The dataset titles will be suffixed with the matched
106 * characters for each of the wildcards in the config path,
107 * separated by spaces. For example, if the proposed dataset title
108 * is the string "bytes", and there are two wildcards in the path,
109 * then dataset titles like "bytes-0 0" or "bytes-12 9" will be
110 * possible as labels for the datasets that are plotted.
111 */
112 void PlotProbe(const std::string& typeId,
113 const std::string& path,
114 const std::string& probeTraceSource,
115 const std::string& title,
117
118 /**
119 * \param adaptorName the timeSeriesAdaptor's name.
120 *
121 * \brief Adds a time series adaptor to be used to make the plot.
122 */
123 void AddTimeSeriesAdaptor(const std::string& adaptorName);
124
125 /**
126 * \param probeName the probe's name.
127 * \return Ptr to probe
128 * \brief Gets the specified probe.
129 */
130 Ptr<Probe> GetProbe(std::string probeName) const;
131
132 /**
133 * \return Ptr to GnuplotAggregator object
134 * \brief Gets the aggregator.
135 *
136 * This function is non-const because an aggregator may be lazily
137 * created by this method.
138 */
140
141 private:
142 /**
143 * \param typeId the type ID for the probe used when it is created.
144 * \param probeName the probe's name.
145 * \param path Config path to access the probe.
146 *
147 * \brief Adds a probe to be used to make the plot.
148 */
149 void AddProbe(const std::string& typeId, const std::string& probeName, const std::string& path);
150
151 /**
152 * \brief Constructs the aggregator.
153 */
154 void ConstructAggregator();
155
156 /**
157 * \param typeId the type ID for the probe used when it is created.
158 * \param matchIdentifier this string is used to make the probe's
159 * context be unique.
160 * \param path Config path to access the probe.
161 * \param probeTraceSource the probe trace source to access.
162 * \param title the title to be associated to this dataset.
163 *
164 * \brief Connects the probe to the aggregator.
165 */
166 void ConnectProbeToAggregator(const std::string& typeId,
167 const std::string& matchIdentifier,
168 const std::string& path,
169 const std::string& probeTraceSource,
170 const std::string& title);
171
172 /// Used to create the probes and collectors as they are added.
174
175 /// The aggregator used to make the plots.
177
178 /// Maps probe names to probes.
179 std::map<std::string, std::pair<Ptr<Probe>, std::string>> m_probeMap;
180
181 /// Maps time series adaptor names to time series adaptors.
182 std::map<std::string, Ptr<TimeSeriesAdaptor>> m_timeSeriesAdaptorMap;
183
184 /// Number of plot probes that have been created.
186
187 /// The name of the output file to created without its extension.
189
190 /// Title string to use for this plot.
191 std::string m_title;
192
193 /// Legend for the x axis.
194 std::string m_xLegend;
195
196 /// Legend for the y axis.
197 std::string m_yLegend;
198
199 /// Terminal type for the plot.
200 std::string m_terminalType;
201
202}; // class GnuplotHelper
203
204} // namespace ns3
205
206#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.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.