27 #include "ns3/abort.h"
28 #include "ns3/assert.h"
29 #include "ns3/config.h"
31 #include "ns3/get-wildcard-matches.h"
41 m_outputFileNameWithoutExtension (
"gnuplot-helper"),
42 m_title (
"Gnuplot Helper Plot"),
43 m_xLegend (
"X Values"),
44 m_yLegend (
"Y Values"),
45 m_terminalType (
"png")
54 const std::string &title,
55 const std::string &xLegend,
56 const std::string &yLegend,
57 const std::string &terminalType)
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)
85 << xLegend << yLegend << terminalType);
91 " 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\\nProbe Path: " + path);
124 aggregator->SetKeyLocation (keyLocation);
126 std::string pathWithoutLastToken;
127 std::string lastToken;
130 bool pathHasNoWildcards = path.find (
"*") == std::string::npos;
133 size_t lastSlash = path.find_last_of (
"/");
134 if (lastSlash == std::string::npos)
136 pathWithoutLastToken = path;
142 pathWithoutLastToken = path.substr (0, lastSlash);
145 lastToken = path.substr (lastSlash + 1, std::string::npos);
151 uint32_t matchCount = matches.
GetN ();
154 std::string matchIdentifier;
157 if (matchCount == 1 && pathHasNoWildcards)
162 matchIdentifier =
"0";
169 else if (matchCount > 0)
172 for (uint32_t i = 0; i < matchCount; i++)
175 std::ostringstream matchIdentifierStream;
176 matchIdentifierStream << i;
177 matchIdentifier = matchIdentifierStream.str ();
181 std::string wildcardSeparator =
" ";
192 title +
"-" + wildcardMatches);
204 const std::string &probeName,
205 const std::string &path)
226 probe->SetName (probeName);
229 probe->ConnectByPath (path);
235 m_probeMap[probeName] = std::make_pair (probe, typeId);
246 NS_ABORT_MSG (
"That time series adaptor has already been added");
253 timeSeriesAdaptor->Enable ();
263 std::map<std::string, std::pair <Ptr<Probe>, std::string> >::const_iterator mapIterator =
m_probeMap.find (probeName);
268 return mapIterator->second.first;
309 const std::string &matchIdentifier,
310 const std::string &path,
311 const std::string &probeTraceSource,
312 const std::string &title)
314 NS_LOG_FUNCTION (
this << typeId << matchIdentifier << path << probeTraceSource
323 std::ostringstream probeNameStream;
325 std::string probeName = probeNameStream.str ();
328 std::string probeContext = probeName
329 +
"/" + matchIdentifier +
"/" + probeTraceSource;
341 if (
m_probeMap[probeName].second ==
"ns3::DoubleProbe")
343 m_probeMap[probeName].first->TraceConnectWithoutContext
348 else if (
m_probeMap[probeName].second ==
"ns3::BooleanProbe")
350 m_probeMap[probeName].first->TraceConnectWithoutContext
355 else if (
m_probeMap[probeName].second ==
"ns3::PacketProbe")
357 m_probeMap[probeName].first->TraceConnectWithoutContext
362 else if (
m_probeMap[probeName].second ==
"ns3::ApplicationPacketProbe")
364 m_probeMap[probeName].first->TraceConnectWithoutContext
369 else if (
m_probeMap[probeName].second ==
"ns3::Ipv4PacketProbe")
371 m_probeMap[probeName].first->TraceConnectWithoutContext
376 else if (
m_probeMap[probeName].second ==
"ns3::Ipv6PacketProbe")
378 m_probeMap[probeName].first->TraceConnectWithoutContext
383 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger8Probe")
385 m_probeMap[probeName].first->TraceConnectWithoutContext
390 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger16Probe")
392 m_probeMap[probeName].first->TraceConnectWithoutContext
397 else if (
m_probeMap[probeName].second ==
"ns3::Uinteger32Probe")
399 m_probeMap[probeName].first->TraceConnectWithoutContext
406 NS_FATAL_ERROR (
"Unknown probe type " <<
m_probeMap[probeName].second <<
"; need to add support in the helper for this");
410 std::string adaptorTraceSource =
"Output";
417 aggregator->Add2dDataset (probeContext, title);
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.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
void PlotProbe(const std::string &typeId, const std::string &path, const std::string &probeTraceSource, const std::string &title, enum GnuplotAggregator::KeyLocation keyLocation=GnuplotAggregator::KEY_INSIDE)
void AddTimeSeriesAdaptor(const std::string &adaptorName)
Adds a time series adaptor to be used to make the plot.
std::map< std::string, std::pair< Ptr< Probe >, std::string > > m_probeMap
Maps probe names to probes.
void SetTypeId(TypeId tid)
void Write2d(std::string context, double x, double y)
Writes a 2D value to a 2D gnuplot dataset.
std::string GetMatchedPath(uint32_t i) const
std::string m_xLegend
Legend for the x axis.
GnuplotHelper()
Constructs a gnuplot helper that will create a space separated gnuplot data file named "gnuplot-helpe...
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.
#define NS_FATAL_ERROR(msg)
fatal error handling
std::string m_outputFileNameWithoutExtension
The name of the output file to created without its extension.
void ConfigurePlot(const std::string &outputFileNameWithoutExtension, const std::string &title, const std::string &xLegend, const std::string &yLegend, const std::string &terminalType="png")
Config::MatchContainer LookupMatches(std::string path)
Ptr< GnuplotAggregator > m_aggregator
The aggregator used to make the plots.
Ptr< Object > Create(void) const
void AddProbe(const std::string &typeId, const std::string &probeName, const std::string &path)
Adds a probe to be used to make the plot.
std::map< std::string, Ptr< TimeSeriesAdaptor > > m_timeSeriesAdaptorMap
Maps time series adaptor names to time series adaptors.
void ConstructAggregator()
Constructs the aggregator.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void TraceSinkUinteger32(uint32_t oldData, uint32_t newData)
Trace sink for receiving data from uint32_t valued trace sources.
uint32_t GetN(void) const
Ptr< GnuplotAggregator > GetAggregator()
Gets the aggregator.
void TraceSinkUinteger8(uint8_t oldData, uint8_t newData)
Trace sink for receiving data from uint8_t valued trace sources.
hold a set of objects which match a specific search string.
#define NS_ABORT_MSG(msg)
Abnormal program termination.
KeyLocation
The location of the key in the plot.
void TraceSinkUinteger16(uint16_t oldData, uint16_t newData)
Trace sink for receiving data from uint16_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.
Ptr< Probe > GetProbe(std::string probeName) const
Gets the specified probe.
std::string m_yLegend
Legend for the y axis.
Ptr< T > GetObject(void) const
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...
std::string m_title
Title string to use for this plot.
std::string m_terminalType
Terminal type for the plot.