26 #include "ns3/nstime.h" 54 .SetGroupName (
"Stats")
79 res = sqlite3_get_table (
m_db,
81 &result, &nrows, &ncols,
84 if (res != SQLITE_OK) {
107 sqlite3_free_table (result);
121 if (sqlite3_open (m_dbFile.c_str (), &
m_db)) {
122 NS_LOG_ERROR (
"Could not open sqlite3 database \"" << m_dbFile <<
"\"");
124 sqlite3_close (
m_db);
129 Exec (
"create table if not exists Experiments (run, experiment, strategy, input, description text)");
132 sqlite3_prepare_v2 (
m_db,
133 "insert into Experiments (run, experiment, strategy, input, description) values (?, ?, ?, ?, ?)",
140 sqlite3_bind_text (stmt, 1, run.c_str (), run.length (), SQLITE_TRANSIENT);
150 sqlite3_finalize (stmt);
152 Exec (
"create table if not exists Metadata ( run text, key text, value)");
154 sqlite3_prepare_v2 (
m_db,
155 "insert into Metadata (run, key, value) values (?, ?, ?)",
162 std::pair<std::string, std::string> blob = (*i);
164 sqlite3_reset (stmt);
165 sqlite3_bind_text (stmt, 1, run.c_str (),
166 run.length (), SQLITE_TRANSIENT);
167 sqlite3_bind_text (stmt, 2, blob.first.c_str (),
168 blob.first.length (), SQLITE_TRANSIENT);
169 sqlite3_bind_text (stmt, 3, blob.second.c_str (),
170 blob.second.length (), SQLITE_TRANSIENT);
173 sqlite3_finalize (stmt);
179 (*i)->Output (callback);
183 sqlite3_close (
m_db);
195 m_owner->Exec (
"create table if not exists Singletons ( run text, name text, variable text, value )");
197 sqlite3_prepare_v2 (m_owner->m_db,
198 "insert into Singletons (run, name, variable, value) values (?, ?, ?, ?)",
200 &m_insertSingletonStatement,
203 sqlite3_bind_text (m_insertSingletonStatement, 1, m_runLabel.c_str (), m_runLabel.length (), SQLITE_TRANSIENT);
241 sqlite3_reset (m_insertSingletonStatement);
242 sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
243 sqlite3_bind_text (m_insertSingletonStatement, 3,
variable.c_str (),
variable.length (), SQLITE_TRANSIENT);
244 sqlite3_bind_int (m_insertSingletonStatement, 4, val);
245 sqlite3_step (m_insertSingletonStatement);
254 sqlite3_reset (m_insertSingletonStatement);
255 sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
256 sqlite3_bind_text (m_insertSingletonStatement, 3,
variable.c_str (),
variable.length (), SQLITE_TRANSIENT);
257 sqlite3_bind_int64 (m_insertSingletonStatement, 4, val);
258 sqlite3_step (m_insertSingletonStatement);
268 sqlite3_reset (m_insertSingletonStatement);
269 sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
270 sqlite3_bind_text (m_insertSingletonStatement, 3,
variable.c_str (),
variable.length (), SQLITE_TRANSIENT);
271 sqlite3_bind_double (m_insertSingletonStatement, 4, val);
272 sqlite3_step (m_insertSingletonStatement);
282 sqlite3_reset (m_insertSingletonStatement);
283 sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
284 sqlite3_bind_text (m_insertSingletonStatement, 3,
variable.c_str (),
variable.length (), SQLITE_TRANSIENT);
285 sqlite3_bind_text (m_insertSingletonStatement, 4, val.c_str (), val.length (), SQLITE_TRANSIENT);
286 sqlite3_step (m_insertSingletonStatement);
296 sqlite3_reset (m_insertSingletonStatement);
297 sqlite3_bind_text (m_insertSingletonStatement, 2, key.c_str (), key.length (), SQLITE_TRANSIENT);
298 sqlite3_bind_text (m_insertSingletonStatement, 3,
variable.c_str (),
variable.length (), SQLITE_TRANSIENT);
299 sqlite3_bind_int64 (m_insertSingletonStatement, 4, val.
GetTimeStep ());
300 sqlite3_step (m_insertSingletonStatement);
DataCalculatorList::iterator DataCalculatorEnd()
Returns an iterator to the past-the-end of the DataCalculator list.
Simulation virtual time values and global simulation resolution.
Abstract Data Output Interface class s
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual double getMin() const =0
Returns the minimum of the values.
virtual ~SqliteDataOutput()
Abstract class for calculating statistical data.
virtual double getSqrSum() const =0
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
sqlite3_stmt * m_insertSingletonStatement
Prepared singleton insert statement.
std::string GetInputLabel() const
Return the input label.
std::string GetStrategyLabel() const
Return the strategy label.
Class to generate OMNeT output.
virtual double getStddev() const =0
Returns the standard deviation of the (weighted) observations.
MetadataList::iterator MetadataBegin()
Returns an iterator to the beginning of the metadata list.
virtual double getMax() const =0
Returns the maximum of the values.
virtual void DoDispose()
Destructor implementation.
std::string variable
variable or class member
std::string GetExperimentLabel() const
Return the experiment label.
~SqliteOutputCallback()
Destructor.
std::string GetDescription() const
Return the description label.
std::string GetRunLabel() const
Return the runID label.
SqliteOutputCallback(Ptr< SqliteDataOutput > owner, std::string run)
Constructor.
std::string m_filePrefix
File prefix for the DataOutputInterface.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Outputs data in a format compatible with SQLite.
virtual double getSum() const =0
static TypeId GetTypeId(void)
Register this type.
void OutputSingleton(std::string key, std::string variable, int val)
Generates a single data output.
virtual void DoDispose()
Destructor implementation.
DataCalculatorList::iterator DataCalculatorBegin()
Returns an iterator to the beginning of the DataCalculator list.
sqlite3 * m_db
pointer to the SQL database
bool isNaN(double x)
true if x is NaN
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
void OutputStatistic(std::string key, std::string variable, const StatisticalSummary *statSum)
Generates data statistics.
int Exec(std::string exe)
Execute a sqlite3 query.
virtual long getCount() const =0
Returns the number of observations.
virtual void Output(DataCollector &dc)
Outputs information from the provided DataCollector.
a unique identifier for an interface.
MetadataList::iterator MetadataEnd()
Returns an iterator to the past-the-end of the metadata list.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.