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);
73 m_os.open (jsonFile.c_str ());
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\" : \"";
79 if (args.size () == 0)
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;
112 std::vector<std::string> args;
116 std::ostringstream ss;
131 << (now + delay).GetTimeStep () <<
"\"]";
134 std::unique_lock lock {
m_mutex};
151 m_os <<
" ]" << std::endl;
152 m_os <<
"}" << std::endl;
void Close(void)
Close the output 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.
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.
~DesMetrics(void)
Destructor, closes the trace file.
static std::string m_outputDir
Cache the last-used output directory.
static uint32_t GetContext(void)
Get the current simulation context.
@ NO_CONTEXT
Flag for events not associated with any particular context.
Simulation virtual time values and global simulation resolution.
int64_t GetTimeStep(void) 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.