23#include "ns3/assert.h"
24#include "ns3/config.h"
25#include "ns3/get-wildcard-matches.h"
39 : m_aggregator(nullptr),
41 m_outputFileNameWithoutExtension(
"gnuplot-helper"),
42 m_title(
"Gnuplot Helper Plot"),
43 m_xLegend(
"X Values"),
44 m_yLegend(
"Y Values"),
54 const std::string& title,
55 const std::string& xLegend,
56 const std::string& yLegend,
57 const std::string& terminalType)
58 : m_aggregator(nullptr),
60 m_outputFileNameWithoutExtension(outputFileNameWithoutExtension),
64 m_terminalType(terminalType)
79 const std::string& title,
80 const std::string& xLegend,
81 const std::string& yLegend,
82 const std::string& terminalType)
84 NS_LOG_FUNCTION(
this << outputFileNameWithoutExtension << title << xLegend << yLegend
91 <<
m_aggregator <<
" may be destroyed if no references remain.");
107 const std::string& path,
108 const std::string& probeTraceSource,
109 const std::string& title,
112 NS_LOG_FUNCTION(
this << typeId << path << probeTraceSource << title << keyLocation);
118 aggregator->SetTitle(
m_title +
" \\n\\nTrace Source Path: " + path);
124 aggregator->SetKeyLocation(keyLocation);
126 std::string pathWithoutLastToken;
127 std::string lastToken;
130 bool pathHasNoWildcards = path.find(
'*') == std::string::npos;
134 size_t lastSlash = path.find_last_of(
'/');
135 if (lastSlash == std::string::npos)
137 pathWithoutLastToken = path;
143 pathWithoutLastToken = path.substr(0, lastSlash);
146 lastToken = path.substr(lastSlash + 1, std::string::npos);
151 NS_LOG_DEBUG(
"Searching config database for trace source " << path);
154 NS_LOG_DEBUG(
"Found " << matchCount <<
" matches for trace source " << path);
157 std::string matchIdentifier;
160 if (matchCount == 1 && pathHasNoWildcards)
165 matchIdentifier =
"0";
168 else if (matchCount > 0)
171 for (
uint32_t i = 0; i < matchCount; i++)
174 std::ostringstream matchIdentifierStream;
175 matchIdentifierStream << i;
176 matchIdentifier = matchIdentifierStream.str();
180 std::string wildcardSeparator =
" ";
182 std::string wildcardMatches =
GetWildcardMatches(path, matchedPath, wildcardSeparator);
189 title +
"-" + wildcardMatches);
201 const std::string& probeName,
202 const std::string& path)
223 probe->SetName(probeName);
226 probe->ConnectByPath(path);
232 m_probeMap[probeName] = std::make_pair(probe, typeId);
243 NS_ABORT_MSG(
"That time series adaptor has already been added");
250 timeSeriesAdaptor->Enable();
260 std::map<std::string, std::pair<Ptr<Probe>, std::string>>::const_iterator mapIterator =
266 return mapIterator->second.first;
307 const std::string& matchIdentifier,
308 const std::string& path,
309 const std::string& probeTraceSource,
310 const std::string& title)
312 NS_LOG_FUNCTION(
this << typeId << matchIdentifier << path << probeTraceSource << title);
320 std::ostringstream probeNameStream;
322 std::string probeName = probeNameStream.str();
325 std::string probeContext = probeName +
"/" + matchIdentifier +
"/" + probeTraceSource;
339 m_probeMap[probeName].first->TraceConnectWithoutContext(
346 m_probeMap[probeName].first->TraceConnectWithoutContext(
353 m_probeMap[probeName].first->TraceConnectWithoutContext(
360 m_probeMap[probeName].first->TraceConnectWithoutContext(
367 m_probeMap[probeName].first->TraceConnectWithoutContext(
374 m_probeMap[probeName].first->TraceConnectWithoutContext(
381 m_probeMap[probeName].first->TraceConnectWithoutContext(
388 m_probeMap[probeName].first->TraceConnectWithoutContext(
395 m_probeMap[probeName].first->TraceConnectWithoutContext(
402 m_probeMap[probeName].first->TraceConnectWithoutContext(
410 <<
"; need to add support in the helper for this");
414 std::string adaptorTraceSource =
"Output";
421 aggregator->Add2dDataset(probeContext, title);
hold a set of objects which match a specific search string.
std::string GetMatchedPath(uint32_t i) const
void Write2d(std::string context, double x, double y)
Writes a 2D value to a 2D gnuplot dataset.
KeyLocation
The location of the key in the plot.
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.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
void TraceSinkUinteger8(uint8_t oldData, uint8_t newData)
Trace sink for receiving data from uint8_t valued trace sources.
void TraceSinkDouble(double oldData, double newData)
Trace sink for receiving data from double valued trace sources.
void TraceSinkBoolean(bool oldData, bool newData)
Trace sink for receiving data from bool valued trace sources.
void TraceSinkUinteger32(uint32_t oldData, uint32_t newData)
Trace sink for receiving data from uint32_t valued trace sources.
void TraceSinkUinteger16(uint16_t oldData, uint16_t newData)
Trace sink for receiving data from uint16_t valued trace sources.
MatchContainer LookupMatches(std::string path)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
std::string GetWildcardMatches(const std::string &configPath, const std::string &matchedPath, const std::string &wildcardSeparator)
Returns the text matches from the matched path for each of the wildcards in the Config path,...