A Discrete-Event Network Simulator
API
des-metrics.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 LLNL
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
18  */
19 
20 #ifndef DESMETRICS_H
21 #define DESMETRICS_H
22 
29 #include "nstime.h"
30 #include "singleton.h"
31 
32 #include <fstream>
33 #include <mutex>
34 #include <stdint.h> // uint32_t
35 #include <string>
36 #include <vector>
37 
38 namespace ns3
39 {
40 
109 class DesMetrics : public Singleton<DesMetrics>
110 {
111  public:
121  void Initialize(std::vector<std::string> args, std::string outDir = "");
122 
129  void Trace(const Time& now, const Time& delay);
130 
138  void TraceWithContext(uint32_t context, const Time& now, const Time& delay);
139 
143  ~DesMetrics() override;
144 
145  private:
147  void Close();
148 
155  static std::string m_outputDir;
156 
158  std::ofstream m_os;
159  char m_separator;
160 
162  std::mutex m_mutex;
163 
164 }; // class DesMetrics
165 
166 } // namespace ns3
167 
168 #endif /* DESMETRICS_H */
Event trace data collector for the DES Metrics project.
Definition: des-metrics.h:110
~DesMetrics() override
Destructor, closes the trace file.
Definition: des-metrics.cc:137
bool m_initialized
Have we been initialized.
Definition: des-metrics.h:157
std::mutex m_mutex
Mutex to control access to the output file.
Definition: des-metrics.h:162
void Initialize(std::vector< std::string > args, std::string outDir="")
Open the DesMetrics trace file and print the header.
Definition: des-metrics.cc:42
void Close()
Close the output file.
Definition: des-metrics.cc:143
char m_separator
The separator between event records.
Definition: des-metrics.h:159
void Trace(const Time &now, const Time &delay)
Trace an event to self at the time it is scheduled.
Definition: des-metrics.cc:101
void TraceWithContext(uint32_t context, const Time &now, const Time &delay)
Trace an event (with context) at the time it is scheduled.
Definition: des-metrics.cc:107
std::ofstream m_os
The output JSON trace file stream.
Definition: des-metrics.h:158
static std::string m_outputDir
Cache the last-used output directory.
Definition: des-metrics.h:155
A template singleton.
Definition: singleton.h:61
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
ns3::Singleton declaration and template implementation.