C++ Operations

Namespace: tim::operation

These structs are invoked by the variadic template bundlers when performing operations on components. The constructor of the class is invoked with a reference to the component and any additional arguments either provided by the bundler or passed in by the user.

component_tuple<Foo, Bar> handle("example");

handle.start();
for(int i = 0; i < N; ++i)
{
    handle.store(i);
    // ...
}
handle.stop();

will roughly translate to:

component_tuple<Foo, Bar> handle("example");

Foo& f = std::get<0>(handle.m_data);
Bar& b = std::get<1>(handle.m_data);

// constructor
auto ... = operation::set_prefix<Foo>(f, "example");
auto ... = operation::set_prefix<Bar>(b, "example");

// handle.start()
auto ... = operation::start<Foo>(f);
auto ... = operation::start<Bar>(b);

for(int i = 0; i < N; ++i)
{
    // handle.store(i)
    auto ... = operation::store<Foo>(f, i);
    auto ... = operation::store<Bar>(b, i);
    // ...
}
// handle.stop()
auto ... = operation::stop<Foo>(f);
auto ... = operation::stop<Bar>(b);

and, after the optimization by the compiler, those temporary objects will be eliminated and only the contents of happen inside the constructor (if any) will remain. This can be verified by executing the nm utility and searching for any symbols in the binary with the name operation:

nm --demangle <EXE or LIB> | grep operation
template<typename Tp>
struct init

This operation class is used for invoking the static initializer and thread-local initializer of a component.

template<typename Tp>
struct init_storage
template<typename Tp>
struct fini_storage
template<typename Tp>
struct construct

The purpose of this operation class is construct an object with specific args.

template<typename Tp>
struct set_prefix

Call the set_prefix member function. These instantiations are always inlined because of the use of string_view. Without inlining, you will get undefined symbols in C++14 code when timemory was compiled with C++17.

tparam Tp

Component type

template<typename Tp>
struct set_scope
template<typename Tp>
struct push_node
template<typename Tp>
struct pop_node
template<typename Tp>
struct record
template<typename Tp>
struct reset
template<typename Tp>
struct measure

This operation class is used for a single measurement for a component.

template<typename Tp>
struct sample

This operation class is used for sampling.

template<typename RetType, typename LhsType, typename RhsType>
struct compose

The purpose of this operation class is operating on two components to compose a result, e.g. use system-clock and user-clock to get a cpu-clock.

template<typename T, bool DefaultValue>
struct is_running

This operation attempts to call a member function which provides whether or not the component currently within a phase measurement.

tparam T

Component type

tparam DefaultValue

The value to return if the member function is not provided

template<typename T>
struct set_started

This operation attempts to call a member function which the component provides to internally store whether or not it is currently within a phase measurement (to prevent restarts)

tparam T

Component type

template<typename Tp>
struct start
template<typename Tp>
struct priority_start
template<typename Tp>
struct standard_start
template<typename Tp>
struct delayed_start
template<typename T>
struct set_stopped

This operation attempts to call a member function which the component provides to internally store whether or not it is currently within a phase measurement (to prevent stopping when it hasn’t been started)

tparam T

Component type

template<typename Tp>
struct stop
template<typename Tp>
struct priority_stop
template<typename Tp>
struct standard_stop
template<typename Tp>
struct delayed_stop
template<typename Tp>
struct mark

This operation class is used for marking some event (usually in some external profiler)

template<typename Tp>
struct mark_begin

This operation class is used for asynchronous routines such as cuda_event and nvtx_marker which are passed cudaStream_t instances.

template<typename Tp>
struct mark_end

This operation class is used for asynchronous routines such as cuda_event and nvtx_marker which are passed cudaStream_t instances.

template<typename Tp>
struct store
template<typename Tp>
struct audit

The purpose of this operation class is for a component to provide some extra customization within a GOTCHA function. It allows a GOTCHA component to inspect the arguments and the return type of a wrapped function. To add support to a component, define void audit(std::string, context, <Args...>). The first argument is the function name (possibly mangled), the second is either type tim::audit::incoming or tim::audit::outgoing, and the remaining arguments are the corresponding types.

One such purpose may be to create a custom component that intercepts a malloc and uses the arguments to get the exact allocation size.

template<typename Tp>
struct plus

Define addition operations.

template<typename Tp>
struct minus

Define subtraction operations.

template<typename Tp>
struct multiply

This operation class is used for multiplication of a component.

template<typename Tp>
struct divide

This operation class is used for division of a component.

template<typename Tp>
struct get

The purpose of this operation class is to provide a non-template hook to get the object itself.

template<typename Tp>
struct get_data

The purpose of this operation class is to combine the output types from the “get()” member function for multiple components this is specifically used in the Python interface to provide direct access to the results.

template<typename Tp>
struct get_labeled_data
template<typename Tp>
struct tim::operation::base_printer : public tim::operation::common_utils

invoked from the base class to provide default printing behavior

Public Static Functions

static inline string_t attribute_string(const string_t &key, const string_t &item)

generate an attribute

static inline string_t replace(string_t &item, const string_t &str, const strset_t &values)

replace matching values in item with str

static inline string_t lowercase(string_t _str)

convert to lowercase

static inline string_t uppercase(string_t _str)

convert to uppercase

static inline bool contains(const string_t &str, const strset_t &items)

check if str contains any of the string items

template<typename Tp, typename ...Args>
static inline string_t join(Tp &&_delim, Args&&... _args)

shorthand for apply<string_t>::join(…)

template<typename Tp>
struct print

print routines for individual components

template<typename Tp>
struct tim::operation::print_header : public tim::operation::common_utils

Public Static Functions

static inline string_t attribute_string(const string_t &key, const string_t &item)

generate an attribute

static inline string_t replace(string_t &item, const string_t &str, const strset_t &values)

replace matching values in item with str

static inline string_t lowercase(string_t _str)

convert to lowercase

static inline string_t uppercase(string_t _str)

convert to uppercase

static inline bool contains(const string_t &str, const strset_t &items)

check if str contains any of the string items

template<typename Tp, typename ...Args>
static inline string_t join(Tp &&_delim, Args&&... _args)

shorthand for apply<string_t>::join(…)

template<typename Tp>
struct tim::operation::print_statistics : public tim::operation::common_utils

prints the statistics for a type

Public Static Functions

static inline string_t attribute_string(const string_t &key, const string_t &item)

generate an attribute

static inline string_t replace(string_t &item, const string_t &str, const strset_t &values)

replace matching values in item with str

static inline string_t lowercase(string_t _str)

convert to lowercase

static inline string_t uppercase(string_t _str)

convert to uppercase

static inline bool contains(const string_t &str, const strset_t &items)

check if str contains any of the string items

template<typename Tp, typename ...Args>
static inline string_t join(Tp &&_delim, Args&&... _args)

shorthand for apply<string_t>::join(…)

template<typename Tp>
struct print_storage

Print the storage for a component.

Subclassed by tim::operation::print_storage< Tp * >

template<typename Tp>
struct add_secondary : public tim::operation::internal::add_secondary<Tp, trait::secondary_data<Tp>::value>

component contains secondary data resembling the original data but should be another node entry in the graph. These types must provide a get_secondary() member function and that member function must return a pair-wise iterable container, e.g. std::map, of types:

  • std::string

  • value_type or Tp

tparam Tp

Component type

template<typename T>
struct add_statistics

Enabling statistics in timemory has two parts:

  1. tim::trait::record_statistics must be set to true for component

  2. tim::trait::statistics must set the data type of the statistics

    • this is usually set to the data type returned from get()

    • tuple<> is the default and will fully disable statistics unless changed

template<typename Tp>
struct serialization : public tim::operation::internal::serialization<Tp, is_enabled<Tp>::value>
template<typename T, bool Enabled = trait::echo_enabled<T>::value>
struct echo_measurement

This operation class echoes DartMeasurements for a CDash dashboard.

template<typename Tp>
struct copy

This operation class is used for copying the object generically.

template<typename Tp>
struct assemble
template<typename Tp>
struct derive
template<typename Tp>
struct cache
template<typename Tp>
struct fini

This operation class is used for invoking the static initializer and thread-local initializer of a component.

template<typename Type, bool has_data>
struct get
template<typename Type, bool has_data>
struct mpi_get
template<typename Type, bool has_data>
struct upc_get
template<typename Type, bool has_data>
struct dmp_get
template<typename Type, bool has_data>
struct print
template<typename Type, bool has_data>
struct merge
template<typename Type>
struct flamegraph
template<typename Tp>
struct generic_deleter
template<typename Tp>
struct generic_counter
template<typename Tp, typename Op, typename Tag>
struct generic_operator

This operation class is similar to pointer_operator but can handle non-pointer types.