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.
library.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "timemory/compat/macros.h"
#include "timemory/enum.h"
+ Include dependency graph for library.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* timemory_create_func_t) (const char *, uint64_t *, int, int *)
 
typedef void(* timemory_delete_func_t) (uint64_t)
 function pointer type for timemory_delete_function More...
 

Functions

uint64_t timemory_get_unique_id (void)
 Returns a unique integer for a thread. More...
 
void timemory_create_record (const char *name, uint64_t *id, int n, int *ct)
 
void timemory_delete_record (uint64_t nid)
 Deletes the record created by timemory_create_record. More...
 
bool timemory_library_is_initialized (void)
 Returns whether the library is initialized or not. More...
 
void timemory_named_init_library (char *name)
 
void timemory_init_library (int argc, char **argv)
 Initializes timemory. Not strictly necessary but highly recommended. More...
 
void timemory_finalize_library (void)
 Finalizes timemory. Output will be generated. Any attempt to store data within timemory storage is undefined after this point and will likely cause errors. More...
 
void timemory_pause (void)
 Turn off timemory collection. More...
 
void timemory_resume (void)
 Turn on timemory collection. More...
 
void timemory_set_default (const char *components)
 Pass in a default set of components to use. Will be overridden by TIMEMORY_COMPONENTS environment variable. More...
 
void timemory_set_environ (const char *evar, const char *eval, int ovr, int up)
 
void timemory_add_components (const char *components)
 Add some components to the current set of components being collected Any components which are currently being collected are ignored. More...
 
void timemory_remove_components (const char *components)
 Remove some components to the current set of components being collected. Any components which are not currently being collected are ignored. More...
 
void timemory_push_components (const char *components)
 Replace the current set of components with a new set of components. More...
 
void timemory_push_components_enum (int args,...)
 Replace the current set of components with a new set of components with the set of enumerations provided to the function. First argument should be the number of new components. More...
 
void timemory_pop_components (void)
 Inverse of the last timemory_push_components or timemory_push_components_enum call. Popping all components will restore to set the configured as the default. More...
 
void timemory_begin_record (const char *name, uint64_t *id)
 
void timemory_begin_record_enum (const char *name, uint64_t *,...)
 Similar to timemory_begin_record but accepts a specific enumerated set of components, which is terminated by TIMEMORY_COMPONENTS_END. More...
 
void timemory_begin_record_types (const char *name, uint64_t *, const char *)
 Similar to timemory_begin_record but accepts a specific set of components as a string. More...
 
uint64_t timemory_get_begin_record (const char *name)
 Variant to timemory_begin_record which returns a unique integer. More...
 
uint64_t timemory_get_begin_record_enum (const char *name,...)
 Variant to timemory_begin_record_enum which returns a unique integer. More...
 
uint64_t timemory_get_begin_record_types (const char *name, const char *ctypes)
 Variant to timemory_begin_record_types which returns a unique integer. More...
 
void timemory_end_record (uint64_t id)
 
void timemory_push_region (const char *name)
 
void timemory_pop_region (const char *name)
 
void c_timemory_init (int argc, char **argv, timemory_settings)
 
void c_timemory_finalize (void)
 
int c_timemory_enabled (void)
 
void * c_timemory_create_auto_timer (const char *)
 
void c_timemory_delete_auto_timer (void *)
 
void * c_timemory_create_auto_tuple (const char *,...)
 
void c_timemory_delete_auto_tuple (void *)
 
const char * c_timemory_blank_label (const char *)
 
const char * c_timemory_basic_label (const char *, const char *)
 
const char * c_timemory_label (const char *, const char *, int, const char *)
 
int cxx_timemory_enabled (void)
 
void cxx_timemory_init (int, char **, timemory_settings)
 
void * cxx_timemory_create_auto_timer (const char *)
 
void * cxx_timemory_create_auto_tuple (const char *, int, const int *)
 
void * cxx_timemory_delete_auto_timer (void *)
 
void * cxx_timemory_delete_auto_tuple (void *)
 
const char * cxx_timemory_label (int, int, const char *, const char *, const char *)
 
bool timemory_trace_is_initialized (void)
 
void timemory_reset_throttle (const char *name)
 
bool timemory_is_throttled (const char *name)
 
void timemory_add_hash_id (uint64_t id, const char *name)
 
void timemory_add_hash_ids (uint64_t nentries, uint64_t *ids, const char **names)
 
void timemory_push_trace_hash (uint64_t id)
 
void timemory_pop_trace_hash (uint64_t id)
 
void timemory_push_trace (const char *name)
 
void timemory_pop_trace (const char *name)
 
void timemory_trace_init (const char *, bool, const char *)
 
void timemory_trace_finalize (void)
 
void timemory_trace_set_env (const char *, const char *)
 

Variables

timemory_create_func_t timemory_create_function
 The function pointer to set to customize which components are used by library interface. More...
 
timemory_delete_func_t timemory_delete_function
 The function pointer to set which deletes an entry created by timemory_create_function. More...
 

Typedef Documentation

◆ timemory_create_func_t

typedef void(* timemory_create_func_t) (const char *, uint64_t *, int, int *)

Definition at line 334 of file library.h.

◆ timemory_delete_func_t

void(* timemory_delete_func_t)(uint64_t)

function pointer type for timemory_delete_function

Definition at line 338 of file library.h.

Function Documentation

◆ c_timemory_basic_label()

const char * c_timemory_basic_label ( const char *  _func,
const char *  _extra 
)

Definition at line 138 of file timemory_c.c.

139 {
140 return cxx_timemory_label(1, 0, _func, "", _extra);
141 }
const char * cxx_timemory_label(int, int, const char *, const char *, const char *)

References cxx_timemory_label().

◆ c_timemory_blank_label()

const char * c_timemory_blank_label ( const char *  _extra)

Definition at line 131 of file timemory_c.c.

132 {
133 return cxx_timemory_label(0, 0, "", "", _extra);
134 }

References cxx_timemory_label().

◆ c_timemory_create_auto_timer()

void * c_timemory_create_auto_timer ( const char *  tag)

Definition at line 73 of file timemory_c.c.

74 {
75 void* _ret = NULL;
78 return _ret;
79 }
int cxx_timemory_enabled(void)
void * cxx_timemory_create_auto_timer(const char *)
const hash_alias_ptr_t hash_value_t std::string *& _ret
Definition: definition.hpp:300

References cxx_timemory_create_auto_timer(), and cxx_timemory_enabled().

◆ c_timemory_create_auto_tuple()

void * c_timemory_create_auto_tuple ( const char *  tag,
  ... 
)

Definition at line 83 of file timemory_c.c.

