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.cpp File Reference
#include "timemory/compat/library.h"
#include "timemory/config.hpp"
#include "timemory/library.h"
#include "timemory/runtime/configure.hpp"
#include "timemory/timemory.hpp"
#include "timemory/trace.hpp"
#include <cstdarg>
#include <deque>
#include <iostream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
+ Include dependency graph for library.cpp:

Go to the source code of this file.

Macros

#define TIMEMORY_LIBRARY_SOURCE   1
 

Typedefs

using string_t = std::string
 
using library_toolset_t = TIMEMORY_LIBRARY_TYPE
 
using toolset_t = typename library_toolset_t::component_type
 
using region_map_t = std::unordered_map< std::string, std::stack< uint64_t > >
 
using record_map_t = std::unordered_map< uint64_t, toolset_t >
 
using component_enum_t = std::vector< TIMEMORY_COMPONENT >
 
using components_stack_t = std::deque< component_enum_t >
 

Functions

std::string & get_default_components ()
 
component_enum_tget_current_components ()
 
std::array< bool, 2 > & get_library_state ()
 
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 *ctypes)
 
void timemory_delete_record (uint64_t id)
 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 *_component_string)
 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 over, int parse)
 
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. More...
 
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. More...
 
void timemory_push_components (const char *_component_string)
 Replace the current set of components with a new set of components. More...
 
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. 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_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. More...
 
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. 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_types (const char *name, const char *ctypes)
 Variant to timemory_begin_record_types 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...
 
void timemory_end_record (uint64_t id)
 
void timemory_push_region (const char *name)
 
void timemory_pop_region (const char *name)
 
void timemory_create_record_ (const char *name, uint64_t *id, int n, int *ct)
 
void timemory_delete_record_ (uint64_t id)
 
void timemory_init_library_ (int argc, char **argv)
 
void timemory_finalize_library_ (void)
 
void timemory_set_default_ (const char *components)
 
void timemory_push_components_ (const char *components)
 
void timemory_pop_components_ (void)
 
void timemory_begin_record_ (const char *name, uint64_t *id)
 
void timemory_begin_record_types_ (const char *name, uint64_t *id, const char *ctypes)
 
uint64_t timemory_get_begin_record_ (const char *name)
 
uint64_t timemory_get_begin_record_types_ (const char *name, const char *ctypes)
 
void timemory_end_record_ (uint64_t id)
 
void timemory_push_region_ (const char *name)
 
void timemory_pop_region_ (const char *name)
 

Variables

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

Macro Definition Documentation

◆ TIMEMORY_LIBRARY_SOURCE

#define TIMEMORY_LIBRARY_SOURCE   1

Definition at line 26 of file library.cpp.

Typedef Documentation

◆ component_enum_t

using component_enum_t = std::vector<TIMEMORY_COMPONENT>

Definition at line 62 of file library.cpp.

◆ components_stack_t

using components_stack_t = std::deque<component_enum_t>

Definition at line 63 of file library.cpp.

◆ library_toolset_t

Definition at line 58 of file library.cpp.

◆ record_map_t

using record_map_t = std::unordered_map<uint64_t, toolset_t>

Definition at line 61 of file library.cpp.

◆ region_map_t

using region_map_t = std::unordered_map<std::string, std::stack<uint64_t> >

Definition at line 60 of file library.cpp.

◆ string_t

using string_t = std::string

Definition at line 57 of file library.cpp.

◆ toolset_t

using toolset_t = typename library_toolset_t::component_type

Definition at line 59 of file library.cpp.

Function Documentation

◆ get_current_components()

component_enum_t & get_current_components ( )
inline

Definition at line 113 of file library.cpp.

114{
115 auto& _stack = get_components_stack();
116 if(_stack.empty())
117 {
118 _stack.push_back(
119 tim::enumerate_components(get_default_components(), "TIMEMORY_COMPONENTS"));
120 }
121 return _stack.back();
122}
std::string & get_default_components()
Definition: library.cpp:102
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

Referenced by timemory_add_components(), timemory_begin_record(), timemory_get_begin_record(), and timemory_remove_components().

◆ get_default_components()

std::string & get_default_components ( )
inline

Definition at line 102 of file library.cpp.

103{
104 static std::string _instance =
105 tim::get_env<std::string>("TIMEMORY_GLOBAL_COMPONENTS", "wall_clock");
106 return _instance;
107}
tim::mpl::apply< std::string > string
Definition: macros.hpp:53

Referenced by timemory_set_default().

◆ get_library_state()

std::array< bool, 2 > & get_library_state ( )

Definition at line 127 of file library.cpp.

128{
129 static auto _instance = std::array<bool, 2>({ { false, false } });
130 return _instance;
131}

