timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::component::network_stats Struct Reference

#include "timemory/components/network/components.hpp"

+ Collaboration diagram for tim::component::network_stats:

Public Types

using value_type = cache::network_stats
 
using this_type = network_stats
 
using base_type = base< this_type, value_type >
 
using data_array_type = typename cache::network_stats::data_type
 
using string_array_type = typename cache::network_stats::string_array_type
 
using iface_map_type = std::unordered_map< std::string, string_array_type >
 
using storage_type = empty_storage
 

Public Member Functions

 network_stats (std::string)
 
 network_stats (std::vector< std::string >)
 
 network_stats ()=default
 
 ~network_stats ()=default
 
 network_stats (const network_stats &)=default
 
 network_stats (network_stats &&)=default
 
network_statsoperator= (const network_stats &)=default
 
network_statsoperator= (network_stats &&)=default
 
data_array_type get () const
 
std::string get_display () const
 
void sample ()
 
void start ()
 
void stop ()
 

Static Public Member Functions

static std::string label ()
 
static std::string description ()
 
static data_array_type data_array (value_type)
 
static data_array_type unit_array ()
 
static string_array_type label_array ()
 
static string_array_type display_unit_array ()
 
static string_array_type description_array ()
 
static value_type record (const std::string &_interface)
 
static value_type record (const std::vector< std::string > &_interfaces)
 
static std::vector< std::string > & get_interfaces ()
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

Static Public Attributes

static constexpr size_t data_size = cache::network_stats::data_size
 

Detailed Description

Definition at line 43 of file components.hpp.

Member Typedef Documentation

◆ base_type

◆ data_array_type

using tim::component::network_stats::data_array_type = typename cache::network_stats::data_type

Definition at line 50 of file components.hpp.

◆ iface_map_type

using tim::component::network_stats::iface_map_type = std::unordered_map<std::string, string_array_type>

Definition at line 52 of file components.hpp.

◆ storage_type

Definition at line 66 of file declaration.hpp.

◆ string_array_type

using tim::component::network_stats::string_array_type = typename cache::network_stats::string_array_type

Definition at line 51 of file components.hpp.

◆ this_type

◆ value_type

using tim::component::network_stats::value_type = cache::network_stats

Definition at line 47 of file components.hpp.

Constructor & Destructor Documentation

◆ network_stats() [1/5]

tim::component::network_stats::network_stats ( std::string  _interface)
inline

Definition at line 126 of file components.hpp.

127: m_interfaces{ std::move(_interface) }
128{}

◆ network_stats() [2/5]

tim::component::network_stats::network_stats ( std::vector< std::string >  _interfaces)
inline

Definition at line 130 of file components.hpp.

131: m_interfaces{ std::move(_interfaces) }
132{}

◆ network_stats() [3/5]

tim::component::network_stats::network_stats ( )
default

◆ ~network_stats()

tim::component::network_stats::~network_stats ( )
default

◆ network_stats() [4/5]

tim::component::network_stats::network_stats ( const network_stats )
default

◆ network_stats() [5/5]

tim::component::network_stats::network_stats ( network_stats &&  )
default

Member Function Documentation

◆ data_array()

network_stats::data_array_type tim::component::network_stats::data_array ( value_type  _data)
inlinestatic

Definition at line 261 of file components.hpp.

262{
263 return _data.get_data();
264}

◆ description()

std::string tim::component::network_stats::description ( )
inlinestatic

Definition at line 98 of file components.hpp.

99{
100 return "Reports network bytes, packets, errors, dropped";
101}

◆ description_array()

network_stats::string_array_type tim::component::network_stats::description_array ( )
inlinestatic

Definition at line 285 of file components.hpp.

286{
287 return cache::network_stats::data_descriptions();
288}

◆ display_unit_array()

network_stats::string_array_type tim::component::network_stats::display_unit_array ( )
inlinestatic

Definition at line 279 of file components.hpp.

280{
281 return cache::network_stats::data_display_units();
282}

◆ get()

network_stats::data_array_type tim::component::network_stats::get ( ) const
inline

Definition at line 188 of file components.hpp.

189{
190 auto _data = load();
191 if(!m_first && !get_is_transient())
192 {
193 _data.get_data().fill(0);
194 return _data.get_data();
195 }
196
197 static auto _data_units = cache::network_stats::data_units();
198 for(size_t i = 0; i < data_size; ++i)
199 _data.get_data()[i] /= _data_units[i];
200 return _data.get_data();
201}
static constexpr size_t data_size
Definition: components.hpp:45

References data_size, tim::component::base< network_stats, cache::network_stats >::get_is_transient(), and tim::component::base< network_stats, cache::network_stats >::load().

Referenced by get_display().

◆ get_display()

std::string tim::component::network_stats::get_display ( ) const
inline

Definition at line 204 of file components.hpp.

205{
206 auto&& _get_display = [](const int64_t& _val, const std::string& _lbl,
207 const std::string& _units) {
208 std::stringstream ss;
210 ss << std::setw(base_type::get_width())
211 << std::setprecision(base_type::get_precision()) << _val;
212 if(!_units.empty())
213 ss << " " << _units;
214 if(!_lbl.empty())
215 ss << " " << _lbl;
216 return ss.str();
217 };
218
219 auto&& _val = value_type{ get() };
220 auto _disp = cache::network_stats::data_display_units();
221 auto _labels = cache::network_stats::data_labels();
222 std::stringstream ss;
223 for(size_t i = 0; i < data_size; ++i)
224 ss << ", " << _get_display(_val.get_data()[i], _labels[i], _disp[i]);
225 return ss.str().substr(2);
226}
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
static short get_precision()
static short get_width()
static fmtflags get_format_flags()
cache::network_stats value_type
Definition: components.hpp:47
data_array_type get() const
Definition: components.hpp:188