84 {
86 return NULL;
87
88 const int max_size = (int) TIMEMORY_COMPONENTS_END;
89 int num_components = 0;
90 int* components = (int*) malloc(max_size * sizeof(int));
91 if(!components)
92 return NULL;
93 va_list args;
94 va_start(args, tag);
95 for(int i = 0; i < max_size; ++i)
96 {
97 int comp = va_arg(args, int);
98 if(comp >= TIMEMORY_COMPONENTS_END)
99 break;
100 ++num_components;
101 components[i] = comp;
102 }
103 va_end(args);
104
105 void* ptr = NULL;
106 if(num_components > 0)
107 ptr = cxx_timemory_create_auto_tuple(tag, num_components, components);
108 free(components);
109
110 return ptr;
111 }
void * cxx_timemory_create_auto_tuple(const char *, int, const int *)
#define TIMEMORY_COMPONENTS_END
Definition: enum.h:155
components
Definition: settings.cpp:1700

References tim::components, cxx_timemory_create_auto_tuple(), cxx_timemory_enabled(), and TIMEMORY_COMPONENTS_END.

◆ c_timemory_delete_auto_timer()

void c_timemory_delete_auto_timer ( void *  ctimer)

Definition at line 115 of file timemory_c.c.

116 {
117 ctimer = cxx_timemory_delete_auto_timer(ctimer);
118 assert(ctimer == NULL);
119 }
void * cxx_timemory_delete_auto_timer(void *)

References cxx_timemory_delete_auto_timer().

◆ c_timemory_delete_auto_tuple()

void c_timemory_delete_auto_tuple ( void *  ctuple)

Definition at line 123 of file timemory_c.c.

124 {
125 ctuple = cxx_timemory_delete_auto_tuple(ctuple);
126 assert(ctuple == NULL);
127 }
void * cxx_timemory_delete_auto_tuple(void *)

References cxx_timemory_delete_auto_tuple().

◆ c_timemory_enabled()

int c_timemory_enabled ( void  )

Definition at line 69 of file timemory_c.c.

69{ return cxx_timemory_enabled(); }

References cxx_timemory_enabled().

◆ c_timemory_finalize()

void c_timemory_finalize ( void  )

Definition at line 65 of file timemory_c.c.

void timemory_finalize_library(void)
Finalizes timemory. Output will be generated. Any attempt to store data within timemory storage is un...
Definition: library.cpp:253

References timemory_finalize_library().

◆ c_timemory_init()

void c_timemory_init ( int  argc,
char **  argv,
timemory_settings  _settings 
)

Definition at line 57 of file timemory_c.c.

58 {
61 }
void cxx_timemory_init(int, char **, timemory_settings)
void timemory_init_library(int argc, char **argv)
Initializes timemory. Not strictly necessary but highly recommended.
Definition: library.cpp:212
char ** argv
Definition: config.cpp:55
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255

References tim::_settings, tim::argv, cxx_timemory_init(), and timemory_init_library().

◆ c_timemory_label()

const char * c_timemory_label ( const char *  _func,
const char *  _file,
int  _line,
const char *  _extra 
)

Definition at line 145 of file timemory_c.c.

147 {
148 return cxx_timemory_label(2, _line, _func, _file, _extra);
149 }
const auto & _file
Definition: definition.hpp:72

References tim::plotting::_file, and cxx_timemory_label().

◆ cxx_timemory_create_auto_timer()

void * cxx_timemory_create_auto_timer ( const char *  )

◆ cxx_timemory_create_auto_tuple()

void * cxx_timemory_create_auto_tuple ( const char *  ,
int  ,
const int *   
)

◆ cxx_timemory_delete_auto_timer()

void * cxx_timemory_delete_auto_timer ( void *  )

◆ cxx_timemory_delete_auto_tuple()

void * cxx_timemory_delete_auto_tuple ( void *  )

◆ cxx_timemory_enabled()

int cxx_timemory_enabled ( void  )

◆ cxx_timemory_init()

void cxx_timemory_init ( int  ,
char **  ,
timemory_settings   
)

Referenced by c_timemory_init().

◆ cxx_timemory_label()

const char * cxx_timemory_label ( int  ,
int  ,
const char *  ,
const char *  ,
const char *   
)

◆ timemory_add_components()

void timemory_add_components ( const char *  _component_string)

Add some components to the current set of components being collected Any components which are currently being collected are ignored.

timemory_add_components("peak_rss, priority_context_switch");
void timemory_add_components(const char *_component_string)
Add some components to the current set of components being collected Any components which are current...
Definition: library.cpp:348

Definition at line 348 of file library.cpp.

349 {
351 auto& _stack = get_current_components();
352 for(auto itr : tim::enumerate_components(_component_string))
353 _stack.push_back(itr);
354 }
component_enum_t & get_current_components()
Definition: library.cpp:113
A lightweight synchronization object for preventing recursion. The first template parameter should ha...
Definition: trace.hpp:135
std::vector< TIMEMORY_COMPONENT > enumerate_components(const Container< StringT, ExtraArgs... > &component_names)
description: use this function to generate an array of enumerations from a list of string that can be...
Definition: enumerate.hpp:62

References tim::enumerate_components(), and get_current_components().

◆ timemory_add_hash_id()

void timemory_add_hash_id ( uint64_t  id,
const char *  name 
)

Definition at line 392 of file trace.cpp.

393 {
395 if(!lk)
396 {
398 fprintf(stderr,
399 "[timemory-trace]> timemory_add_hash_id failed: locked...\n");
400 return;
401 }
403 fprintf(stderr, "[timemory-trace]> adding '%s' with hash %lu...\n", name,
404 (unsigned long) id);
405 auto _id = tim::add_hash_id(name);
406 if(_id != id)
407 tim::add_hash_id(_id, id);
408
409 // master thread adds the ids
410 if(tim::threading::get_id() == 0)
411 {
412 master_hash_ids[id] = name;
413 if(_id != id)
414 master_hash_ids[_id] = name;
415 }
416 }
hash_value_t add_hash_id(hash_map_ptr_t &_hash_map, string_view_cref_t _prefix)
add an string to the given hash-map (if it doesn't already exist) and return the hash
Definition: types.hpp:190

References tim::debug.

Referenced by timemory_add_hash_ids().

◆ timemory_add_hash_ids()

void timemory_add_hash_ids ( uint64_t  nentries,
uint64_t *  ids,
const char **  names 
)

Definition at line 420 of file trace.cpp.

421 {
423 fprintf(stderr, "[timemory-trace]> adding %lu hash ids...\n",
424 (unsigned long) nentries);
425 for(uint64_t i = 0; i < nentries; ++i)
426 timemory_add_hash_id(ids[i], names[i]);
427 }
void timemory_add_hash_id(uint64_t id, const char *name)
Definition: trace.cpp:392

References tim::debug, and timemory_add_hash_id().

◆ timemory_begin_record()

void timemory_begin_record ( const char *  name,
uint64_t *  id 
)
Parameters
[in]nameLabel for the record
[in,out]ididentifier passed back to timemory_end_record
uint64_t idx = 0;
timemory_begin_record("foo", &idx);
// ...
void timemory_end_record(uint64_t id)
Definition: library.cpp:557
void timemory_begin_record(const char *name, uint64_t *id)
Definition: library.cpp:409

Definition at line 409 of file library.cpp.

410 {
412 if(!lk || tim::settings::enabled() == false)
413 {
415 return;
416 }
417 auto& comp = get_current_components();
418 timemory_create_record(name, id, comp.size(), (int*) (comp.data()));
419
420#if defined(DEBUG)
421 if(tim::settings::verbose() > 2)
422 printf("beginning record for '%s' (id = %lli)...\n", name,
423 (long long int) *id);
424#endif
425 }
void timemory_create_record(const char *name, uint64_t *id, int n, int *ctypes)
Definition: library.cpp:156
::tim::statistics< Tp > max(::tim::statistics< Tp > lhs, const Tp &rhs)
Definition: statistics.hpp:320

References tim::enabled, get_current_components(), std::max(), timemory_create_record(), and tim::verbose.

Referenced by timemory_begin_record_().

◆ timemory_begin_record_enum()

void timemory_begin_record_enum ( const char *  name,
uint64_t *  id,
  ... 
)

Similar to timemory_begin_record but accepts a specific enumerated set of components, which is terminated by TIMEMORY_COMPONENTS_END.

uint64_t idx = 0;
// ...
#define CPU_UTIL
Definition: enum.h:185
#define WALL_CLOCK
Definition: enum.h:386

Definition at line 450 of file library.cpp.

451 {
453 if(!lk || tim::settings::enabled() == false)
454 {
456 return;
457 }
458
459 component_enum_t comp;
460 va_list args;
461 va_start(args, id);
462 for(int i = 0; i < TIMEMORY_COMPONENTS_END; ++i)
463 {
464 auto enum_arg = va_arg(args, int);
465 if(enum_arg >= TIMEMORY_COMPONENTS_END)
466 break;
467 comp.push_back(enum_arg);
468 }
469 va_end(args);
470
471 timemory_create_record(name, id, comp.size(), (int*) (comp.data()));
472
473#if defined(DEBUG)
474 if(tim::settings::verbose() > 2)
475 printf("beginning record for '%s' (id = %lli)...\n", name,
476 (long long int) *id);
477#endif
478 }
std::vector< TIMEMORY_COMPONENT > component_enum_t
Definition: library.cpp:62

References tim::enabled, std::max(), TIMEMORY_COMPONENTS_END, timemory_create_record(), and tim::verbose.

◆ timemory_begin_record_types()

void timemory_begin_record_types ( const char *  name,
uint64_t *  id,
const char *  ctypes 
)

Similar to timemory_begin_record but accepts a specific set of components as a string.

uint64_t idx = 0;
timemory_begin_record_types("foo", &idx, "wall_clock, cpu_util");
// ...
void timemory_begin_record_types(const char *name, uint64_t *id, const char *ctypes)
Similar to timemory_begin_record but accepts a specific set of components as a string.
Definition: library.cpp:429

Definition at line 429 of file library.cpp.

430 {
432 if(!lk || tim::settings::enabled() == false)
433 {
435 return;
436 }
437
438 auto comp = tim::enumerate_components(std::string(ctypes));
439 timemory_create_record(name, id, comp.size(), (int*) (comp.data()));
440
441#if defined(DEBUG)
442 if(tim::settings::verbose() > 2)
443 printf("beginning record for '%s' (id = %lli)...\n", name,
444 (long long int) *id);
445#endif
446 }
tim::mpl::apply< std::string > string
Definition: macros.hpp:53

References tim::enabled, tim::enumerate_components(), std::max(), timemory_create_record(), and tim::verbose.

Referenced by timemory_begin_record_types_().

◆ timemory_create_record()

void timemory_create_record ( const char *  name,
uint64_t *  id,
int  n,
int *  ctypes 
)
Parameters
[in]namelabel for the record
[in,out]idassigned a unique identifier for the record
[in]nnumber of components
[in]ctarray of enumeration identifiers of size n

Function called by timemory_begin_record, timemory_begin_record_enum, timemory_begin_record_types, timemory_get_begin_record, timemory_get_begin_record_enum, timemory_get_begin_record_types, timemory_push_region for creating and starting the current collection of components.

Definition at line 156 of file library.cpp.

157 {
159 {
160 (*timemory_create_function)(name, id, n, ctypes);
161 return;
162 }
163 // else: provide default behavior
164
165 static thread_local auto& _record_map = get_record_map();
167 _record_map.insert({ *id, toolset_t(name, true) });
168 tim::initialize(_record_map[*id], n, ctypes);
169 _record_map[*id].start();
170 if(_record_map.bucket_count() > _record_map.size())
171 _record_map.rehash(_record_map.size() + 10);
172 }
timemory_create_func_t timemory_create_function
The function pointer to set to customize which components are used by library interface.
Definition: library.cpp:51
uint64_t timemory_get_unique_id(void)
Returns a unique integer for a thread.
Definition: library.cpp:144
typename library_toolset_t::component_type toolset_t
Definition: library.cpp:59
void initialize(CompList< CompTypes... > &obj, std::initializer_list< EnumT > components)
Definition: initialize.hpp:53

References timemory_create_function.

Referenced by timemory_begin_record(), timemory_begin_record_enum(), timemory_begin_record_types(), timemory_create_record_(), timemory_get_begin_record(), timemory_get_begin_record_enum(), and timemory_get_begin_record_types().

◆ timemory_delete_record()

void timemory_delete_record ( uint64_t  nid)

Deletes the record created by timemory_create_record.

Definition at line 177 of file library.cpp.

178 {
180 {
181 (*timemory_delete_function)(id);
182 }
183 else if(get_record_map().find(id) != get_record_map().end())
184 {
185 static thread_local auto& _record_map = get_record_map();
186 // stop recording, destroy objects, and erase key from map
187 _record_map[id].stop();
188 _record_map.erase(id);
189 }
190 }
timemory_delete_func_t timemory_delete_function
The function pointer to set which deletes an entry created by timemory_create_function.
Definition: library.cpp:52

References timemory_delete_function.

Referenced by timemory_delete_record_(), and timemory_end_record().

◆ timemory_end_record()

void timemory_end_record ( uint64_t  id)
Parameters
[in]idIdentifier for the recording entry

Definition at line 557 of file library.cpp.

558 {
560 if(!lk || id == std::numeric_limits<uint64_t>::max())
561 return;
562
564
565#if defined(DEBUG)
566 if(tim::settings::verbose() > 2)
567 printf("ending record for %lli...\n", (long long int) id);
568#endif
569 }
void timemory_delete_record(uint64_t id)
Deletes the record created by timemory_create_record.
Definition: library.cpp:177

References std::max(), timemory_delete_record(), and tim::verbose.

Referenced by timemory_end_record_().

◆ timemory_finalize_library()

void timemory_finalize_library ( void  )

Finalizes timemory. Output will be generated. Any attempt to store data within timemory storage is undefined after this point and will likely cause errors.

Definition at line 253 of file library.cpp.

254 {
256 get_library_state()[1] = true;
257
258 auto _manager = tim::manager::master_instance();
260 if(!_manager || !_settings)
261 return;
262
263 if(_settings->get_enabled() == false && get_record_map().empty())
264 return;
265
266 auto& _record_map = get_record_map();
267
268 if(_settings->get_verbose() > 0)
269 {
270 printf("\n%s\n", spacer.c_str());
271 printf("\tFinalization of timemory library...\n");
272 printf("%s\n\n", spacer.c_str());
273 }
274
275 // put keys into a set so that a potential LD_PRELOAD for timemory_delete_record
276 // is called and there is not a concern for the map iterator
277 std::unordered_set<uint64_t> keys;
278 for(auto& itr : _record_map)
279 keys.insert(itr.first);
280
281 // delete all the records
282 for(const auto& itr : keys)
284
285 // clear the map
286 _record_map.clear();
287
288 // have the manager finalize
290 tim::manager::instance()->finalize();
291
292 // do the finalization
294
295 // just in case
296 _settings->get_enabled() = false;
297
298 // set the finalization state to true
299 tim::dmp::set_finalized(true);
300
301 // reset manager
302 tim::manager::instance().reset();
303
304 // PGI and Intel compilers don't respect destruction order
305#if defined(__PGI) || defined(__INTEL_COMPILER)
306 _settings->get_output() = false;
307#endif
308 }
static pointer_t instance()
Get a shared pointer to the instance for the current thread.
static pointer_t master_instance()
Get a shared pointer to the instance on the primary thread.
std::array< bool, 2 > & get_library_state()
Definition: library.cpp:127
void timemory_finalize()
finalization of the specified types
static settings * instance()
Definition: settings.hpp:536

References get_library_state().

Referenced by c_timemory_finalize(), and timemory_finalize_library_().

◆ timemory_get_begin_record()

uint64_t timemory_get_begin_record ( const char *  name)

Variant to timemory_begin_record which returns a unique integer.

Definition at line 482 of file library.cpp.

483 {
485 if(!lk || tim::settings::enabled() == false)
487
488 uint64_t id = 0;
489 auto& comp = get_current_components();
490 timemory_create_record(name, &id, comp.size(), (int*) (comp.data()));
491
492#if defined(DEBUG)
493 if(tim::settings::verbose() > 2)
494 printf("beginning record for '%s' (id = %lli)...\n", name,
495 (long long int) id);
496#endif
497
498 return id;
499 }

References tim::enabled, get_current_components(), std::max(), timemory_create_record(), and tim::verbose.

Referenced by timemory_get_begin_record_().

◆ timemory_get_begin_record_enum()

uint64_t timemory_get_begin_record_enum ( const char *  name,
  ... 
)

Variant to timemory_begin_record_enum which returns a unique integer.

Definition at line 524 of file library.cpp.

525 {
527 if(!lk || tim::settings::enabled() == false)
529
530 uint64_t id = 0;
531
532 component_enum_t comp;
533 va_list args;
534 va_start(args, name);
535 for(int i = 0; i < TIMEMORY_COMPONENTS_END; ++i)
536 {
537 auto enum_arg = va_arg(args, int);
538 if(enum_arg >= TIMEMORY_COMPONENTS_END)
539 break;
540 comp.push_back(enum_arg);
541 }
542 va_end(args);
543
544 timemory_create_record(name, &id, comp.size(), (int*) (comp.data()));
545
546#if defined(DEBUG)
547 if(tim::settings::verbose() > 2)
548 printf("beginning record for '%s' (id = %lli)...\n", name,
549 (long long int) id);
550#endif
551
552 return id;
553 }

References tim::enabled, std::max(), TIMEMORY_COMPONENTS_END, timemory_create_record(), and tim::verbose.

◆ timemory_get_begin_record_types()

uint64_t timemory_get_begin_record_types ( const char *  name,
const char *  ctypes 
)

Variant to timemory_begin_record_types which returns a unique integer.

Definition at line 503 of file library.cpp.

504 {
506 if(!lk || tim::settings::enabled() == false)
508
509 uint64_t id = 0;
510 auto comp = tim::enumerate_components(std::string(ctypes));
511 timemory_create_record(name, &id, comp.size(), (int*) (comp.data()));
512
513#if defined(DEBUG)
514 if(tim::settings::verbose() > 2)
515 printf("beginning record for '%s' (id = %lli)...\n", name,
516 (long long int) id);
517#endif
518
519 return id;
520 }

References tim::enabled, tim::enumerate_components(), std::max(), timemory_create_record(), and tim::verbose.

Referenced by timemory_get_begin_record_types_().

◆ timemory_get_unique_id()

uint64_t timemory_get_unique_id ( void  )

Returns a unique integer for a thread.

Definition at line 144 of file library.cpp.

145 {
146 // the maps are thread-local so no concerns for data-race here since
147 // two threads updating at once and subsequently losing once of the updates
148 // still results in a unique id for that thread
149 static uint64_t uniqID = 0;
150 return uniqID++;
151 }

◆ timemory_init_library()

void timemory_init_library ( int  argc,
char **  argv 
)

Initializes timemory. Not strictly necessary but highly recommended.

Definition at line 212 of file library.cpp.

213 {
215 if(get_library_state()[0])
216 return;
217 get_library_state()[0] = true;
218
219 if(argc < 1 && argv)
220 argc = 1;
221 if(argv == nullptr)
222 {
223 argc = 0;
224 }
225 else
226 {
227 int i = 0;
228 for(; i < argc; ++i)
229 {
230 if(argv[i] == nullptr)
231 {
232 argc = i;
233 break;
234 }
235 }
236 }
237
238 if(tim::settings::verbose() > 0)
239 {
240 printf("%s\n", spacer.c_str());
241 printf("\tInitialization of timemory library...\n");
242 printf("%s\n\n", spacer.c_str());
243 }
244
245 if(argc > 0 && argv)
247 tim::manager::instance()->update_metadata_prefix();
248 // tim::settings::parse();
249 }
void timemory_init(Args &&... _args)
Definition: config.hpp:49

References tim::argv, get_library_state(), and tim::verbose.

Referenced by c_timemory_init(), timemory_init_library_(), timemory_named_init_library(), and timemory_trace_init().

◆ timemory_is_throttled()

bool timemory_is_throttled ( const char *  name)

Definition at line 374 of file trace.cpp.

375 {
376 size_t _id = tim::get_hash_id(name);
377 return (get_throttle()->count(_id) > 0);
378 }
hash_value_t get_hash_id(Tp &&_prefix)
Definition: types.hpp:143

◆ timemory_library_is_initialized()

bool timemory_library_is_initialized ( void  )

Returns whether the library is initialized or not.

Definition at line 195 of file library.cpp.

195{ return get_library_state()[0]; }

References get_library_state().

◆ timemory_named_init_library()

void timemory_named_init_library ( char *  name)

Definition at line 200 of file library.cpp.

201 {
202 if(name)
203 {
204 char* _name[1] = { name };
205 timemory_init_library(1, _name);
206 }
207 }

References timemory_init_library().

◆ timemory_pause()

void timemory_pause ( void  )

Turn off timemory collection.

Definition at line 313 of file library.cpp.

313{ tim::settings::enabled() = false; }

References tim::enabled.

◆ timemory_pop_components()

void timemory_pop_components ( void  )

Inverse of the last timemory_push_components or timemory_push_components_enum call. Popping all components will restore to set the configured as the default.

Definition at line 399 of file library.cpp.

400 {
402 static thread_local auto& _stack = get_components_stack();
403 if(_stack.size() > 1)
404 _stack.pop_back();
405 }

Referenced by timemory_pop_components_().

◆ timemory_pop_region()

void timemory_pop_region ( const char *  name)
Parameters
[in]namelabel for region

Stops collection of components with label.

void foo()
{
// ...
}
void timemory_push_region(const char *name)
Definition: library.cpp:573
void timemory_pop_region(const char *name)
Definition: library.cpp:587

Definition at line 587 of file library.cpp.

588 {
590 if(!lk)
591 return;
592 auto& region_map = get_region_map();
593 auto itr = region_map.find(name);
594 if(itr == region_map.end() || (itr != region_map.end() && itr->second.empty()))
595 fprintf(stderr, "Warning! region '%s' does not exist!\n", name);
596 else
597 {
598 uint64_t idx = itr->second.top();
599 lk.release();
602 itr->second.pop();
603 }
604 }

Referenced by timemory_pop_region_().

◆ timemory_pop_trace()

void timemory_pop_trace ( const char *  name)

Definition at line 632 of file trace.cpp.

633 {
634 uint64_t _hash = std::numeric_limits<uint64_t>::max();
635 {
637 if(!get_library_state()[0] || get_library_state()[1])
638 return;
639 _hash = tim::get_hash_id(name);
640 }
642 }
void timemory_pop_trace_hash(uint64_t id)
Definition: trace.cpp:514
std::array< bool, 2 > & get_library_state()
Definition: library.cpp:127

References get_library_state(), std::max(), and timemory_pop_trace_hash().

◆ timemory_pop_trace_hash()

void timemory_pop_trace_hash ( uint64_t  id)

Definition at line 514 of file trace.cpp.

515 {
517 if(!get_library_state()[0] || get_library_state()[1])
518 return;
519
520 auto& _trace_map = get_trace_map();
521 if(!tim::settings::enabled() && _trace_map.empty())
522 {
523 if(tim::settings::debug() && _trace_map.empty())
524 fprintf(stderr,
525 "[timemory-trace]> timemory_pop_trace_hash(%lu) failed. "
526 "trace_map empty...\n",
527 (unsigned long) id);
528 return;
529 }
530
531 int64_t ntotal = _trace_map[id].size();
532 int64_t offset = ntotal - 1;
533
535 {
536 auto itr = tim::get_hash_ids()->find(id);
537 string_t name = (itr != tim::get_hash_ids()->end()) ? itr->second : "unknown";
538 fprintf(stderr,
539 "ending trace for '%s' (id = %llu, offset = %lli, rank = %i, pid = "
540 "%i, thread = %i)...\n",
541 name.c_str(), (long long unsigned) id, (long long int) offset,
542 tim::dmp::rank(), (int) tim::process::get_id(),
543 (int) tim::threading::get_id());
544 }
545
546 (*get_overhead())[id].first.stop();
547
548 // if there were no entries, return (pop called without a push)
549 if(offset < 0)
550 return;
551
552 if(offset >= 0 && ntotal > 0)
553 {
554 _trace_map[id].back().stop();
555 _trace_map[id].pop_back();
556 }
557
558 if(get_throttle() && get_throttle()->count(id) > 0)
559 return;
560
561 auto _count = ++(get_overhead()->at(id).second);
562
563 if(_count % tim::settings::throttle_count() == 0)
564 {
565 auto _accum = get_overhead()->at(id).first.get_accum() / _count;
566 if(_accum < tim::settings::throttle_value())
567 {
569 {
570 auto name = tim::get_hash_ids()->find(id)->second;
571 fprintf(
572 stderr,
573 "[timemory-trace]> Throttling all future calls to '%s' on rank = "
574 "%i, pid = "
575 "%i, thread = %i. avg runtime = %lu ns from %lu invocations... "
576 "Consider eliminating from instrumentation...\n",
577 name.c_str(), tim::dmp::rank(), (int) tim::process::get_id(),
578 (int) tim::threading::get_id(), (unsigned long) _accum,
579 (unsigned long) _count);
580 }
581 get_throttle()->insert(id);
582 }
583 else
584 {
585 if(_accum < (10 * tim::settings::throttle_value()) &&
587 {
588 auto name = tim::get_hash_ids()->find(id)->second;
589 fprintf(
590 stderr,
591 "[timemory-trace]> Warning! function call '%s' within an order "
592 "of magnitude of threshold for throttling value on rank = %i, "
593 "pid = "
594 "%i, thread = %i. avg runtime = %lu ns from %lu invocations... "
595 "Consider eliminating from instrumentation...\n",
596 name.c_str(), tim::dmp::rank(), (int) tim::process::get_id(),
597 (int) tim::threading::get_id(), (unsigned long) _accum,
598 (unsigned long) _count);
599 }
600 }
601 get_overhead()->at(id).first.reset();
602 get_overhead()->at(id).second = 0;
603 }
604 }
std::string string_t
Definition: library.cpp:57
hash_map_ptr_t & get_hash_ids()
throttle_value
Definition: settings.cpp:1680
throttle_count
Definition: settings.cpp:1678

References get_library_state().

Referenced by timemory_pop_trace().

◆ timemory_push_components()

void timemory_push_components ( const char *  _component_string)

Replace the current set of components with a new set of components.

timemory_push_components("priority_context_switch, read_bytes");
void timemory_push_components(const char *_component_string)
Replace the current set of components with a new set of components.
Definition: library.cpp:368

Definition at line 368 of file library.cpp.

369 {
371 static thread_local auto& _stack = get_components_stack();
372 _stack.push_back(tim::enumerate_components(_component_string));
373 }

Referenced by timemory_push_components_().

◆ timemory_push_components_enum()

void timemory_push_components_enum ( int  types,
  ... 
)

Replace the current set of components with a new set of components with the set of enumerations provided to the function. First argument should be the number of new components.

Definition at line 377 of file library.cpp.

378 {
380 static thread_local auto& _stack = get_components_stack();
381
382 component_enum_t comp({ types });
383 va_list args;
384 va_start(args, types);
385 for(int i = 0; i < TIMEMORY_COMPONENTS_END; ++i)
386 {
387 auto enum_arg = va_arg(args, int);
388 if(enum_arg >= TIMEMORY_COMPONENTS_END)
389 break;
390 comp.push_back(enum_arg);
391 }
392 va_end(args);
393
394 _stack.push_back(comp);
395 }

◆ timemory_push_region()

void timemory_push_region ( const char *  name)
Parameters
[in]namelabel for region

Starts collection of components with label.

void foo()
{
// ...
}

Definition at line 573 of file library.cpp.

574 {
576 if(!lk)
577 return;
578 auto& region_map = get_region_map();
579 lk.release();
580 auto idx = timemory_get_begin_record(name);
582 region_map[name].push(idx);
583 }
uint64_t timemory_get_begin_record(const char *name)
Variant to timemory_begin_record which returns a unique integer.
Definition: library.cpp:482

Referenced by timemory_push_region_().

◆ timemory_push_trace()

void timemory_push_trace ( const char *  name)

Definition at line 608 of file trace.cpp.

609 {
611 timemory_trace_init("", true, "");
612
613 uint64_t _hash = std::numeric_limits<uint64_t>::max();
614 {
617 PRINT_HERE("rank = %i, pid = %i, thread = %i, name = %s",
618 tim::dmp::rank(), (int) tim::process::get_id(),
619 (int) tim::threading::get_id(), name);
620
621 if(!get_library_state()[0] || get_library_state()[1] ||
623 return;
624
625 _hash = tim::add_hash_id(name);
626 }
628 }
void timemory_trace_init(const char *comps, bool read_command_line, const char *cmd)
Definition: trace.cpp:671
void timemory_push_trace_hash(uint64_t id)
Definition: trace.cpp:448
bool timemory_trace_is_initialized()
Definition: trace.cpp:366
#define PRINT_HERE(...)
Definition: macros.hpp:152

References tim::debug, tim::enabled, get_library_state(), std::max(), PRINT_HERE, timemory_push_trace_hash(), timemory_trace_init(), and timemory_trace_is_initialized().

◆ timemory_push_trace_hash()

void timemory_push_trace_hash ( uint64_t  id)

Definition at line 448 of file trace.cpp.

449 {
451 timemory_trace_init("", true, "");
452
453 static thread_local auto _copied = (timemory_copy_hash_ids(), true);
455
457
458 if(!lk)
459 {
460#if defined(DEBUG) || !defined(NDEBUG)
462 PRINT_HERE("Tracing is locked: %s", (lk) ? "Y" : "N");
463#endif
464 return;
465 }
466
468 {
469#if defined(DEBUG) || !defined(NDEBUG)
471 PRINT_HERE("Invalid library state: init = %s, fini = %s, enabled = %s",
472 (get_library_state()[0]) ? "Y" : "N",
473 (get_library_state()[1]) ? "Y" : "N",
474 (tim::settings::enabled()) ? "Y" : "N");
475#endif
476 return;
477 }
478
479 if(get_throttle()->count(id) > 0)
480 {
481#if defined(DEBUG) || !defined(NDEBUG)
483 PRINT_HERE("trace %llu is throttled", (unsigned long long) id);
484#endif
485 return;
486 }
487
488 auto& _trace_map = get_trace_map();
489 auto& _overh_map = *get_overhead();
490
491 if(tim::get_hash_ids()->find(id) == tim::get_hash_ids()->end())
492 return;
493
495 {
496 int64_t n = _trace_map[id].size();
497 auto itr = tim::get_hash_ids()->find(id);
498 string_t name = (itr != tim::get_hash_ids()->end()) ? itr->second : "unknown";
499 fprintf(stderr,
500 "beginning trace for '%s' (id = %llu, offset = %lli, rank = %i, pid "
501 "= %i, thread = %i)...\n",
502 name.c_str(), (long long unsigned) id, (long long int) n,
503 tim::dmp::rank(), (int) tim::process::get_id(),
504 (int) tim::threading::get_id());
505 }
506
507 _trace_map[id].emplace_back(traceset_t{ id });
508 _trace_map[id].back().start();
509 _overh_map[id].first.start();
510 }
return _hash_map end()
void consume_parameters(ArgsT &&...)
Definition: types.hpp:285
This is a variadic component wrapper which combines the features of tim::component_tuple<T....
Definition: types.hpp:63
void timemory_copy_hash_ids()
Definition: trace.cpp:431

References tim::consume_parameters(), tim::debug, tim::enabled, get_library_state(), PRINT_HERE, timemory_copy_hash_ids(), timemory_trace_init(), and timemory_trace_is_initialized().

Referenced by timemory_push_trace().

◆ timemory_remove_components()

void timemory_remove_components ( const char *  _component_string)

Remove some components to the current set of components being collected. Any components which are not currently being collected are ignored.

timemory_add_components("priority_context_switch, read_bytes");

Definition at line 358 of file library.cpp.

359 {
361 auto& _stack = get_current_components();
362 for(auto itr : tim::enumerate_components(_component_string))
363 _stack.erase(std::remove(_stack.begin(), _stack.end(), itr), _stack.end());
364 }

References tim::enumerate_components(), and get_current_components().

◆ timemory_reset_throttle()

void timemory_reset_throttle ( const char *  name)

Definition at line 382 of file trace.cpp.

383 {
384 size_t _id = tim::get_hash_id(name);
385 auto itr = get_throttle()->find(_id);
386 if(itr != get_throttle()->end())
387 get_throttle()->erase(itr);
388 }

◆ timemory_resume()

void timemory_resume ( void  )

Turn on timemory collection.

Definition at line 318 of file library.cpp.

318{ tim::settings::enabled() = true; }

References tim::enabled.

◆ timemory_set_default()

void timemory_set_default ( const char *  _component_string)

Pass in a default set of components to use. Will be overridden by TIMEMORY_COMPONENTS environment variable.

timemory_set_default("wall_clock, cpu_clock, cpu_util");
void timemory_set_default(const char *_component_string)
Pass in a default set of components to use. Will be overridden by TIMEMORY_COMPONENTS environment var...
Definition: library.cpp:322

Definition at line 322 of file library.cpp.

323 {
326 tim::get_env<std::string>("TIMEMORY_GLOBAL_COMPONENTS", _component_string);
327 // tim::set_env("TIMEMORY_COMPONENTS", _component_string, 0);
328 static thread_local auto& _stack = get_components_stack();
329 if(_stack.empty())
331 }
std::string & get_default_components()
Definition: library.cpp:102

References get_default_components().

Referenced by timemory_set_default_().

◆ timemory_set_environ()

void timemory_set_environ ( const char *  evar,
const char *  eval,
int  over,
int  parse 
)
Parameters
[in]evarEnvironment variable name
[in]evalEnvironment variable value
[in]ovrOverwrite existing environment variable when > 0
[in]upUpdate settings when > 0

Set an environment variable and (potentially) update settings with new value.

// overwrites the TIMEMORY_GLOBAL_COMPONENTS environment variable and updates
// settings
timemory_set_environ("TIIMEMORY_GLOBAL_COMPONENTS,
"wall_clock, cpu_clock, cpu_util", 1, 1);
void timemory_set_environ(const char *evar, const char *eval, int over, int parse)
Definition: library.cpp:335

Definition at line 335 of file library.cpp.

336 {
338 if(evar && eval)
339 {
340 tim::set_env(evar, eval, over);
341 if(parse > 0)
343 }
344 }
void set_env(const std::string &env_var, const Tp &_val, int override)
static void parse(settings *=instance< TIMEMORY_API >())
Definition: settings.cpp:410

References tim::settings::parse(), and tim::set_env().

◆ timemory_trace_finalize()

void timemory_trace_finalize ( void  )

Definition at line 808 of file trace.cpp.

809 {
811 if(library_trace_count.load() == 0)
812 return;
813
814 auto _manager = tim::manager::master_instance();
816 if(!_manager || !_settings)
817 return;
818
819 auto _debug = _settings->get_debug();
820 if(_settings->get_verbose() > 1 || _settings->get_debug())
821 PRINT_HERE("rank = %i, pid = %i, thread = %i", tim::dmp::rank(),
822 (int) tim::process::get_id(), (int) tim::threading::get_id());
823
824 CONDITIONAL_PRINT_HERE(_debug, "%s", "getting count");
825 // do the finalization
826 auto _count = --library_trace_count;
827
828 if(_count > 0)
829 {
830 CONDITIONAL_PRINT_HERE(_debug, "%s", "positive count");
831 // have the manager finalize
833 tim::manager::instance()->finalize();
834 CONDITIONAL_PRINT_HERE(_debug, "%s", "returning");
835 return;
836 }
837
838 CONDITIONAL_PRINT_HERE(_debug, "%s", "secondary lock");
839 tim::auto_lock_t lock(tim::type_mutex<TIMEMORY_API>());
840
841 CONDITIONAL_PRINT_HERE(_debug, "%s", "setting state");
842 // tim::settings::enabled() = false;
843 get_library_state()[1] = true;
844
845 CONDITIONAL_PRINT_HERE(_debug, "%s", "barrier");
846 tim::mpi::barrier();
847
848 CONDITIONAL_PRINT_HERE(_debug, "%s", "resetting");
849 // reset traces just in case
851
852 // if already finalized
853 bool _skip_stop = false;
854 if(!_manager || _manager->is_finalized())
855 _skip_stop = true;
856
857 // clean up any remaining entries
858 if(!_skip_stop)
859 {
860 CONDITIONAL_PRINT_HERE(_debug, "%s", "cleaning trace map");
861 for(auto& itr : get_trace_map())
862 {
863 for(auto& eitr : itr.second)
864 eitr.stop();
865 // delete all the records
866 itr.second.clear();
867 }
868 CONDITIONAL_PRINT_HERE(_debug, "%s", "clearing trace map");
869 // delete all the records
870 get_trace_map().clear();
871 }
872
873 CONDITIONAL_PRINT_HERE(_debug, "%s", "resetting mpi gotcha");
874 // deactivate the gotcha wrappers
875 if(use_mpi_gotcha)
876 mpi_gotcha_handle.reset();
877
878 CONDITIONAL_PRINT_HERE(_debug, "%s", "finalizing library");
879 // finalize the library
881
882 CONDITIONAL_PRINT_HERE(_debug, "%s", "finalized trace");
883 }
void reset(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:599
std::unique_lock< mutex_t > auto_lock_t
Unique lock type around mutex_t.
Definition: locking.hpp:42
#define CONDITIONAL_PRINT_HERE(CONDITION,...)
Definition: macros.hpp:183

◆ timemory_trace_init()

void timemory_trace_init ( const char *  comps,
bool  read_command_line,
const char *  cmd 
)

Definition at line 671 of file trace.cpp.

672 {
674 if(!tim::manager::instance() || tim::manager::instance()->is_finalized())
675 return;
676
677 // configures the output path
678 auto _configure_output_path = [&]() {
679 static bool _performed_explicit = false;
680 if(_performed_explicit || tim::settings::output_path() != "timemory-output")
681 return;
683 {
684 auto _init = [](int _ac, char** _av) { timemory_init_library(_ac, _av); };
686 }
687 else
688 {
689 std::string exe_name = (cmd) ? cmd : "";
690 if(!exe_name.empty())
691 _performed_explicit = true;
692
693 while(exe_name.find('\\') != std::string::npos)
694 exe_name = exe_name.substr(exe_name.find_last_of('\\') + 1);
695 while(exe_name.find('/') != std::string::npos)
696 exe_name = exe_name.substr(exe_name.find_last_of('/') + 1);
697
698 static const std::vector<std::string> _exe_suffixes = { ".py", ".exe" };
699 for(const auto& ext : _exe_suffixes)
700 {
701 if(exe_name.find(ext) != std::string::npos)
702 exe_name.erase(exe_name.find(ext), ext.length() + 1);
703 }
704
705 exe_name = std::string("timemory-") + exe_name + "-output";
706 for(auto& itr : exe_name)
707 {
708 if(itr == '_')
709 itr = '-';
710 }
711
713 }
715 tim::manager::instance()->update_metadata_prefix();
716 };
717
718 // write the info about the rank/pid/thread/command
719 auto _write_info = [&]() {
720 std::stringstream _info;
721 _info << "[timemory_trace_init]> ";
722 if(tim::dmp::is_initialized())
723 _info << "rank = " << tim::dmp::rank() << ", ";
724 _info << "pid = " << tim::process::get_id() << ", ";
725 _info << "tid = " << tim::threading::get_id();
726 if(cmd && strlen(cmd) > 0)
727 _info << ", command: " << cmd;
728 if(comps && strlen(comps) > 0)
729 _info << ", default components: " << comps;
730 fprintf(stderr, "%s\n", _info.str().c_str());
731 };
732
733 // configures the tracing components
734 auto _configure_components = [&]() {
735 if(comps && strlen(comps) > 0)
736 {
737 _write_info();
738 tim::set_env<std::string>("TIMEMORY_TRACE_COMPONENTS", comps, 0);
741 }
742
744
745 // configure bundle
746 user_trace_bundle::global_init(true);
747 // tim::operation::init<user_trace_bundle>(
748 // tim::operation::mode_constant<tim::operation::init_mode::global>{});
749 };
750
751 if(!get_library_state()[0] && library_trace_count++ == 0)
752 {
753 _configure_components();
754 _configure_output_path();
755
757 get_library_state()[0] = true;
758
759 auto _exit_action = [](int nsig) {
760 auto _manager = tim::manager::master_instance();
761 if(_manager && !_manager->is_finalized() && !_manager->is_finalizing())
762 {
763 std::cout << "Finalizing after signal: " << nsig << " :: "
765 static_cast<tim::sys_signal>(nsig))
766 << std::endl;
768 }
769 };
771 std::atexit(&timemory_trace_finalize);
772#if !defined(TIMEMORY_MACOS)
773 // Apple clang version 11.0.3 (clang-1103.0.32.62) doesn't seem to have this
774 // function
775 std::at_quick_exit(&tim::timemory_finalize);
776#endif
777
778#if defined(TIMEMORY_MPI_GOTCHA)
779 if(!mpi_gotcha_handle.get())
780 {
781 mpi_gotcha_handle =
782 std::make_shared<mpi_trace_bundle_t>("timemory_trace_mpi_gotcha");
783 mpi_trace_gotcha::get_trace_components() = comps;
785 mpi_trace_gotcha::get_command() = (cmd) ? cmd : "";
786 if(mpi_is_attached)
787 mpi_trace_gotcha::set_attr();
788 mpi_gotcha_handle->start();
789 }
790 else if(mpi_gotcha_handle.get())
791 {
792 tim::manager::instance()->update_metadata_prefix();
793 }
794#endif
795 }
796 else
797 {
799 PRINT_HERE("trace already initialized: %s",
800 (get_library_state()[0]) ? "Y" : "N");
801
802 _configure_components();
803 }
804 }
static void use_exit_hook(bool val)
Enable setting std::exit callback.
Definition: manager.hpp:176
static std::string str(const sys_signal &)
Definition: signals.hpp:147
static void set_exit_action(signal_function_t _f)
Definition: signals.hpp:280
void read_command_line(Func &&_func)
this only works on Linux where there is a /proc/<PID>/cmdline file
Definition: config.hpp:65
std::string exe_name
Definition: config.cpp:77
sys_signal
Definition: declaration.hpp:69
output_path
Definition: settings.cpp:1661
trace_components
Definition: settings.cpp:1694
void timemory_trace_finalize(void)
Definition: trace.cpp:808

References tim::plotting::cmd, tim::exe_name, tim::manager::instance(), tim::output_path, tim::config::read_command_line(), and timemory_init_library().

Referenced by timemory_push_trace(), and timemory_push_trace_hash().

◆ timemory_trace_is_initialized()

bool timemory_trace_is_initialized ( void  )

Definition at line 366 of file trace.cpp.

367 {
368 return (get_library_state()[0] &&
369 library_trace_count.load(std::memory_order_relaxed) > 0);
370 }

References get_library_state().

Referenced by timemory_push_trace(), and timemory_push_trace_hash().

◆ timemory_trace_set_env()

void timemory_trace_set_env ( const char *  env_var,
const char *  env_val 
)

Definition at line 658 of file trace.cpp.

659 {
661 tim::set_env<std::string>(env_var, env_val, 0);
662 if(get_library_state()[0])
663 {
665 user_trace_bundle::global_init(true);
666 }
667 }

References get_library_state(), and tim::settings::parse().

Variable Documentation

◆ timemory_create_function

timemory_create_func_t timemory_create_function
extern

The function pointer to set to customize which components are used by library interface.

using namespace tim::component;
using test_list_t =
static std::map<uint64_t, std::shared_ptr<test_list_t>> test_map;
void
custom_create_record(const char* name, uint64_t* id, int n, int* ct)
{
uint64_t idx = timemory_get_unique_id();
auto tmp = std::make_shared<test_list_t>(name);
tim::initialize(*tmp, n, ct);
tmp->initialize<cpu_util, cpu_clock>();
test_map[idx] = tmp;
test_map[idx]->start();
*id = idx;
}
void
main()
{
// ... using default create/delete functions ...
timemory_create_function = &custom_create_record;
// ... using custom create/delete functions ...
// ... using default create/delete functions ...
}
This is a variadic component wrapper where all components are optional at runtime....

Definition at line 51 of file library.cpp.

Referenced by timemory_create_record().

◆ timemory_delete_function

timemory_delete_func_t timemory_delete_function
extern

The function pointer to set which deletes an entry created by timemory_create_function.

static std::map<uint64_t, std::shared_ptr<test_list_t>> test_map;
void
custom_delete_record(uint64_t id)
{
auto itr = test_map.find(id);
if(itr != test_map.end())
{
itr->second->stop();
test_map.erase(itr);
}
}
void
main()
{
// ... using default create/delete functions ...
timemory_create_function = &custom_create_record;
timemory_delete_function = &custom_delete_record;
// ... using custom create/delete functions ...
// ... using default create/delete functions ...
}

Definition at line 52 of file library.cpp.

Referenced by timemory_delete_record().