12#include "ns3/assert.h"
13#include "ns3/config.h"
14#include "ns3/get-wildcard-matches.h"
28 : m_aggregator(nullptr),
30 m_outputFileNameWithoutExtension(
"gnuplot-helper"),
31 m_title(
"Gnuplot Helper Plot"),
32 m_xLegend(
"X Values"),
33 m_yLegend(
"Y Values"),
43 const std::string& title,
44 const std::string& xLegend,
45 const std::string& yLegend,
46 const std::string& terminalType)
47 : m_aggregator(nullptr),
49 m_outputFileNameWithoutExtension(outputFileNameWithoutExtension),
53 m_terminalType(terminalType)
68 const std::string& title,
69 const std::string& xLegend,
70 const std::string& yLegend,
71 const std::string& terminalType)
73 NS_LOG_FUNCTION(
this << outputFileNameWithoutExtension << title << xLegend << yLegend
80 <<
m_aggregator <<
" may be destroyed if no references remain.");
96 const std::string& path,
97 const std::string& probeTraceSource,
98 const std::string& title,
101 NS_LOG_FUNCTION(
this << typeId << path << probeTraceSource << title << keyLocation);
107 aggregator->SetTitle(
m_title +
" \\n\\nTrace Source Path: " + path);
113 aggregator->SetKeyLocation(keyLocation);
115 std::string pathWithoutLastToken;
116 std::string lastToken;
119 bool pathHasNoWildcards = path.find(
'*') == std::string::npos;
123 size_t lastSlash = path.find_last_of(
'/');
124 if (lastSlash == std::string::npos)
126 pathWithoutLastToken = path;
132 pathWithoutLastToken = path.substr(0, lastSlash);
135 lastToken = path.substr(lastSlash + 1, std::string::npos);
140 NS_LOG_DEBUG(
"Searching config database for trace source " << path);
143 NS_LOG_DEBUG(
"Found " << matchCount <<
" matches for trace source " << path);
146 std::string matchIdentifier;
149 if (matchCount == 1 && pathHasNoWildcards)
154 matchIdentifier =
"0";
157 else if (matchCount > 0)
160 for (
uint32_t i = 0; i < matchCount; i++)
163 std::ostringstream matchIdentifierStream;
164 matchIdentifierStream << i;
165 matchIdentifier = matchIdentifierStream.str();
169 std::string wildcardSeparator =
" ";
171 std::string wildcardMatches =
GetWildcardMatches(path, matchedPath, wildcardSeparator);
178 title +
"-" + wildcardMatches);
190 const std::string& probeName,
191 const std::string& path)
212 probe->SetName(probeName);
215 probe->ConnectByPath(path);
221 m_probeMap[probeName] = std::make_pair(probe, typeId);
232 NS_ABORT_MSG(
"That time series adaptor has already been added");
239 timeSeriesAdaptor->Enable();
249 auto mapIterator =
m_probeMap.find(probeName);
254 return mapIterator->second.first;
295 const std::string& matchIdentifier,
296 const std::string& path,
297 const std::string& probeTraceSource,
298 const std::string& title)
300 NS_LOG_FUNCTION(
this << typeId << matchIdentifier << path << probeTraceSource << title);
308 std::ostringstream probeNameStream;
310 std::string probeName = probeNameStream.str();
313 std::string probeContext = probeName +
"/" + matchIdentifier +
"/" + probeTraceSource;
328 m_probeMap[probeName].first->TraceConnectWithoutContext(
335 m_probeMap[probeName].first->TraceConnectWithoutContext(
346 m_probeMap[probeName].first->TraceConnectWithoutContext(
353 m_probeMap[probeName].first->TraceConnectWithoutContext(
360 m_probeMap[probeName].first->TraceConnectWithoutContext(
368 <<
"; need to add support in the helper for this");
372 std::string adaptorTraceSource =
"Output";
379 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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
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,...