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.
type_traits.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/** \file timemory/mpl/type_traits.hpp
26 * \headerfile timemory/mpl/type_traits.hpp "timemory/mpl/type_traits.hpp"
27 * These are the definitions of type-traits used by timemory and should be defined
28 * separately from the class so that they can be queried without including the
29 * definition of the component
30 *
31 */
32
33#pragma once
34
35#include "timemory/api.hpp"
39#include "timemory/tpls/cereal/archives.hpp"
40//
41#include <type_traits>
42
43//======================================================================================//
44//
45// Type Traits
46//
47//======================================================================================//
48
49namespace tim
50{
51template <typename T>
52struct statistics;
53
54class manager;
55
56namespace trait
57{
58//--------------------------------------------------------------------------------------//
59//
60template <typename TraitT>
61inline std::string
63{
64 constexpr bool _val = TraitT::value;
65 return (_val) ? "true" : "false";
66}
67
68//--------------------------------------------------------------------------------------//
69/// \struct tim::trait::base_has_accum
70/// \brief trait that signifies that a component has an accumulation value. In general,
71/// most components implement 'value' and 'accum' data members of 'value_type'. Where
72/// 'value' is generally used as intermediate storage between start/stop and after stop
73/// have been called, 'value' is assigned as the difference between start/stop and added
74/// to 'accum'. However, in the case where 'accum' is not a valid metric for the
75/// component, this trait can be used to save memory bc it results in the 'accum' data
76/// member to be implemented as a data-type of std::tuple<>, which only requires 1 byte of
77/// memory.
78///
79template <typename T>
80struct base_has_accum : true_type
81{};
82
83//--------------------------------------------------------------------------------------//
84/// \struct tim::trait::base_has_last
85/// \brief trait that signifies that a component has an "last" value which may be
86/// different than the "value" value. In general, most components implement
87/// 'value' and 'accum' data members of 'value_type'. Where 'value' is generally
88/// used as intermediate storage between start/stop and after stop have been called,
89/// 'value' is assigned as the difference between start/stop and added to 'accum'.
90/// However, in the case where 'value' is valid as an individual measurement, this trait
91/// can be used to store 'value' as the individual measurement and 'last' as the
92/// difference or vice-versa.
93///
94template <typename T>
95struct base_has_last : false_type
96{};
97
98//--------------------------------------------------------------------------------------//
99/// \struct tim::trait::data
100/// \brief trait to specify the value type of a component before the definition of
101/// the component
102///
103template <typename T>
104struct data
105{
106 // an empty type-list indicates the data type is not currently known
107 // but empty tuple indicates that the type is unavailable
109};
110
111//--------------------------------------------------------------------------------------//
112/// \struct tim::trait::component_apis
113/// \brief trait to specify the APIs that the component is logically a part of
114///
115template <typename T>
117{
119};
120
121template <typename T>
123
124//--------------------------------------------------------------------------------------//
125/// \struct tim::trait::supports_runtime_enabled
126/// \brief trait to specify that the type supports toggling availablity at runtime.
127/// Supporting runtime availability has a relatively miniscule overhead but disabling it
128/// can ensure that the implementation truly maps down to the same assembly as
129/// hand-implementations.
130///
131template <typename Tp>
132struct supports_runtime_enabled : true_type
133{};
134
135//--------------------------------------------------------------------------------------//
136
137template <>
138struct runtime_enabled<void>
139{
141
142 // GET specialization if component is available
143 static TIMEMORY_HOT TIMEMORY_INLINE bool get() { return get_runtime_value(); }
144
145 // SET specialization if component is available
146 static void set(bool val) { get_runtime_value() = val; }
147
148private:
149 static TIMEMORY_HOT TIMEMORY_INLINE bool& get_runtime_value()
150 {
151 static bool _instance = TIMEMORY_DEFAULT_ENABLED;
152 return _instance;
153 }
154};
155
156//--------------------------------------------------------------------------------------//
157/// \struct tim::trait::default_runtime_enabled
158/// \brief trait whose compile-time constant field `value` designates the default runtime
159/// value of \ref tim::trait::runtime_enabled. Standard setting is true.
160///
161template <typename T>
162struct default_runtime_enabled : true_type
163{};
164
165//--------------------------------------------------------------------------------------//
166/// \struct tim::trait::runtime_enabled
167/// \brief trait that signifies that an implementation is enabled at runtime. The
168/// value returned from get() is for the specific setting for the type, the
169/// global settings (type: void) and the specific settings for it's APIs
170///
171template <typename T>
173{
174private:
175 template <typename U>
176 static constexpr bool get_value()
177 {
179 }
180
181public:
183
184 /// type-list of APIs that are runtime configurable
187
188 /// GET specialization if component is available
189 template <typename U = T>
190 static TIMEMORY_INLINE bool get(
191 enable_if_t<is_available<U>::value && get_value<U>(), int> = 0)
192 {
193 return (runtime_enabled<void>::get() && get_runtime_value() &&
195 }
196
197 /// SET specialization if component is available
198 template <typename U = T>
199 static TIMEMORY_INLINE bool set(
200 bool val, enable_if_t<is_available<U>::value && get_value<U>(), int> = 0)
201 {
202 return (get_runtime_value() = val);
203 }
204
205 /// GET specialization if component is NOT available
206 template <typename U = T>
207 static TIMEMORY_INLINE bool get(
208 enable_if_t<!is_available<U>::value || !get_value<U>(), long> = 0)
209 {
211 }
212
213 /// SET specialization if component is NOT available
214 template <typename U = T>
215 static TIMEMORY_INLINE bool set(
216 bool, enable_if_t<!is_available<U>::value || !get_value<U>(), long> = 0)
217 {
219 }
220
221private:
222 static TIMEMORY_HOT bool& get_runtime_value()
223 {
224 static bool _instance =
226 return _instance;
227 }
228};
229
230//--------------------------------------------------------------------------------------//
231/// \struct tim::trait::custom_label_printing
232/// \brief trait that signifies that a component will handle printing the label(s)
233///
234template <typename T>
235struct custom_label_printing : false_type
236{};
237
238//--------------------------------------------------------------------------------------//
239/// \struct tim::trait::custom_unit_printing
240/// \brief trait that signifies that a component will handle printing the units(s)
241///
242template <typename T>
243struct custom_unit_printing : false_type
244{};
245
246//--------------------------------------------------------------------------------------//
247/// \struct tim::trait::start_priority
248/// \brief trait that designates whether there is a priority when starting the type w.r.t.
249/// other types. Lower values indicate higher priority.
250///
251template <typename T>
252struct start_priority : std::integral_constant<int, 0>
253{};
254
255//--------------------------------------------------------------------------------------//
256/// \struct tim::trait::stop_priority
257/// \brief trait that designates whether there is a priority when stopping the type w.r.t.
258/// other types. Lower values indicate higher priority.
259///
260template <typename T>
261struct stop_priority : std::integral_constant<int, 0>
262{};
263
264//--------------------------------------------------------------------------------------//
265/// \struct tim::trait::fini_priority
266/// \brief trait that designates whether there is a priority when finalizing the type
267/// w.r.t. other types. Recommended for component which hold instances of other
268/// components. Lower values indicate higher priority.
269///
270template <typename T>
271struct fini_priority : std::integral_constant<int, 0>
272{};
273
274//--------------------------------------------------------------------------------------//
275/// \struct tim::trait::is_timing_category
276/// \brief trait that designates the width and precision should follow formatting settings
277/// related to timing measurements
278///
279template <typename T>
280struct is_timing_category : false_type
281{};
282
283//--------------------------------------------------------------------------------------//
284/// \struct tim::trait::is_memory_category
285/// \brief trait that designates the width and precision should follow formatting settings
286/// related to memory measurements
287///
288template <typename T>
289struct is_memory_category : false_type
290{};
291
292//--------------------------------------------------------------------------------------//
293/// \struct tim::trait::uses_timing_units
294/// \brief trait that designates the units should follow unit settings related to timing
295/// measurements
296///
297template <typename T>
298struct uses_timing_units : false_type
299{};
300
301//--------------------------------------------------------------------------------------//
302/// \struct tim::trait::uses_memory_units
303/// \brief trait that designates the units should follow unit settings related to memory
304/// measurements
305///
306template <typename T>
307struct uses_memory_units : false_type
308{};
309
310//--------------------------------------------------------------------------------------//
311/// \struct tim::trait::uses_percent_units
312/// \brief trait that designates the units are a percentage
313///
314template <typename T>
315struct uses_percent_units : false_type
316{};
317
318//--------------------------------------------------------------------------------------//
319/// \struct tim::trait::requires_json
320/// \brief trait that designates a type should always print a JSON output
321///
322template <typename T>
323struct requires_json : false_type
324{};
325
326//--------------------------------------------------------------------------------------//
327/// \struct tim::trait::api_components
328/// \brief trait that designates components in an API (tim::api)
329///
330template <typename T, typename Tag>
332{
334};
335
336//--------------------------------------------------------------------------------------//
337/// \struct tim::trait::component_value_type
338/// \brief trait that can be used to override the evaluation of the \ref
339/// tim::trait::collects_data trait. It checks to see if \ref tim::trait::data is
340/// specialized and, if not, evaluates to:
341///
342/// \code{.cpp}
343/// typename T::value_type
344/// \endcode
345///
346/// Unless the component has been marked as not available. If the component is not
347/// available, the 'type' will always be void. When a component is available,
348/// this trait will return the value type for a component regardless of whether
349/// it base specified within the component definition or if it was declared via
350/// a type-trait. Use the \ref tim::trait::collects_data for a constexpr boolean
351/// 'value' for whether this value is a null type.
352template <typename T>
354{
356 typename data<T>::type, typename T::value_type>;
357};
358
359template <typename T>
361{
362 using type = void;
363};
364
365template <typename T>
368
369//--------------------------------------------------------------------------------------//
370/// \struct tim::trait::collects_data
371/// \brief trait that specifies or determines if a component collects any data. Default
372/// behavior is to check if the component is available and extract the type and value
373/// fields from \ref tim::trait::component_value_type. When a component is available,
374/// the 'type' of this trait will return the 'value type' for a component regardless of
375/// whether it was specified within the component definition or if it was declared via a
376/// type-trait. The constexpr 'value' boolean indicates whether the 'type' is not a null
377/// type.
378///
379template <typename T>
381{
383 static constexpr bool value = (!concepts::is_null_type<type>::value);
384};
385
386//--------------------------------------------------------------------------------------//
387/// \struct tim::trait::supports_custom_record
388/// \brief trait that designates the type supports changing the record() static function
389/// per-instance
390///
391template <typename T>
392struct supports_custom_record : false_type
393{};
394
395//--------------------------------------------------------------------------------------//
396/// \struct tim::trait::iterable_measurement
397/// \brief trait that signifies that get() returns an iterable type
398///
399template <typename T>
400struct iterable_measurement : false_type
401{};
402
403//--------------------------------------------------------------------------------------//
404/// \struct tim::trait::secondary_data
405/// \brief trait that signifies that secondary data resembling the original data
406/// exists but should be another node entry in the graph. These types
407/// must provide a get_secondary() member function and that member function
408/// must return a pair-wise iterable container, e.g. std::map, of types:
409/// - std::string
410/// - value_type
411///
412template <typename T>
413struct secondary_data : false_type
414{};
415
416//--------------------------------------------------------------------------------------//
417/// \struct tim::trait::thread_scope_only
418/// \brief trait that signifies the component only has relevant values if it is not
419/// collapsed into the master thread
420///
421template <typename T>
422struct thread_scope_only : false_type
423{};
424
425//--------------------------------------------------------------------------------------//
426/// \struct tim::trait::custom_serialization
427/// \brief trait that signifies the component will be providing it's own split load(...)
428/// and store(...) for serialization so do not provide one in the base class
429///
430template <typename T>
431struct custom_serialization : false_type
432{};
433
434//--------------------------------------------------------------------------------------//
435/// \struct tim::trait::record_statistics
436/// \brief trait that signifies the component will calculate min/max/stddev
437///
438template <typename T>
439struct record_statistics : default_record_statistics_type
440{};
441
442//--------------------------------------------------------------------------------------//
443/// \struct tim::trait::statistics
444/// \brief trait that specifies the data type of the statistics
445///
446template <typename T>
448{
449 using type = std::tuple<>;
450};
451
452//--------------------------------------------------------------------------------------//
453/// \struct tim::trait::permissive_statistics
454/// \brief trait that will suppress compilation error in
455/// `operation::add_statistics<Component>` if the data type passed is
456/// implicitly convertible to the data type in `statistics<Component>::type`
457/// but avoids converting integers to floating points and vice-versa.
458///
459template <typename T>
460struct permissive_statistics : false_type
461{};
462
463//--------------------------------------------------------------------------------------//
464/// \struct tim::trait::sampler
465/// \brief trait that signifies the component supports sampling.
466///
467template <typename T>
468struct sampler : false_type
469{};
470
471//--------------------------------------------------------------------------------------//
472/// \struct tim::trait::file_sampler
473/// \brief trait that signifies the component samples a measurement from a file. If
474/// multiple components sample from the same file, it is recommended to create a cache
475/// type which performs a single read of the file and caches the values such that when
476/// these components are bundled together, they can just read their data from the cache
477/// structure.
478///
479/// See also: \ref tim::trait::cache
480///
481template <typename T>
482struct file_sampler : false_type
483{};
484
485//--------------------------------------------------------------------------------------//
486/// \struct tim::trait::units
487/// \brief trait that specifies the units
488///
489template <typename T>
490struct units
491{
492 using type = int64_t;
494};
495
496//--------------------------------------------------------------------------------------//
497/// \struct tim::trait::echo_enabled
498/// \brief trait that configures echo_measurement usage
499///
500template <typename T>
501struct echo_enabled : true_type
502{};
503
504//--------------------------------------------------------------------------------------//
505/// \struct tim::trait::pretty_archive
506/// \brief trait that configures whether output archive uses pretty formmatting. If set
507/// to false_type then the JSON/XML/etc. will be compact (if supported)
508///
509template <typename T>
510struct pretty_archive : std::false_type
511{};
512
513/// \struct tim::trait::api_input_archive
514/// \brief trait that configures the default input archive type for an entire API
515/// specification, e.g. TIMEMORY_API (which is `struct tim::project::timemory`). The input
516/// archive format of individual components is determined from the derived \ref
517/// tim::trait::input_archive
518///
519template <typename Api>
521{
523};
524
525/// \struct tim::trait::api_output_archive
526/// \brief trait that configures the default output archive type for an entire API
527/// specification, e.g. TIMEMORY_API (which is `struct tim::project::timemory`). The
528/// output archive format of individual components is determined from the derived \ref
529/// tim::trait::output_archive
530///
531template <typename Api>
533{
535
536 static constexpr bool is_default_v = std::is_same<default_type, type_list<>>::value;
538
540 conditional_t<is_pretty_v, cereal::PrettyJSONOutputArchive,
541 cereal::MinimalJSONOutputArchive>,
543};
544
545//--------------------------------------------------------------------------------------//
546/// \struct tim::trait::input_archive
547/// \brief trait that configures output archive type
548///
549template <typename T, typename Api>
551{
553};
554
555//--------------------------------------------------------------------------------------//
556/// \struct tim::trait::output_archive
557/// \brief trait that configures output archive type
558///
559template <typename T, typename Api>
561{
563
564 using minimal_type = cereal::MinimalJSONOutputArchive;
565 using pretty_type = cereal::PrettyJSONOutputArchive;
566
567 static constexpr bool is_pretty_v = pretty_archive<T>::value ||
570
571 static constexpr bool is_json = (std::is_same<api_type, pretty_type>::value ||
572 std::is_same<api_type, minimal_type>::value);
573
575 api_type>;
576};
577
578template <>
580{
581 using type = cereal::BaseJSONOutputArchive<cereal::PrettyJsonWriter>;
582};
583
584template <typename Api>
585struct output_archive<manager, Api> : output_archive<manager, TIMEMORY_API>
586{};
587
588//--------------------------------------------------------------------------------------//
589/// \struct tim::trait::archive_extension
590/// \brief Extension for the input or output archive types. It will throw an error if
591/// used on new archive types and not specialized
592template <typename T>
594{
597 type_list<cereal::JSONInputArchive, cereal::PrettyJSONOutputArchive,
598 cereal::MinimalJSONOutputArchive>;
600 type_list<cereal::BinaryInputArchive, cereal::BinaryOutputArchive,
601 cereal::PortableBinaryInputArchive,
602 cereal::PortableBinaryOutputArchive>;
603
604 template <typename U = T>
606 {
607 return ".xml";
608 }
609
610 template <typename U = T>
612 {
613 return ".json";
614 }
615
616 template <typename U = T>
618 {
619 return ".dat";
620 }
621};
622
623//--------------------------------------------------------------------------------------//
624/// \struct tim::trait::report
625/// \brief trait that allows runtime configuration of reporting certain types of values.
626/// Only applies to text output. This will allows modifying the value set by the
627/// specific "report_*" type-trait.
628///
629template <typename T>
630struct report
631{
632#define TIMEMORY_REPORT_GET_SET(FNAME, FIELD) \
633 static bool FNAME() { return get(FIELD); } \
634 static void FNAME(bool val) { set(FIELD, val); }
635
636#define TIMEMORY_REPORT_ENV_QUERY(FIELD) \
637 get_env<bool>("TIMEMORY_PRINT_" #FIELD, get_runtime_value().at(FIELD))
638
639 enum field : short
640 {
641 COUNT = 0,
654 };
655
656 using value_type = std::array<bool, FIELDS_END>;
657
658 static bool get(short idx)
659 {
660 return get_runtime_value().at(idx % FIELDS_END) &&
661 get_runtime_env().at(idx % FIELDS_END);
662 }
663
664 static void set(short idx, bool val)
665 {
666 get_runtime_value().at(idx % FIELDS_END) = val;
667 }
668
681
682private:
683 static value_type& get_runtime_value()
684 {
685 static value_type _instance{
692 };
693 return _instance;
694 }
695
696 static value_type get_runtime_env()
697 {
698 return value_type{
705 };
706 }
707
708#undef TIMEMORY_REPORT_ENV_QUERY
709#undef TIMEMORY_REPORT_GET_SET
710};
711
712//--------------------------------------------------------------------------------------//
713/// \struct tim::trait::report_count
714/// \brief trait that configures type to not report the number of lap count (useful if
715/// meaningless). Only applies to text output.
716///
717template <typename T>
718struct report_count : true_type
719{};
720
721//--------------------------------------------------------------------------------------//
722/// \struct tim::trait::report_count
723/// \brief trait that configures type to not report the number of lap count (useful if
724/// meaningless). Only applies to text output.
725///
726template <typename T>
727struct report_depth : true_type
728{};
729
730//--------------------------------------------------------------------------------------//
731/// \struct tim::trait::report_metric_name
732/// \brief trait that configures type to not report the "METRIC" column, useful if
733/// redundant). Only applies to text output.
734///
735template <typename T>
736struct report_metric_name : true_type
737{};
738
739//--------------------------------------------------------------------------------------//
740/// \struct tim::trait::report_units
741/// \brief trait that configures type to not report the "UNITS" column (useful if always
742/// empty). Only applies to text output.
743///
744template <typename T>
745struct report_units : true_type
746{};
747
748//--------------------------------------------------------------------------------------//
749/// \struct tim::trait::report_sum
750/// \brief trait that configures type to not report the accumulated value (useful if
751/// meaningless). Only applies to text output.
752///
753template <typename T>
754struct report_sum : true_type
755{};
756
757//--------------------------------------------------------------------------------------//
758/// \struct tim::trait::report_mean
759/// \brief trait that configures type to not report the mean value (useful if
760/// meaningless). Only applies to text output.
761///
762template <typename T>
763struct report_mean : true_type
764{};
765
766//--------------------------------------------------------------------------------------//
767/// \struct tim::trait::report_statistics
768/// \brief trait that configures type to not report the "UNITS" column (useful if always
769/// empty). Only applies to text output and does NOT affect whether statistics are
770/// accumulated. For disabling statistics completely, see \ref
771/// tim::trait::record_statistics and \ref tim::policy::record_statistics.
772///
773template <typename T>
774struct report_statistics : true_type
775{};
776
777//--------------------------------------------------------------------------------------//
778/// \struct tim::trait::report_self
779/// \brief trait that configures type to not report the % self field (useful if
780/// meaningless). Only applies to text output.
781///
782template <typename T>
783struct report_self : true_type
784{};
785
786//--------------------------------------------------------------------------------------//
787/// \struct tim::trait::supports_flamegraph
788/// \brief trait that designates a type supports flamegraph output
789///
790template <typename T>
791struct supports_flamegraph : false_type
792{};
793
794//--------------------------------------------------------------------------------------//
795/// \struct tim::trait::derivation_types
796/// \brief trait that designates the type supports calling assemble and derive member
797/// functions with these types. Specializations MUST be structured as a
798/// tim::type_list<...> of tim::type_list<...> where each inner type_list entry is
799/// the list of component types required to perform a derivation.
800/// \code{.cpp}
801/// template <>
802/// struct derivation_types<cpu_util>
803/// {
804/// // can derive its data when present alongside wall_clock + cpu_clock and/or
805/// // wall_clock + user_clock + system_clock
806/// using type = type_list<
807/// type_list<wall_clock, cpu_clock>,
808/// type_list<wall_clock, user_clock, system_clock>
809/// >;
810/// };
811/// \endcode
812///
813template <typename T>
814struct derivation_types : false_type
815{
816 static constexpr size_t size = 0;
817 using type = std::tuple<type_list<>>;
818};
819
820//--------------------------------------------------------------------------------------//
821/// \struct tim::trait::python_args
822/// \brief trait that designates the type supports these arguments from python.
823/// Specializations MUST be structured as either one `tim::type_list<...>` or
824/// a `tim::type_list<...>` of `tim::type_list<...>`.
825/// The first argument is a \ref TIMEMORY_OPERATION enumerated type and for each
826/// inner \ref tim::type_list, a python member function for the stand-alone component
827/// will be generated with those arguments. E.g. to create a custom store member function
828/// accepting integer:
829/// \code{.py}
830/// foo = timemory.component.CaliperLoopMarker("example")
831/// foo.start()
832/// for i in range(10):
833/// foo.store(i) # store member function accepting integer
834/// # ...
835/// foo.stop()
836/// \endcode
837/// The type-trait specification would look like this:
838/// \code{.cpp}
839/// template <>
840/// struct python_args<TIMEMORY_STORE, component::caliper_loop_marker>
841/// {
842/// using type = type_list<size_t>;
843/// };
844/// \endcode
845///
846template <int OpT, typename T>
848{
850};
851
852//--------------------------------------------------------------------------------------//
853
854template <int OpT, typename T>
856
857//--------------------------------------------------------------------------------------//
858/// \struct tim::trait::cache
859/// \brief trait that specifies the intermediate data type that will hold the relevant
860/// data required by the component. This is useful for when multiple components
861/// read different parts of the same file (e.g. /proc/<PID>/io) or an API
862/// reports data in a larger data structure than the scope of the component (e.g. rusage)
863/// but multiple components require access to this data structure
864///
865template <typename T>
866struct cache
867{
869};
870
871//--------------------------------------------------------------------------------------//
872//
873// determines if output is generated
874//
875//--------------------------------------------------------------------------------------//
876/// \struct tim::trait::generates_output
877/// \brief trait used to evaluate whether a component value type produces a useable value
878template <typename T, typename V>
880{
881 using type = V;
882 static constexpr bool value = (!concepts::is_null_type<type>::value);
883};
884
885template <typename T>
886struct generates_output<T, void>
887{
888 using type = void;
889 static constexpr bool value = false;
890};
891
892template <typename T>
894{
896 static constexpr bool value = false;
897};
898
899template <typename T>
901{
902 // this is default evaluation from trait::data<T>::type
903 using type = typename T::value_type;
904 static constexpr bool value = (!concepts::is_null_type<type>::value);
905};
906
907template <typename T>
908struct generates_output<T, data<T>> : generates_output<T, typename data<T>::type>
909{};
910
911//--------------------------------------------------------------------------------------//
912/// \struct tim::trait::uses_storage
913/// \brief trait that designates that a component will instantiate tim::storage
914///
915template <typename T>
917{};
918
919//--------------------------------------------------------------------------------------//
920/// \struct tim::trait::tree_storage
921/// \brief trait that configures type to always use hierarchical call-stack storage
922///
923template <typename T>
924struct tree_storage : false_type
925{};
926
927//--------------------------------------------------------------------------------------//
928/// \struct tim::trait::flat_storage
929/// \brief trait that configures type to always use flat call-stack storage
930///
931template <typename T>
932struct flat_storage : false_type
933{};
934
935//--------------------------------------------------------------------------------------//
936/// \struct tim::trait::timeline_storage
937/// \brief trait that configures type to always use timeline call-stack storage
938///
939template <typename T>
940struct timeline_storage : false_type
941{};
942
943//--------------------------------------------------------------------------------------//
944//
945// determines if storage should be implemented
946//
947//--------------------------------------------------------------------------------------//
948/// \struct tim::trait::uses_value_storage
949/// \brief This trait is used to determine whether the (expensive) instantiation of the
950/// storage class happens
951template <typename T, typename V, typename A>
953{
954 using value_type = V;
955 static constexpr bool avail_v = (A::value && trait::is_available<T>::value);
957 static constexpr bool value = (avail_v && output_v);
958};
959
960// this specialization is from trait::data<T> when using storage
961template <typename T>
962struct uses_value_storage<T, type_list<>, true_type>
963{
964 using value_type = typename T::value_type;
966};
967
968// this specialization is from trait::data<T> when not using storage
969template <typename T>
970struct uses_value_storage<T, type_list<>, false_type>
971{
972 using value_type = void;
973 static constexpr bool value = false;
974};
975
976template <typename T, typename A>
977struct uses_value_storage<T, void, A>
978{
979 using value_type = void;
980 static constexpr bool value = false;
981};
982
983template <typename T, typename A>
985{
987 static constexpr bool value = false;
988};
989
990// this specialization is from trait::data<T>
991template <typename T, typename A>
993: uses_value_storage<T, type_list<>, conditional_t<A::value, true_type, false_type>>
994{};
995
996/// \struct tim::trait::perfetto_category
997/// \brief Provides the static category for perfetto traces
998template <typename ApiT>
1000{
1001 static constexpr auto value = "timemory";
1002};
1003
1004//--------------------------------------------------------------------------------------//
1005/// \struct tim::trait::is_component
1006/// \brief trait that designates the type is a timemory component
1007/// \deprecated{ This has been migrated to `tim::concepts` }
1008///
1009template <typename T>
1010struct is_component : false_type
1011{};
1012
1013//--------------------------------------------------------------------------------------//
1014/// \struct tim::trait::is_gotcha
1015/// \brief trait that designates the type is a gotcha
1016/// \deprecated{ This has been migrated to `tim::concepts` }
1017///
1018template <typename T>
1019struct is_gotcha : false_type
1020{};
1021
1022//--------------------------------------------------------------------------------------//
1023/// \struct tim::trait::is_user_bundle
1024/// \brief trait that designates the type is a user-bundle
1025/// \deprecated{ This has been migrated to `tim::concepts` }
1026///
1027template <typename T>
1028struct is_user_bundle : false_type
1029{};
1030
1031//--------------------------------------------------------------------------------------//
1032/// \struct tim::trait::record_max
1033/// \brief trait that signifies that updating w.r.t. another instance should
1034/// be a max of the two instances
1035/// \deprecated This is no longer used. Overload the operators for +=, -=, etc. to obtain
1036/// previous functionality.
1037//
1038template <typename T>
1039struct record_max : false_type
1040{};
1041
1042//--------------------------------------------------------------------------------------//
1043/// \struct tim::trait::array_serialization
1044/// \brief trait that signifies that data is an array type
1045/// \deprecated { This trait is no longer used as array types are determined by other
1046/// means }
1047///
1048template <typename T>
1049struct array_serialization : false_type
1050{};
1051
1052//--------------------------------------------------------------------------------------//
1053/// \struct tim::trait::requires_prefix
1054/// \brief trait that signifies that a component requires the prefix to be set right after
1055/// construction. Types with this trait must contain a member string variable named
1056/// prefix
1057/// \deprecated { This trait is no longer used as this property is determined by other
1058/// means }
1059///
1060template <typename T>
1061struct requires_prefix : false_type
1062{};
1063
1064//--------------------------------------------------------------------------------------//
1065/// \struct tim::trait::supports_args
1066/// \brief trait that designates the type supports calling a function with a certain
1067/// set of argument types (passed via a tuple).
1068/// \deprecated This is legacy code and support for calling a function with given
1069/// arguments is automatically determined.
1070///
1071template <typename T, typename Tuple>
1072struct supports_args : false_type
1073{};
1074
1075//--------------------------------------------------------------------------------------//
1076} // namespace trait
1077} // namespace tim
1078
1079//======================================================================================//
1080//
1081// Specifications
1082//
1083//======================================================================================//
1084
1085#if !defined(TIMEMORY_DEFINE_CONCRETE_TRAIT)
1086# define TIMEMORY_DEFINE_CONCRETE_TRAIT(TRAIT, COMPONENT, VALUE) \
1087 namespace tim \
1088 { \
1089 namespace trait \
1090 { \
1091 template <> \
1092 struct TRAIT<COMPONENT> : VALUE \
1093 {}; \
1094 } \
1095 }
1096#endif
1097
1098//--------------------------------------------------------------------------------------//
1099
1100#if !defined(TIMEMORY_DEFINE_TEMPLATE_TRAIT)
1101# define TIMEMORY_DEFINE_TEMPLATE_TRAIT(TRAIT, COMPONENT, VALUE, TYPE) \
1102 namespace tim \
1103 { \
1104 namespace trait \
1105 { \
1106 template <TYPE T> \
1107 struct TRAIT<COMPONENT<T>> : VALUE \
1108 {}; \
1109 } \
1110 }
1111#endif
1112
1113//--------------------------------------------------------------------------------------//
1114
1115#if !defined(TIMEMORY_DEFINE_VARIADIC_TRAIT)
1116# define TIMEMORY_DEFINE_VARIADIC_TRAIT(TRAIT, COMPONENT, VALUE, TYPE) \
1117 namespace tim \
1118 { \
1119 namespace trait \
1120 { \
1121 template <TYPE... T> \
1122 struct TRAIT<COMPONENT<T...>> : VALUE \
1123 {}; \
1124 } \
1125 }
1126#endif
1127
1128//--------------------------------------------------------------------------------------//
#define TIMEMORY_INPUT_ARCHIVE
Definition: api.hpp:217
#define TIMEMORY_DEFAULT_ENABLED
Definition: api.hpp:201
#define TIMEMORY_OUTPUT_ARCHIVE
Definition: api.hpp:221
return false
Definition: definition.hpp:326
typename get_true_types< Predicate, Sequence... >::type get_true_types_t
Definition: available.hpp:276
typename component_value_type< T, is_available< T >::value >::type component_value_type_t
std::string display_type
std::string as_string()
Definition: type_traits.hpp:62
conditional_t<!std::is_same< type_list<>, typename data< T >::type >::value, typename data< T >::type, typename T::value_type > type
TIMEMORY_INPUT_ARCHIVE type
typename python_args< OpT, T >::type python_args_t
typename api_input_archive< Api >::type type
typename component_apis< T >::type component_apis_t
trait to specify the value type of a component before the definition of the component
trait that specifies the units
trait to specify the APIs that the component is logically a part of
trait that specifies the data type of the statistics
trait that configures output archive type
trait that specifies the intermediate data type that will hold the relevant data required by the comp...
trait that can be used to override the evaluation of the tim::trait::collects_data trait....
Definition: types.hpp:120
trait that configures the default input archive type for an entire API specification,...
trait that designates the type supports these arguments from python. Specializations MUST be structur...
trait that designates components in an API (tim::api)
Definition: kokkosp.cpp:39
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
Definition: types.hpp:190
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
typename std::conditional< B, Lhs, Rhs >::type conditional_t
Definition: types.hpp:197
lightweight tuple-alternative for meta-programming logic
Definition: types.hpp:233
concept that specifies that a type is not a useful type
Definition: concepts.hpp:159
this is a placeholder type for optional type-traits. It is used as the default type for the type-trai...
Definition: types.hpp:225
trait that configures the default output archive type for an entire API specification,...
TIMEMORY_OUTPUT_ARCHIVE default_type
static constexpr bool is_pretty_v
static constexpr bool is_default_v
conditional_t< is_default_v, conditional_t< is_pretty_v, cereal::PrettyJSONOutputArchive, cereal::MinimalJSONOutputArchive >, default_type > type
generic functions for setting/accessing static properties on types
Definition: types.hpp:80
Extension for the input or output archive types. It will throw an error if used on new archive types ...
enable_if_t< is_one_of< U, binary_types >::value, std::string > operator()()
enable_if_t< is_one_of< U, json_types >::value, std::string > operator()()
enable_if_t< is_one_of< U, xml_types >::value, std::string > operator()()
trait that signifies that data is an array type
trait that signifies that a component has an accumulation value. In general, most components implemen...
Definition: type_traits.hpp:81
trait that signifies that a component has an "last" value which may be different than the "value" val...
Definition: type_traits.hpp:96
trait that specifies or determines if a component collects any data. Default behavior is to check if ...
static constexpr bool value
component_value_type_t< T > type
trait that signifies that a component will handle printing the label(s)
trait that signifies the component will be providing it's own split load(...) and store(....
trait that signifies that a component will handle printing the units(s)
trait whose compile-time constant field value designates the default runtime value of tim::trait::run...
trait that designates the type supports calling assemble and derive member functions with these types...
std::tuple< type_list<> > type
static constexpr size_t size
trait that configures echo_measurement usage
trait that signifies the component samples a measurement from a file. If multiple components sample f...
trait that designates whether there is a priority when finalizing the type w.r.t. other types....
trait that configures type to always use flat call-stack storage
trait used to evaluate whether a component value type produces a useable value
static constexpr bool value
trait that signifies that an implementation for the component is available. When this is set to false...
Definition: types.hpp:355
trait that designates the type is a timemory component
trait that designates the type is a gotcha
trait that designates the width and precision should follow formatting settings related to memory mea...
trait that designates the width and precision should follow formatting settings related to timing mea...
trait that designates the type is a user-bundle
trait that signifies that get() returns an iterable type
cereal::BaseJSONOutputArchive< cereal::PrettyJsonWriter > type
trait that configures output archive type
static constexpr bool is_pretty_v
static constexpr bool is_json
cereal::MinimalJSONOutputArchive minimal_type
cereal::PrettyJSONOutputArchive pretty_type
conditional_t< is_json, conditional_t< is_pretty_v, pretty_type, api_type >, api_type > type
typename api_output_archive< Api >::type api_type
Provides the static category for perfetto traces.
static constexpr auto value
trait that will suppress compilation error in operation::add_statistics<Component> if the data type p...
trait that configures whether output archive uses pretty formmatting. If set to false_type then the J...
trait that signifies that updating w.r.t. another instance should be a max of the two instances
trait that signifies the component will calculate min/max/stddev
trait that configures type to not report the number of lap count (useful if meaningless)....
trait that configures type to not report the mean value (useful if meaningless). Only applies to text...
trait that configures type to not report the "METRIC" column, useful if redundant)....
trait that configures type to not report the % self field (useful if meaningless)....
trait that configures type to not report the "UNITS" column (useful if always empty)....
trait that configures type to not report the accumulated value (useful if meaningless)....
trait that configures type to not report the "UNITS" column (useful if always empty)....
trait that allows runtime configuration of reporting certain types of values. Only applies to text ou...
static bool max()
std::array< bool, FIELDS_END > value_type
static bool sum()
static bool stddev()
static bool get(short idx)
static bool variance()
static bool stats()
static bool metric()
static bool count()
static bool mean()
static bool min()
static bool self()
static void set(short idx, bool val)
static bool depth()
trait that designates a type should always print a JSON output
trait that signifies that a component requires the prefix to be set right after construction....
trait that signifies that an implementation is enabled at runtime. The value returned from get() is f...
static bool get(enable_if_t< is_available< U >::value &&get_value< U >(), int >=0)
GET specialization if component is available.
mpl::get_true_types_t< concepts::is_runtime_configurable, component_apis_t< T > > api_type_list
type-list of APIs that are runtime configurable
static bool set(bool val, enable_if_t< is_available< U >::value &&get_value< U >(), int >=0)
SET specialization if component is available.
static constexpr bool value
static bool get(enable_if_t<!is_available< U >::value||!get_value< U >(), long >=0)
GET specialization if component is NOT available.
static bool set(bool, enable_if_t<!is_available< U >::value||!get_value< U >(), long >=0)
SET specialization if component is NOT available.
trait that signifies the component supports sampling.
trait that signifies that secondary data resembling the original data exists but should be another no...
trait that designates whether there is a priority when starting the type w.r.t. other types....
trait that designates whether there is a priority when stopping the type w.r.t. other types....
trait that designates the type supports calling a function with a certain set of argument types (pass...
trait that designates the type supports changing the record() static function per-instance
trait that designates a type supports flamegraph output
trait to specify that the type supports toggling availablity at runtime. Supporting runtime availabil...
trait that signifies the component only has relevant values if it is not collapsed into the master th...
trait that configures type to always use timeline call-stack storage
trait that configures type to always use hierarchical call-stack storage
trait that designates the units should follow unit settings related to memory measurements
trait that designates the units are a percentage
trait that designates that a component will instantiate tim::storage
trait that designates the units should follow unit settings related to timing measurements
This trait is used to determine whether the (expensive) instantiation of the storage class happens.
static constexpr bool avail_v
static constexpr bool output_v
static constexpr bool value
#define TIMEMORY_REPORT_GET_SET(FNAME, FIELD)
#define TIMEMORY_REPORT_ENV_QUERY(FIELD)