References data_size, get(), tim::component::base< Tp, Value >::get_format_flags(), tim::component::base< Tp, Value >::get_precision(), and tim::component::base< Tp, Value >::get_width().

◆ get_interfaces()

std::vector< std::string > & tim::component::network_stats::get_interfaces ( )
inlinestatic

Definition at line 135 of file components.hpp.

136{
137 static std::string _last{};
138 static std::string _value{};
139 static std::vector<std::string> _instance{};
140
142 if(!_settings)
143 return _instance;
144 _settings->get(TIMEMORY_SETTINGS_KEY("NETWORK_INTERFACE"), _value, true);
145
146 auto _update_instance = []() {
147 _instance.clear();
148 for(auto&& itr : delimit(_value, " ,\t;"))
149 {
150 if(itr != "." && itr != "..")
151 _instance.emplace_back(std::move(itr));
152 }
153 };
154
155 if(_instance.empty())
156 {
157 if(!_value.empty())
158 {
159 _update_instance();
160 _last = _value;
161 }
162 else
163 {
164 for(auto&& itr : utility::filesystem::list_directory("/sys/class/net"))
165 {
166 if(itr != "." && itr != "..")
167 _instance.emplace_back(std::move(itr));
168 }
169 if(_instance.empty())
170 return _instance;
171 std::stringstream _ss;
172 for(const auto& itr : _instance)
173 _ss << ", " << itr;
174 _value = _last = _ss.str().substr(2);
175 _settings->set(TIMEMORY_SETTINGS_KEY("NETWORK_INTERFACE"), _value, true);
176 }
177 }
178 else if(_last != _value)
179 {
180 _update_instance();
181 _last = _value;
182 }
183
184 return _instance;
185}
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255
TIMEMORY_SETTINGS_KEY("SUPPRESS_PARSING")) TIMEMORY_SETTINGS_MEMBER_DEF(bool
ContainerT delimit(const std::string &line, const std::string &delimiters="\"',;: ", PredicateT &&predicate=[](const std::string &s) -> std::string { return s;})
Definition: delimit.hpp:68
arg_result get(size_t _idx, Tp &_value)
Definition: argparse.hpp:674
static settings * instance()
Definition: settings.hpp:536

References tim::_settings, tim::delimit(), tim::argparse::argument_parser::get(), tim::settings::instance(), and tim::TIMEMORY_SETTINGS_KEY().

Referenced by start().

◆ get_opaque()

template<typename... Args>
static opaque tim::component::empty_base::get_opaque ( Args &&  ...)
inlinestaticinherited

Definition at line 72 of file declaration.hpp.

73 {
74 return opaque{};
75 }

◆ label()

std::string tim::component::network_stats::label ( )
inlinestatic

Definition at line 92 of file components.hpp.

93{
94 return "network_stats";
95}

◆ label_array()

network_stats::string_array_type tim::component::network_stats::label_array ( )
inlinestatic

Definition at line 273 of file components.hpp.

274{
275 return cache::network_stats::data_labels();
276}

◆ operator=() [1/2]

network_stats & tim::component::network_stats::operator= ( const network_stats )
default

◆ operator=() [2/2]

network_stats & tim::component::network_stats::operator= ( network_stats &&  )
default

◆ record() [1/2]

network_stats::value_type tim::component::network_stats::record ( const std::string &  _interface)
inlinestatic

Definition at line 104 of file components.hpp.

105{
106 if(_interface.empty())
107 return cache::network_stats{};
108 // const auto& _iface_paths = get_iface_paths(_name);
109 return cache::network_stats{ _interface };
110}

Referenced by sample(), start(), and stop().

◆ record() [2/2]

network_stats::value_type tim::component::network_stats::record ( const std::vector< std::string > &  _interfaces)
inlinestatic

Definition at line 113 of file components.hpp.

114{
115 if(_interfaces.empty())
116 return cache::network_stats{};
117 cache::network_stats _data{};
118 for(const auto& itr : _interfaces)
119 {
120 if(!itr.empty())
121 _data += cache::network_stats{ itr };
122 }
123 return _data;
124}

◆ sample()

void tim::component::network_stats::sample ( )
inline

Definition at line 229 of file components.hpp.

230{
231 if(m_first)
232 {
233 m_first = false;
234 value = record(m_interfaces);
235 }
236 else
237 {
238 auto _current = record(m_interfaces);
239 accum += _current - value;
240 value = _current;
241 set_is_transient(true);
242 }
243}
static value_type record(const std::string &_interface)
Definition: components.hpp:104

References record(), and tim::component::base< network_stats, cache::network_stats >::set_is_transient().

◆ start()

void tim::component::network_stats::start ( )
inline

Definition at line 246 of file components.hpp.

247{
248 if(m_interfaces.empty())
249 m_interfaces = get_interfaces();
250 value = record(m_interfaces);
251}
static std::vector< std::string > & get_interfaces()
Definition: components.hpp:135

References get_interfaces(), and record().

◆ stop()

void tim::component::network_stats::stop ( )
inline

Definition at line 254 of file components.hpp.

255{
256 value = record(m_interfaces) - value;
257 accum += value;
258}

References record().

◆ unit_array()

network_stats::data_array_type tim::component::network_stats::unit_array ( )
inlinestatic

Definition at line 267 of file components.hpp.

268{
269 return cache::network_stats::data_units();
270}

Member Data Documentation

◆ data_size

constexpr size_t tim::component::network_stats::data_size = cache::network_stats::data_size
staticconstexpr

Definition at line 45 of file components.hpp.

Referenced by get(), and get_display().


The documentation for this struct was generated from the following file: