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.
components.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25/**
26 * \file timemory/components/io/components.hpp
27 * \brief Implementation of the io component(s)
28 */
29
30#pragma once
31
33#include "timemory/components/io/backends.hpp"
35#include "timemory/components/timing/backends.hpp"
39#include "timemory/units.hpp"
40
41//======================================================================================//
42//
43namespace tim
44{
45namespace component
46{
47//--------------------------------------------------------------------------------------//
48/// \struct tim::component::read_char
49/// \brief I/O counter for chars read. The number of bytes which this task has caused to
50/// be read from storage. This is simply the sum of bytes which this process passed to
51/// read() and pread(). It includes things like tty IO and it is unaffected by whether or
52/// not actual physical disk IO was required (the read might have been satisfied from
53/// pagecache)
54struct read_char : public base<read_char, std::pair<int64_t, int64_t>>
55{
57 using value_type = std::pair<int64_t, int64_t>;
59 using result_type = std::pair<double, double>;
62
63 static std::string label() { return "read_char"; }
65 {
66 return "Number of bytes which this task has caused to be read from storage. Sum "
67 "of bytes which this process passed to read() and pread(). Not disk IO.";
68 }
69
70 static std::pair<double, double> unit()
71 {
72 return std::pair<double, double>{
73 units::megabyte, static_cast<double>(units::megabyte) / units::sec
74 };
75 }
76
77 static std::vector<std::string> display_unit_array()
78 {
79 return std::vector<std::string>{ std::get<0>(get_display_unit()),
80 std::get<1>(get_display_unit()) };
81 }
82
83 static std::vector<std::string> label_array()
84 {
85 return std::vector<std::string>{ label(), "read_rate" };
86 }
87
89 {
90 return display_unit_type{ "MB", "MB/sec" };
91 }
92
93 static std::pair<double, double> unit_array() { return unit(); }
94
95 static std::vector<std::string> description_array()
96 {
97 return std::vector<std::string>{ "Number of char read", "Rate of char read" };
98 }
99
100 static auto get_timestamp() { return tim::get_clock_real_now<int64_t, std::nano>(); }
101
102 static value_type record() { return value_type(get_char_read(), get_timestamp()); }
103
104 static auto get_timing_unit()
105 {
106 static auto _value = units::sec;
107 if(settings::timing_units().length() > 0)
108 _value = std::get<1>(units::get_timing_unit(settings::timing_units()));
109 return _value;
110 }
111
112 TIMEMORY_NODISCARD std::string get_display() const
113 {
114 std::stringstream ss;
115 std::stringstream ssv;
116 std::stringstream ssr;
117 auto _prec = base_type::get_precision();
118 auto _width = base_type::get_width();
119 auto _flags = base_type::get_format_flags();
120 auto _disp = get_display_unit();
121
122 auto _val = get();
123
124 ssv.setf(_flags);
125 ssv << std::setw(_width) << std::setprecision(_prec) << std::get<0>(_val);
126 if(!std::get<0>(_disp).empty())
127 ssv << " " << std::get<0>(_disp);
128
129 ssr.setf(_flags);
130 ssr << std::setw(_width) << std::setprecision(_prec) << std::get<1>(_val);
131 if(!std::get<1>(_disp).empty())
132 ssr << " " << std::get<1>(_disp);
133
134 ss << ssv.str() << ", " << ssr.str();
135 ss << " rchar";
136 return ss.str();
137 }
138
139 TIMEMORY_NODISCARD result_type get() const
140 {
141 auto val = base_type::load();
142
143 double data = std::get<0>(val);
144 double delta = std::get<1>(val);
145
146 delta /= static_cast<double>(std::nano::den);
147 delta *= get_timing_unit();
148
149 double rate = 0.0;
150 if(delta != 0.0)
151 rate = data / delta;
152
153 if(laps > 0)
154 rate *= laps;
155
156 data /= std::get<0>(get_unit());
157 rate /= std::get<0>(get_unit());
158
159 if(!std::isfinite(rate))
160 rate = 0.0;
161
162 return result_type(data, rate);
163 }
164
165 void start() { value = record(); }
166
167 void stop()
168 {
169 using namespace tim::component::operators;
170 auto diff = (record() - value);
171 std::get<0>(diff) = std::abs(std::get<0>(diff));
172 accum += (value = diff);
173 }
174
176 {
177 static auto _instance = this_type::unit();
178 static auto& _mem = std::get<0>(_instance);
179 static auto& _rate = std::get<1>(_instance);
180
181 if(settings::memory_units().length() > 0)
182 _mem = std::get<1>(units::get_memory_unit(settings::memory_units()));
183
184 if(settings::timing_units().length() > 0)
185 {
186 auto _timing_val =
188 _rate = _mem / (_timing_val);
189 }
190
191 static const auto factor = static_cast<double>(std::nano::den);
192 unit_type _tmp = _instance;
193 std::get<1>(_tmp) *= factor;
194
195 return _tmp;
196 }
197
199 {
200 static display_unit_type _instance = this_type::display_unit();
201 static auto& _mem = std::get<0>(_instance);
202 static auto& _rate = std::get<1>(_instance);
203
204 if(settings::memory_units().length() > 0)
205 _mem = std::get<0>(units::get_memory_unit(settings::memory_units()));
206
207 if(settings::timing_units().length() > 0)
208 {
209 auto _tval = std::get<0>(units::get_timing_unit(settings::timing_units()));
210 _rate = mpl::apply<std::string>::join('/', _mem, _tval);
211 }
212 else if(settings::memory_units().length() > 0)
213 {
214 _rate = mpl::apply<std::string>::join('/', _mem, "sec");
215 }
216
217 return _instance;
218 }
219
220 /// sample a measurement
221 void sample()
222 {
223 std::get<0>(accum) = std::get<0>(value) =
224 std::max<int64_t>(std::get<0>(value), get_char_read());
225 }
226
227 /// sample a measurement from cached data
228 void sample(const cache_type& _cache)
229 {
230 std::get<0>(accum) = std::get<0>(value) =
231 std::max<int64_t>(std::get<0>(value), _cache.get_char_read());
232 }
233
234 /// read the value from cached data
235 static value_type record(const cache_type& _cache)
236 {
237 return value_type{ _cache.get_char_read(), get_timestamp() };
238 }
239
240 /// start a measurement using the cached data
241 void start(const cache_type& _cache) { value = record(_cache); }
242
243 /// stop a measurement using the cached data
244 void stop(const cache_type& _cache)
245 {
246 using namespace tim::component::operators;
247 auto diff = (record(_cache) - value);
248 std::get<0>(diff) = std::abs(std::get<0>(diff));
249 accum += (value = diff);
250 }
251};
252
253//--------------------------------------------------------------------------------------//
254/// \struct tim::component::written_char
255/// \brief I/O counter for chars written. The number of bytes which this task has caused,
256/// or shall cause to be written to disk. Similar caveats apply here as with \ref
257/// tim::component::read_char (rchar).
258struct written_char : public base<written_char, std::array<int64_t, 2>>
259{
261 using value_type = std::array<int64_t, 2>;
263 using result_type = std::array<double, 2>;
266
267 static std::string label() { return "written_char"; }
269 {
270 return "Number of bytes which this task has caused, or shall cause to be written "
271 "to disk. Similar caveats to read_char.";
272 }
273
275 {
276 return result_type{ { units::megabyte,
277 static_cast<double>(units::megabyte) / units::sec } };
278 }
279
280 static std::vector<std::string> display_unit_array()
281 {
282 return std::vector<std::string>{ std::get<0>(get_display_unit()),
283 std::get<1>(get_display_unit()) };
284 }
285
286 static std::vector<std::string> label_array()
287 {
288 return std::vector<std::string>{ label(), "written_rate" };
289 }
290
292 {
293 return display_unit_type{ { "MB", "MB/sec" } };
294 }
295
296 static std::array<double, 2> unit_array() { return unit(); }
297
298 static std::vector<std::string> description_array()
299 {
300 return std::vector<std::string>{ "Number of char written",
301 "Rate of char written" };
302 }
303
304 static auto get_timestamp() { return tim::get_clock_real_now<int64_t, std::nano>(); }
305
307 {
308 return value_type{ { get_char_written(), get_timestamp() } };
309 }
310
311 static auto get_timing_unit()
312 {
313 static auto _value = units::sec;
314 if(settings::timing_units().length() > 0)
315 _value = std::get<1>(units::get_timing_unit(settings::timing_units()));
316 return _value;
317 }
318
319 TIMEMORY_NODISCARD std::string get_display() const
320 {
321 std::stringstream ss;
322 std::stringstream ssv;
323 std::stringstream ssr;
324 auto _prec = base_type::get_precision();
325 auto _width = base_type::get_width();
326 auto _flags = base_type::get_format_flags();
327 auto _disp = get_display_unit();
328
329 auto _val = get();
330
331 ssv.setf(_flags);
332 ssv << std::setw(_width) << std::setprecision(_prec) << std::get<0>(_val);
333 if(!std::get<0>(_disp).empty())
334 ssv << " " << std::get<0>(_disp);
335
336 ssr.setf(_flags);
337 ssr << std::setw(_width) << std::setprecision(_prec) << std::get<1>(_val);
338 if(!std::get<1>(_disp).empty())
339 ssr << " " << std::get<1>(_disp);
340
341 ss << ssv.str() << ", " << ssr.str();
342 ss << " wchar";
343 return ss.str();
344 }
345
346 TIMEMORY_NODISCARD result_type get() const
347 {
348 auto val = base_type::load();
349
350 double data = std::get<0>(val);
351 double delta = std::get<1>(val);
352
353 delta /= static_cast<double>(std::nano::den);
354 delta *= get_timing_unit();
355
356 double rate = 0.0;
357 if(delta != 0.0)
358 rate = data / delta;
359
360 if(laps > 0)
361 rate *= laps;
362
363 data /= std::get<0>(get_unit());
364 rate /= std::get<0>(get_unit());
365
366 if(!std::isfinite(rate))
367 rate = 0.0;
368
369 return result_type{ { data, rate } };
370 }
371
372 void start() { value = record(); }
373
374 void stop()
375 {
376 using namespace tim::component::operators;
377 auto diff = (record() - value);
378 std::get<0>(diff) = std::abs(std::get<0>(diff));
379 accum += (value = diff);
380 }
381
383 {
384 static auto _instance = this_type::unit();
385 static auto& _mem = std::get<0>(_instance);
386 static auto& _rate = std::get<1>(_instance);
387
388 if(settings::memory_units().length() > 0)
389 _mem = std::get<1>(units::get_memory_unit(settings::memory_units()));
390
391 if(settings::timing_units().length() > 0)
392 {
393 auto _timing_val =
395 _rate = _mem / (_timing_val);
396 }
397
398 static const auto factor = static_cast<double>(std::nano::den);
399 unit_type _tmp = _instance;
400 std::get<1>(_tmp) *= factor;
401
402 return _tmp;
403 }
404
406 {
407 static display_unit_type _instance = this_type::display_unit();
408 static auto& _mem = std::get<0>(_instance);
409 static auto& _rate = std::get<1>(_instance);
410
411 if(settings::memory_units().length() > 0)
412 _mem = std::get<0>(units::get_memory_unit(settings::memory_units()));
413
414 if(settings::timing_units().length() > 0)
415 {
416 auto _tval = std::get<0>(units::get_timing_unit(settings::timing_units()));
417 _rate = mpl::apply<std::string>::join('/', _mem, _tval);
418 }
419 else if(settings::memory_units().length() > 0)
420 {
421 _rate = mpl::apply<std::string>::join('/', _mem, "sec");
422 }
423
424 return _instance;
425 }
426
427 /// sample a measurement
428 void sample()
429 {
430 std::get<0>(accum) = std::get<0>(value) =
431 std::max<int64_t>(std::get<0>(value), get_char_written());
432 }
433
434 /// sample a measurement from cached data
435 void sample(const cache_type& _cache)
436 {
437 std::get<0>(accum) = std::get<0>(value) =
438 std::max<int64_t>(std::get<0>(value), _cache.get_char_written());
439 }
440
441 /// read the value from cached data
442 static value_type record(const cache_type& _cache)
443 {
444 return value_type{ { _cache.get_char_written(), get_timestamp() } };
445 }
446
447 /// start a measurement using the cached data
448 void start(const cache_type& _cache) { value = record(_cache); }
449
450 /// stop a measurement using the cached data
451 void stop(const cache_type& _cache)
452 {
453 using namespace tim::component::operators;
454 auto diff = (record(_cache) - value);
455 std::get<0>(diff) = std::abs(std::get<0>(diff));
456 accum += (value = diff);
457 }
458};
459
460//--------------------------------------------------------------------------------------//
461/// \struct tim::component::read_bytes
462/// \brief I/O counter for bytes read. Attempt to count the number of bytes which this
463/// process really did cause to be fetched from the storage layer. Done at the
464/// submit_bio() level, so it is accurate for block-backed filesystems.
465struct read_bytes : public base<read_bytes, std::pair<int64_t, int64_t>>
466{
468 using value_type = std::pair<int64_t, int64_t>;
470 using result_type = std::pair<double, double>;
473
474 static std::string label() { return "read_bytes"; }
476 {
477 return "Number of bytes which this process really did cause to be fetched from "
478 "the storage layer";
479 }
480
481 static std::pair<double, double> unit()
482 {
483 return std::pair<double, double>{
484 units::megabyte, static_cast<double>(units::megabyte) / units::sec
485 };
486 }
487
488 static std::vector<std::string> display_unit_array()
489 {
490 return std::vector<std::string>{ std::get<0>(get_display_unit()),
491 std::get<1>(get_display_unit()) };
492 }
493
494 static std::vector<std::string> label_array()
495 {
496 return std::vector<std::string>{ label(), "read_rate" };
497 }
498
500 {
501 return display_unit_type{ "MB", "MB/sec" };
502 }
503
504 static std::pair<double, double> unit_array() { return unit(); }
505
506 static std::vector<std::string> description_array()
507 {
508 return std::vector<std::string>{ "Number of bytes read", "Rate of bytes read" };
509 }
510
511 static auto get_timestamp() { return tim::get_clock_real_now<int64_t, std::nano>(); }
512
513 static value_type record() { return value_type(get_bytes_read(), get_timestamp()); }
514
515 static auto get_timing_unit()
516 {
517 static auto _value = units::sec;
518 if(settings::timing_units().length() > 0)
519 _value = std::get<1>(units::get_timing_unit(settings::timing_units()));
520 return _value;
521 }
522
523 TIMEMORY_NODISCARD std::string get_display() const
524 {
525 std::stringstream ss;
526 std::stringstream ssv;
527 std::stringstream ssr;
528 auto _prec = base_type::get_precision();
529 auto _width = base_type::get_width();
530 auto _flags = base_type::get_format_flags();
531 auto _disp = get_display_unit();
532
533 auto _val = get();
534
535 ssv.setf(_flags);
536 ssv << std::setw(_width) << std::setprecision(_prec) << std::get<0>(_val);
537 if(!std::get<0>(_disp).empty())
538 ssv << " " << std::get<0>(_disp);
539
540 ssr.setf(_flags);
541 ssr << std::setw(_width) << std::setprecision(_prec) << std::get<1>(_val);
542 if(!std::get<1>(_disp).empty())
543 ssr << " " << std::get<1>(_disp);
544
545 ss << ssv.str() << ", " << ssr.str();
546 ss << " read_bytes";
547 return ss.str();
548 }
549
550 TIMEMORY_NODISCARD result_type get() const
551 {
552 auto val = base_type::load();
553
554 double data = std::get<0>(val);
555 double delta = std::get<1>(val);
556
557 delta /= static_cast<double>(std::nano::den);
558 delta *= get_timing_unit();
559
560 double rate = 0.0;
561 if(delta != 0.0)
562 rate = data / delta;
563
564 if(laps > 0)
565 rate *= laps;
566
567 data /= std::get<0>(get_unit());
568 rate /= std::get<0>(get_unit());
569
570 if(!std::isfinite(rate))
571 rate = 0.0;
572
573 return result_type(data, rate);
574 }
575
576 void start() { value = record(); }
577
578 void stop()
579 {
580 using namespace tim::component::operators;
581 auto diff = (record() - value);
582 std::get<0>(diff) = std::abs(std::get<0>(diff));
583 accum += (value = diff);
584 }
585
587 {
588 static auto _instance = this_type::unit();
589 static auto& _mem = std::get<0>(_instance);
590 static auto& _rate = std::get<1>(_instance);
591
592 if(settings::memory_units().length() > 0)
593 _mem = std::get<1>(units::get_memory_unit(settings::memory_units()));
594
595 if(settings::timing_units().length() > 0)
596 {
597 auto _timing_val =
599 _rate = _mem / (_timing_val);
600 }
601
602 static const auto factor = static_cast<double>(std::nano::den);
603 unit_type _tmp = _instance;
604 std::get<1>(_tmp) *= factor;
605
606 return _tmp;
607 }
608
610 {
611 static display_unit_type _instance = this_type::display_unit();
612 static auto& _mem = std::get<0>(_instance);
613 static auto& _rate = std::get<1>(_instance);
614
615 if(settings::memory_units().length() > 0)
616 _mem = std::get<0>(units::get_memory_unit(settings::memory_units()));
617
618 if(settings::timing_units().length() > 0)
619 {
620 auto _tval = std::get<0>(units::get_timing_unit(settings::timing_units()));
621 _rate = mpl::apply<std::string>::join('/', _mem, _tval);
622 }
623 else if(settings::memory_units().length() > 0)
624 {
625 _rate = mpl::apply<std::string>::join('/', _mem, "sec");
626 }
627
628 return _instance;
629 }
630
631 /// sample a measurement
632 void sample()
633 {
634 std::get<0>(accum) = std::get<0>(value) =
635 std::max<int64_t>(std::get<0>(value), get_bytes_read());
636 }
637
638 /// sample a measurement from cached data
639 void sample(const cache_type& _cache)
640 {
641 std::get<0>(accum) = std::get<0>(value) =
642 std::max<int64_t>(std::get<0>(value), _cache.get_bytes_read());
643 }
644
645 /// read the value from the cache
646 static value_type record(const cache_type& _cache)
647 {
648 return value_type{ _cache.get_bytes_read(), get_timestamp() };
649 }
650
651 /// start a measurement using the cached data
652 void start(const cache_type& _cache) { value = record(_cache); }
653
654 /// stop a measurement using the cached data
655 void stop(const cache_type& _cache)
656 {
657 using namespace tim::component::operators;
658 auto diff = (record(_cache) - value);
659 std::get<0>(diff) = std::abs(std::get<0>(diff));
660 accum += (value = diff);
661 }
662};
663
664//--------------------------------------------------------------------------------------//
665/// \struct tim::component::written_bytes
666/// \brief I/O counter for bytes written. Attempt to count the number of bytes which this
667/// process caused to be sent to the storage layer. This is done at page-dirtying time.
668struct written_bytes : public base<written_bytes, std::array<int64_t, 2>>
669{
671 using value_type = std::array<int64_t, 2>;
673 using result_type = std::array<double, 2>;
676
677 static std::string label() { return "written_bytes"; }
679 {
680 return "Number of bytes sent to the storage layer";
681 }
682
684 {
685 return result_type{ { units::megabyte,
686 static_cast<double>(units::megabyte) / units::sec } };
687 }
688
689 static std::vector<std::string> display_unit_array()
690 {
691 return std::vector<std::string>{ std::get<0>(get_display_unit()),
692 std::get<1>(get_display_unit()) };
693 }
694
695 static std::vector<std::string> label_array()
696 {
697 return std::vector<std::string>{ label(), "written_rate" };
698 }
699
701 {
702 return display_unit_type{ { "MB", "MB/sec" } };
703 }
704
705 static std::array<double, 2> unit_array() { return unit(); }
706
707 static std::vector<std::string> description_array()
708 {
709 return std::vector<std::string>{ "Number of bytes written",
710 "Rate of bytes written" };
711 }
712
713 static auto get_timestamp() { return tim::get_clock_real_now<int64_t, std::nano>(); }
714
716 {
717 return value_type{ { get_bytes_written(), get_timestamp() } };
718 }
719
720 static auto get_timing_unit()
721 {
722 static auto _value = units::sec;
723 if(settings::timing_units().length() > 0)
724 _value = std::get<1>(units::get_timing_unit(settings::timing_units()));
725 return _value;
726 }
727
728 TIMEMORY_NODISCARD std::string get_display() const
729 {
730 std::stringstream ss;
731 std::stringstream ssv;
732 std::stringstream ssr;
733 auto _prec = base_type::get_precision();
734 auto _width = base_type::get_width();
735 auto _flags = base_type::get_format_flags();
736 auto _disp = get_display_unit();
737
738 auto _val = get();
739
740 ssv.setf(_flags);
741 ssv << std::setw(_width) << std::setprecision(_prec) << std::get<0>(_val);
742 if(!std::get<0>(_disp).empty())
743 ssv << " " << std::get<0>(_disp);
744
745 ssr.setf(_flags);
746 ssr << std::setw(_width) << std::setprecision(_prec) << std::get<1>(_val);
747 if(!std::get<1>(_disp).empty())
748 ssr << " " << std::get<1>(_disp);
749
750 ss << ssv.str() << ", " << ssr.str();
751 ss << " write_bytes";
752 return ss.str();
753 }
754
755 TIMEMORY_NODISCARD result_type get() const
756 {
757 auto val = base_type::load();
758
759 double data = std::get<0>(val);
760 double delta = std::get<1>(val);
761
762 delta /= static_cast<double>(std::nano::den);
763 delta *= get_timing_unit();
764
765 double rate = 0.0;
766 if(delta != 0.0)
767 rate = data / delta;
768
769 if(laps > 0)
770 rate *= laps;
771
772 data /= std::get<0>(get_unit());
773 rate /= std::get<0>(get_unit());
774
775 if(!std::isfinite(rate))
776 rate = 0.0;
777
778 return result_type{ { data, rate } };
779 }
780
781 void start() { value = record(); }
782
783 void stop()
784 {
785 using namespace tim::component::operators;
786 auto diff = (record() - value);
787 std::get<0>(diff) = std::abs(std::get<0>(diff));
788 accum += (value = diff);
789 }
790
792 {
793 static auto _instance = this_type::unit();
794 static auto& _mem = std::get<0>(_instance);
795 static auto& _rate = std::get<1>(_instance);
796
797 if(settings::memory_units().length() > 0)
798 _mem = std::get<1>(units::get_memory_unit(settings::memory_units()));
799
800 if(settings::timing_units().length() > 0)
801 {
802 auto _timing_val =
804 _rate = _mem / (_timing_val);
805 }
806
807 static const auto factor = static_cast<double>(std::nano::den);
808 unit_type _tmp = _instance;
809 std::get<1>(_tmp) *= factor;
810
811 return _tmp;
812 }
813
815 {
816 static display_unit_type _instance = this_type::display_unit();
817 static auto& _mem = std::get<0>(_instance);
818 static auto& _rate = std::get<1>(_instance);
819
820 if(settings::memory_units().length() > 0)
821 _mem = std::get<0>(units::get_memory_unit(settings::memory_units()));
822
823 if(settings::timing_units().length() > 0)
824 {
825 auto _tval = std::get<0>(units::get_timing_unit(settings::timing_units()));
826 _rate = mpl::apply<std::string>::join('/', _mem, _tval);
827 }
828 else if(settings::memory_units().length() > 0)
829 {
830 _rate = mpl::apply<std::string>::join('/', _mem, "sec");
831 }
832
833 return _instance;
834 }
835
836 /// sample a measurement
837 void sample()
838 {
839 std::get<0>(accum) = std::get<0>(value) =
840 std::max<int64_t>(std::get<0>(value), get_bytes_written());
841 }
842
843 /// sample a measurement from cached data
844 void sample(const cache_type& _cache)
845 {
846 std::get<0>(accum) = std::get<0>(value) =
847 std::max<int64_t>(std::get<0>(value), _cache.get_bytes_written());
848 }
849
850 /// read the value from the cache
851 static value_type record(const cache_type& _cache)
852 {
853 return value_type{ { _cache.get_bytes_written(), get_timestamp() } };
854 }
855
856 /// start a measurement using the cached data
857 void start(const cache_type& _cache) { value = record(_cache); }
858
859 /// stop a measurement using the cached data
860 void stop(const cache_type& _cache)
861 {
862 using namespace tim::component::operators;
863 auto diff = (record(_cache) - value);
864 std::get<0>(diff) = std::abs(std::get<0>(diff));
865 accum += (value = diff);
866 }
867};
868//
869//--------------------------------------------------------------------------------------//
870} // namespace component
871} // namespace tim
872//
873//======================================================================================//
Declare the io component types.
type_list abs(type_list<>)
Definition: fwd.hpp:405
std::string display_type
std::tuple< std::string, int64_t > get_timing_unit(std::string _unit)
Definition: units.hpp:229
std::tuple< std::string, int64_t > get_memory_unit(std::string _unit)
Definition: units.hpp:188
Definition: kokkosp.cpp:39
memory_units
Definition: settings.cpp:1657
bool isfinite(const Tp &arg)
Definition: utility.hpp:104
timing_units
Definition: settings.cpp:1650
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
static short get_precision()
decltype(auto) load()
static short get_width()
static fmtflags get_format_flags()
I/O counter for bytes read. Attempt to count the number of bytes which this process really did cause ...
Definition: components.hpp:466
static unit_type get_unit()
Definition: components.hpp:586
static display_unit_type get_display_unit()
Definition: components.hpp:609
result_type get() const
Definition: components.hpp:550
static std::pair< double, double > unit()
Definition: components.hpp:481
void stop(const cache_type &_cache)
stop a measurement using the cached data
Definition: components.hpp:655
static std::string label()
Definition: components.hpp:474
typename trait::units< this_type >::type unit_type
Definition: components.hpp:471
static std::vector< std::string > description_array()
Definition: components.hpp:506
static std::string description()
Definition: components.hpp:475
static std::vector< std::string > display_unit_array()
Definition: components.hpp:488
void sample()
sample a measurement
Definition: components.hpp:632
typename trait::units< this_type >::display_type display_unit_type
Definition: components.hpp:472
static value_type record()
Definition: components.hpp:513
static std::vector< std::string > label_array()
Definition: components.hpp:494
void sample(const cache_type &_cache)
sample a measurement from cached data
Definition: components.hpp:639
std::string get_display() const
Definition: components.hpp:523
static auto get_timing_unit()
Definition: components.hpp:515
static display_unit_type display_unit()
Definition: components.hpp:499
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:468
void start(const cache_type &_cache)
start a measurement using the cached data
Definition: components.hpp:652
static value_type record(const cache_type &_cache)
read the value from the cache
Definition: components.hpp:646
std::pair< double, double > result_type
Definition: components.hpp:470
static std::pair< double, double > unit_array()
Definition: components.hpp:504
I/O counter for chars read. The number of bytes which this task has caused to be read from storage....
Definition: components.hpp:55
static auto get_timestamp()
Definition: components.hpp:100
static std::string description()
Definition: components.hpp:64
typename trait::units< this_type >::display_type display_unit_type
Definition: components.hpp:61
void start(const cache_type &_cache)
start a measurement using the cached data
Definition: components.hpp:241
static std::pair< double, double > unit()
Definition: components.hpp:70
std::pair< double, double > result_type
Definition: components.hpp:59
typename trait::units< this_type >::type unit_type
Definition: components.hpp:60
static std::pair< double, double > unit_array()
Definition: components.hpp:93
static std::vector< std::string > label_array()
Definition: components.hpp:83
std::string get_display() const
Definition: components.hpp:112
static value_type record()
Definition: components.hpp:102
static std::vector< std::string > description_array()
Definition: components.hpp:95
result_type get() const
Definition: components.hpp:139
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:57
static value_type record(const cache_type &_cache)
read the value from cached data
Definition: components.hpp:235
void sample(const cache_type &_cache)
sample a measurement from cached data
Definition: components.hpp:228
static display_unit_type get_display_unit()
Definition: components.hpp:198
static std::string label()
Definition: components.hpp:63
void stop(const cache_type &_cache)
stop a measurement using the cached data
Definition: components.hpp:244
static std::vector< std::string > display_unit_array()
Definition: components.hpp:77
static auto get_timing_unit()
Definition: components.hpp:104
void sample()
sample a measurement
Definition: components.hpp:221
static display_unit_type display_unit()
Definition: components.hpp:88
static unit_type get_unit()
Definition: components.hpp:175
I/O counter for bytes written. Attempt to count the number of bytes which this process caused to be s...
Definition: components.hpp:669
void start(const cache_type &_cache)
start a measurement using the cached data
Definition: components.hpp:857
void sample(const cache_type &_cache)
sample a measurement from cached data
Definition: components.hpp:844
typename trait::units< this_type >::type unit_type
Definition: components.hpp:674
static value_type record(const cache_type &_cache)
read the value from the cache
Definition: components.hpp:851
static value_type record()
Definition: components.hpp:715
std::string get_display() const
Definition: components.hpp:728
static std::vector< std::string > label_array()
Definition: components.hpp:695
result_type get() const
Definition: components.hpp:755
static display_unit_type get_display_unit()
Definition: components.hpp:814
std::array< int64_t, 2 > value_type
Definition: components.hpp:671
static unit_type get_unit()
Definition: components.hpp:791
static std::vector< std::string > display_unit_array()
Definition: components.hpp:689
std::array< double, 2 > result_type
Definition: components.hpp:673
static result_type unit()
Definition: components.hpp:683
void sample()
sample a measurement
Definition: components.hpp:837
typename trait::units< this_type >::display_type display_unit_type
Definition: components.hpp:675
void stop(const cache_type &_cache)
stop a measurement using the cached data
Definition: components.hpp:860
static std::vector< std::string > description_array()
Definition: components.hpp:707
static display_unit_type display_unit()
Definition: components.hpp:700
static std::string description()
Definition: components.hpp:678
static std::string label()
Definition: components.hpp:677
static std::array< double, 2 > unit_array()
Definition: components.hpp:705
I/O counter for chars written. The number of bytes which this task has caused, or shall cause to be w...
Definition: components.hpp:259
static std::vector< std::string > display_unit_array()
Definition: components.hpp:280
static display_unit_type get_display_unit()
Definition: components.hpp:405
void stop(const cache_type &_cache)
stop a measurement using the cached data
Definition: components.hpp:451
static result_type unit()
Definition: components.hpp:274
static std::string label()
Definition: components.hpp:267
typename trait::units< this_type >::display_type display_unit_type
Definition: components.hpp:265
static std::array< double, 2 > unit_array()
Definition: components.hpp:296
void start(const cache_type &_cache)
start a measurement using the cached data
Definition: components.hpp:448
void sample()
sample a measurement
Definition: components.hpp:428
static unit_type get_unit()
Definition: components.hpp:382
static std::vector< std::string > description_array()
Definition: components.hpp:298
std::array< double, 2 > result_type
Definition: components.hpp:263
void sample(const cache_type &_cache)
sample a measurement from cached data
Definition: components.hpp:435
static value_type record(const cache_type &_cache)
read the value from cached data
Definition: components.hpp:442
static display_unit_type display_unit()
Definition: components.hpp:291
typename trait::units< this_type >::type unit_type
Definition: components.hpp:264
std::array< int64_t, 2 > value_type
Definition: components.hpp:261
std::string get_display() const
Definition: components.hpp:319
static std::vector< std::string > label_array()
Definition: components.hpp:286
static value_type record()
Definition: components.hpp:306
result_type get() const
Definition: components.hpp:346
static std::string description()
Definition: components.hpp:268
static string_t join(SepT &&separator, Tuple &&__tup, index_sequence< Idx... >) noexcept
Definition: apply.hpp:408