A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
time-data-calculators.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 Drexel University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Joe Kopena (tjkopena@cs.drexel.edu)
7 */
8
10
11#include "ns3/log.h"
12#include "ns3/nstime.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TimeDataCalculators");
17
18//--------------------------------------------------------------
19//----------------------------------------------
26
31
32/* static */
35{
36 static TypeId tid = TypeId("ns3::TimeMinMaxAvgTotalCalculator")
38 .SetGroupName("Stats")
39 .AddConstructor<TimeMinMaxAvgTotalCalculator>();
40 return tid;
41}
42
43void
45{
46 NS_LOG_FUNCTION(this);
47
49 // TimeMinMaxAvgTotalCalculator::DoDispose
50}
51
52void
54{
55 NS_LOG_FUNCTION(this << i);
56
57 if (m_enabled)
58 {
59 if (m_count)
60 {
61 m_total += i;
62
63 if (i < m_min)
64 {
65 m_min = i;
66 }
67
68 if (i > m_max)
69 {
70 m_max = i;
71 }
72 }
73 else
74 {
75 m_min = i;
76 m_max = i;
77 m_total = i;
78 }
79 m_count++;
80 }
81 // end TimeMinMaxAvgTotalCalculator::Update
82}
83
84void
86{
87 NS_LOG_FUNCTION(this << &callback);
88
89 callback.OutputSingleton(m_context, m_key + "-count", m_count);
90 if (m_count > 0)
91 {
92 callback.OutputSingleton(m_context, m_key + "-total", m_total);
93 callback.OutputSingleton(m_context, m_key + "-average", Time(m_total / m_count));
94 callback.OutputSingleton(m_context, m_key + "-max", m_max);
95 callback.OutputSingleton(m_context, m_key + "-min", m_min);
96 }
97 // end TimeMinMaxAvgTotalCalculator::Output
98}
Calculates data during a simulation.
bool m_enabled
Descendant classes must check & respect m_enabled!
std::string m_context
Context value.
std::string m_key
Key value.
void DoDispose() override
Destructor implementation.
Callback class for the DataOutput classes.
virtual void OutputSingleton(std::string key, std::string variable, int val)=0
Associates the integer value with the variable name for a specific output format.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Unfortunately, templating the base MinMaxAvgTotalCalculator to operate over Time values isn't straigh...
Time m_total
Total value of TimeMinMaxAvgTotalCalculator.
void Update(const Time i)
Updates all variables of TimeMinMaxAvgTotalCalculator.
void DoDispose() override
Destructor implementation.
void Output(DataOutputCallback &callback) const override
Outputs data based on the provided callback.
static TypeId GetTypeId()
Register this type.
uint32_t m_count
Count value of TimeMinMaxAvgTotalCalculator.
Time m_min
Minimum value of TimeMinMaxAvgTotalCalculator.
Time m_max
Maximum value of TimeMinMaxAvgTotalCalculator.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.