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::units Namespace Reference

Functions

std::string time_repr (int64_t _unit)
 
std::string mem_repr (int64_t _unit)
 
std::tuple< std::string, int64_t > get_memory_unit (std::string _unit)
 
std::tuple< std::string, int64_t > get_timing_unit (std::string _unit)
 

Function Documentation

◆ get_memory_unit()

std::tuple< std::string, int64_t > tim::units::get_memory_unit ( std::string  _unit)
inline

Definition at line 188 of file units.hpp.

189{
190 using string_t = std::string;
191 using return_type = std::tuple<string_t, int64_t>;
192 using inner_t = std::tuple<string_t, string_t, int64_t>;
193
194 if(_unit.length() == 0)
195 return return_type{ "MB", tim::units::megabyte };
196
197 for(auto& itr : _unit)
198 itr = tolower(itr);
199
200 for(const auto& itr : { inner_t{ "byte", "b", tim::units::byte },
201 inner_t{ "kilobyte", "kb", tim::units::kilobyte },
202 inner_t{ "megabyte", "mb", tim::units::megabyte },
203 inner_t{ "gigabyte", "gb", tim::units::gigabyte },
204 inner_t{ "terabyte", "tb", tim::units::terabyte },
205 inner_t{ "petabyte", "pb", tim::units::petabyte },
206 inner_t{ "kibibyte", "kib", tim::units::KiB },
207 inner_t{ "mebibyte", "mib", tim::units::MiB },
208 inner_t{ "gibibyte", "gib", tim::units::GiB },
209 inner_t{ "tebibyte", "tib", tim::units::TiB },
210 inner_t{ "pebibyte", "pib", tim::units::PiB } })
211 {
212 if(_unit == std::get<0>(itr) || _unit == std::get<1>(itr))
213 {
214 if(std::get<0>(itr) == "byte")
215 return return_type(std::get<0>(itr), std::get<2>(itr));
216 return return_type(std::get<1>(itr), std::get<2>(itr));
217 }
218 }
219
220 std::cerr << "Warning!! No memory unit matching \"" << _unit << "\". Using default..."
221 << std::endl;
222
223 return return_type{ "MB", tim::units::megabyte };
224}
std::string string_t
Definition: utility.hpp:98
tim::mpl::apply< std::string > string
Definition: macros.hpp:53

Referenced by tim::component::read_char::get_display_unit(), tim::component::written_char::get_display_unit(), tim::component::read_bytes::get_display_unit(), tim::component::written_bytes::get_display_unit(), tim::component::current_peak_rss::get_display_unit(), tim::component::read_char::get_unit(), tim::component::written_char::get_unit(), tim::component::read_bytes::get_unit(), tim::component::written_bytes::get_unit(), and tim::component::current_peak_rss::get_unit().

◆ get_timing_unit()

std::tuple< std::string, int64_t > tim::units::get_timing_unit ( std::string  _unit)
inline

Definition at line 229 of file units.hpp.

230{
231 using string_t = std::string;
232 using strset_t = std::unordered_set<string_t>;
233 using return_type = std::tuple<string_t, int64_t>;
234 using inner_t = std::tuple<string_t, strset_t, int64_t>;
235
236 if(_unit.length() == 0)
237 return return_type{ "sec", tim::units::sec };
238
239 for(auto& itr : _unit)
240 itr = tolower(itr);
241
242 for(const auto& itr :
243 { inner_t{ "nsec", strset_t{ "ns", "nanosecond", "nanoseconds" },
244 tim::units::nsec },
245 inner_t{ "usec", strset_t{ "us", "microsecond", "microseconds" },
246 tim::units::usec },
247 inner_t{ "msec", strset_t{ "ms", "millisecond", "milliseconds" },
248 tim::units::msec },
249 inner_t{ "csec", strset_t{ "cs", "centisecond", "centiseconds" },
250 tim::units::csec },
251 inner_t{ "dsec", strset_t{ "ds", "decisecond", "deciseconds" },
252 tim::units::dsec },
253 inner_t{ "sec", strset_t{ "s", "second", "seconds" }, tim::units::sec },
254 inner_t{ "min", strset_t{ "minute", "minutes" }, tim::units::minute },
255 inner_t{ "hr", strset_t{ "hr", "hour", "hours" }, tim::units::hour } })
256 {
257 if(_unit == std::get<0>(itr) ||
258 std::get<1>(itr).find(_unit) != std::get<1>(itr).end())
259 {
260 return return_type{ std::get<0>(itr), std::get<2>(itr) };
261 }
262 }
263
264 std::cerr << "Warning!! No timing unit matching \"" << _unit << "\". Using default..."
265 << std::endl;
266
267 return return_type{ "sec", tim::units::sec };
268}
return _hash_map end()

Referenced by tim::component::read_char::get_display_unit(), tim::component::written_char::get_display_unit(), tim::component::read_bytes::get_display_unit(), tim::component::written_bytes::get_display_unit(), tim::component::read_char::get_timing_unit(), tim::component::written_char::get_timing_unit(), tim::component::read_bytes::get_timing_unit(), tim::component::written_bytes::get_timing_unit(), tim::component::read_char::get_unit(), tim::component::written_char::get_unit(), tim::component::read_bytes::get_unit(), and tim::component::written_bytes::get_unit().

◆ mem_repr()

std::string tim::units::mem_repr ( int64_t  _unit)
inline

Definition at line 164 of file units.hpp.

165{
166 std::string _sunit;
167 switch(_unit)
168 {
169 case byte: _sunit = "B"; break;
170 case kilobyte: _sunit = "KB"; break;
171 case megabyte: _sunit = "MB"; break;
172 case gigabyte: _sunit = "GB"; break;
173 case terabyte: _sunit = "TB"; break;
174 case petabyte: _sunit = "PB"; break;
175 case kibibyte: _sunit = "KiB"; break;
176 case mebibyte: _sunit = "MiB"; break;
177 case gibibyte: _sunit = "GiB"; break;
178 case tebibyte: _sunit = "TiB"; break;
179 case pebibyte: _sunit = "PiB"; break;
180 default: _sunit = "UNK"; break;
181 }
182 return _sunit;
183}

◆ time_repr()

std::string tim::units::time_repr ( int64_t  _unit)
inline

Definition at line 145 of file units.hpp.

146{
147 std::string _sunit;
148 switch(_unit)
149 {
150 case nsec: _sunit = "nsec"; break;
151 case usec: _sunit = "usec"; break;
152 case msec: _sunit = "msec"; break;
153 case csec: _sunit = "csec"; break;
154 case dsec: _sunit = "dsec"; break;
155 case sec: _sunit = "sec"; break;
156 default: _sunit = "UNK"; break;
157 }
158 return _sunit;
159}

Referenced by tim::component::ert_timer::get_display_unit().