Referenced by timemory_finalize_library(), timemory_init_library(), timemory_library_is_initialized(), timemory_pop_trace(), timemory_pop_trace_hash(), timemory_push_trace(), timemory_push_trace_hash(), timemory_trace_is_initialized(), and timemory_trace_set_env().

◆ timemory_add_components()

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.

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

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

◆ 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_()

void timemory_begin_record_ ( const char *  name,
uint64_t *  id 
)

Definition at line 638 of file library.cpp.

639 {
640 timemory_begin_record(name, id);
641 }

References 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 TIMEMORY_COMPONENTS_END
Definition: enum.h:155
#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 }

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

Referenced by timemory_begin_record_types_().

◆ timemory_begin_record_types_()

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

Definition at line 643 of file library.cpp.

644 {
645 timemory_begin_record_types(name, id, ctypes);
646 }

References timemory_begin_record_types().

◆ timemory_create_record()

void timemory_create_record ( const char *  name,
uint64_t *  id,
int  n,
int *  ct 
)
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_create_record_()

void timemory_create_record_ ( const char *  name,
uint64_t *  id,
int  n,
int *  ct 
)

Definition at line 612 of file library.cpp.

613 {
614 timemory_create_record(name, id, n, ct);
615 }

References timemory_create_record().

◆ timemory_delete_record()

void timemory_delete_record ( uint64_t  id)

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_delete_record_()

void timemory_delete_record_ ( uint64_t  id)

Definition at line 617 of file library.cpp.

void timemory_delete_record(uint64_t id)
Deletes the record created by timemory_create_record.
Definition: library.cpp:177

References timemory_delete_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 }

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

Referenced by timemory_end_record_().

◆ timemory_end_record_()

void timemory_end_record_ ( uint64_t  id)

Definition at line 658 of file library.cpp.

658{ return timemory_end_record(id); }

References 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
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255
static settings * instance()
Definition: settings.hpp:536

References get_library_state().

Referenced by c_timemory_finalize(), and timemory_finalize_library_().

◆ timemory_finalize_library_()

void timemory_finalize_library_ ( void  )

Definition at line 624 of file library.cpp.

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().

◆ 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_()

uint64_t timemory_get_begin_record_ ( const char *  name)

Definition at line 648 of file library.cpp.

649 {
650 return timemory_get_begin_record(name);
651 }
uint64_t timemory_get_begin_record(const char *name)
Variant to timemory_begin_record which returns a unique integer.
Definition: library.cpp:482

References 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_begin_record_types_()

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

Definition at line 653 of file library.cpp.

654 {
655 return timemory_get_begin_record_types(name, ctypes);
656 }
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: library.cpp:503

References 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
char ** argv
Definition: config.cpp:55

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_init_library_()

void timemory_init_library_ ( int  argc,
char **  argv 
)

Definition at line 619 of file library.cpp.

620 {
622 }
void timemory_init_library(int argc, char **argv)
Initializes timemory. Not strictly necessary but highly recommended.
Definition: library.cpp:212

References tim::argv, and timemory_init_library().

◆ 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_components_()

void timemory_pop_components_ ( void  )

Definition at line 636 of file library.cpp.

void timemory_pop_components(void)
Inverse of the last timemory_push_components or timemory_push_components_enum call....
Definition: library.cpp:399

References 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_region_()

void timemory_pop_region_ ( const char *  name)

Definition at line 662 of file library.cpp.

662{ return timemory_pop_region(name); }

References timemory_pop_region().

◆ timemory_push_components()

void timemory_push_components ( const char *  components)

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_()

void timemory_push_components_ ( const char *  components)

Definition at line 631 of file library.cpp.

632 {
634 }
components
Definition: settings.cpp:1700

References tim::components, and timemory_push_components().

◆ timemory_push_components_enum()

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.

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 }

Referenced by timemory_push_region_().

◆ timemory_push_region_()

void timemory_push_region_ ( const char *  name)

Definition at line 660 of file library.cpp.

660{ return timemory_push_region(name); }

References timemory_push_region().

◆ timemory_remove_components()

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.

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_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 *  components)

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 }

References get_default_components().

Referenced by timemory_set_default_().

◆ timemory_set_default_()

void timemory_set_default_ ( const char *  components)

Definition at line 626 of file library.cpp.

627 {
629 }

References tim::components, and timemory_set_default().

◆ timemory_set_environ()

void timemory_set_environ ( const char *  evar,
const char *  eval,
int  ovr,
int  up 
)
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().

Variable Documentation

◆ timemory_create_function

timemory_create_func_t timemory_create_function = nullptr

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 = nullptr

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().