timemory  3.2.1
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 >
 

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 ()
 

Static Public Attributes

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

Detailed Description

Definition at line 44 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 51 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 53 of file components.hpp.

◆ string_array_type

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

Definition at line 52 of file components.hpp.

◆ this_type

◆ value_type

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

Definition at line 48 of file components.hpp.

Constructor & Destructor Documentation

◆ network_stats() [1/5]

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

Definition at line 127 of file components.hpp.

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

◆ network_stats() [2/5]

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

Definition at line 131 of file components.hpp.

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

◆ 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 262 of file components.hpp.

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

◆ description()

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

Definition at line 99 of file components.hpp.

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

◆ description_array()

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

Definition at line 286 of file components.hpp.

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

◆ display_unit_array()

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

Definition at line 280 of file components.hpp.

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

◆ get()

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

Definition at line 189 of file components.hpp.

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

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 205 of file components.hpp.

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

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 136 of file components.hpp.

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

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

Referenced by start().

◆ label()

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

Definition at line 93 of file components.hpp.

94 {
95  return "network_stats";
96 }

◆ label_array()

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

Definition at line 274 of file components.hpp.

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

◆ 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 105 of file components.hpp.

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

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 114 of file components.hpp.

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

◆ sample()

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

Definition at line 230 of file components.hpp.

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

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 247 of file components.hpp.

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

References get_interfaces(), and record().

◆ stop()

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

Definition at line 255 of file components.hpp.

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

References record().

◆ unit_array()

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

Definition at line 268 of file components.hpp.

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

Member Data Documentation

◆ data_size

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

Definition at line 46 of file components.hpp.

Referenced by get(), and get_display().


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