41 std::string model_name(
"desTraceFile");
44 std::string arg0 = args[0];
47 std::string jsonFile = model_name +
".json";
59 const char* date = ctime(¤t_time);
60 std::string capture_date(date, 24);
63 m_os <<
"{" << std::endl;
64 m_os <<
" \"simulator_name\" : \"ns-3\"," << std::endl;
65 m_os <<
" \"model_name\" : \"" << model_name <<
"\"," << std::endl;
66 m_os <<
" \"capture_date\" : \"" << capture_date <<
"\"," << std::endl;
67 m_os <<
" \"command_line_arguments\" : \"";
70 for (std::size_t i = 0; i < args.size(); ++i)
81 m_os <<
"[argv empty or not available]";
83 m_os <<
"\"," << std::endl;
84 m_os <<
" \"events\" : [" << std::endl;
100 std::vector<std::string> args;
104 std::ostringstream ss;
115 ss <<
" [\"" << send <<
"\",\"" << now.
GetTimeStep() <<
"\",\"" << recv <<
"\",\""
116 << (now + delay).GetTimeStep() <<
"\"]";
119 std::unique_lock lock{
m_mutex};
136 m_os <<
" ]" << std::endl;
137 m_os <<
"}" << std::endl;
~DesMetrics() override
Destructor, closes the trace file.
bool m_initialized
Have we been initialized.
std::mutex m_mutex
Mutex to control access to the output file.
void Initialize(std::vector< std::string > args, std::string outDir="")
Open the DesMetrics trace file and print the header.
void Close()
Close the output file.
char m_separator
The separator between event records.
void Trace(const Time &now, const Time &delay)
Trace an event to self at the time it is scheduled.
void TraceWithContext(uint32_t context, const Time &now, const Time &delay)
Trace an event (with context) at the time it is scheduled.
std::ofstream m_os
The output JSON trace file stream.
static std::string m_outputDir
Cache the last-used output directory.
@ NO_CONTEXT
Flag for events not associated with any particular context.
static uint32_t GetContext()
Get the current simulation context.
Simulation virtual time values and global simulation resolution.
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
ns3::DesMetrics declaration.
std::list< std::string > Split(std::string path)
Split a file system path into directories according to the local path separator.
std::string Append(std::string left, std::string right)
Join two file system path elements.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Simulator declaration.
ns3::SystemPath declarations.