52 std::string model_name(
"desTraceFile");
55 std::string arg0 = args[0];
58 std::string jsonFile = model_name +
".json";
70 const char* date = ctime(¤t_time);
71 std::string capture_date(date, 24);
74 m_os <<
"{" << std::endl;
75 m_os <<
" \"simulator_name\" : \"ns-3\"," << std::endl;
76 m_os <<
" \"model_name\" : \"" << model_name <<
"\"," << std::endl;
77 m_os <<
" \"capture_date\" : \"" << capture_date <<
"\"," << std::endl;
78 m_os <<
" \"command_line_arguments\" : \"";
81 for (std::size_t i = 0; i < args.size(); ++i)
92 m_os <<
"[argv empty or not available]";
94 m_os <<
"\"," << std::endl;
95 m_os <<
" \"events\" : [" << std::endl;
111 std::vector<std::string> args;
115 std::ostringstream ss;
126 ss <<
" [\"" << send <<
"\",\"" << now.
GetTimeStep() <<
"\",\"" << recv <<
"\",\""
127 << (now + delay).GetTimeStep() <<
"\"]";
130 std::unique_lock lock{
m_mutex};
147 m_os <<
" ]" << std::endl;
148 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.