timemory  3.2.1
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 61 of file library.cpp.

◆ components_stack_t

using components_stack_t = std::deque<component_enum_t>

Definition at line 62 of file library.cpp.

◆ library_toolset_t

Definition at line 57 of file library.cpp.

◆ record_map_t

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

Definition at line 60 of file library.cpp.

◆ region_map_t

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

Definition at line 59 of file library.cpp.

◆ string_t

using string_t = std::string

Definition at line 56 of file library.cpp.

◆ toolset_t

using toolset_t = typename library_toolset_t::component_type

Definition at line 58 of file library.cpp.

Function Documentation

◆ get_current_components()

component_enum_t& get_current_components ( )
inline

Definition at line 112 of file library.cpp.

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

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

Referenced by timemory_set_default().

◆ get_library_state()

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

Definition at line 126 of file library.cpp.

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

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_init(), 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:347

Definition at line 347 of file library.cpp.

348  {
350  auto& _stack = get_current_components();
351  for(auto itr : tim::enumerate_components(_component_string))
352  _stack.push_back(itr);
353  }
component_enum_t & get_current_components()
Definition: library.cpp:112
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:556
void timemory_begin_record(const char *name, uint64_t *id)
Definition: library.cpp:408

Definition at line 408 of file library.cpp.

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

References tim::enabled, get_current_components(), 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 637 of file library.cpp.

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

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:180
#define TIMEMORY_COMPONENTS_END
Definition: enum.h:150
#define WALL_CLOCK
Definition: enum.h:375

Definition at line 449 of file library.cpp.

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

References tim::enabled, 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:428

Definition at line 428 of file library.cpp.

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

References tim::enabled, tim::enumerate_components(), 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 642 of file library.cpp.

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

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 155 of file library.cpp.

156  {
158  {
159  (*timemory_create_function)(name, id, n, ctypes);
160  return;
161  }
162  // else: provide default behavior
163 
164  static thread_local auto& _record_map = get_record_map();
165  *id = timemory_get_unique_id();
166  _record_map.insert({ *id, toolset_t(name, true) });
167  tim::initialize(_record_map[*id], n, ctypes);
168  _record_map[*id].start();
169  if(_record_map.bucket_count() > _record_map.size())
170  _record_map.rehash(_record_map.size() + 10);
171  }
timemory_create_func_t timemory_create_function
The function pointer to set to customize which components are used by library interface.
Definition: library.cpp:50
uint64_t timemory_get_unique_id(void)
Returns a unique integer for a thread.
Definition: library.cpp:143
typename library_toolset_t::component_type toolset_t
Definition: library.cpp:58
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 611 of file library.cpp.

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

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 176 of file library.cpp.

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

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 616 of file library.cpp.

616 { timemory_delete_record(id); }
void timemory_delete_record(uint64_t id)
Deletes the record created by timemory_create_record.
Definition: library.cpp:176

References timemory_delete_record().

◆ timemory_end_record()

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

Definition at line 556 of file library.cpp.

557  {
559  if(!lk || id == std::numeric_limits<uint64_t>::max())
560  return;
561 
563 
564 #if defined(DEBUG)
565  if(tim::settings::verbose() > 2)
566  printf("ending record for %lli...\n", (long long int) id);
567 #endif
568  }

References timemory_delete_record(), and tim::verbose.

Referenced by timemory_end_record_().

◆ timemory_end_record_()

void timemory_end_record_ ( uint64_t  id)

Definition at line 657 of file library.cpp.

657 { 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 252 of file library.cpp.

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

References tim::_settings, get_library_state(), tim::settings::instance(), and tim::manager::master_instance().

Referenced by c_timemory_finalize(), and timemory_finalize_library_().

◆ timemory_finalize_library_()

void timemory_finalize_library_ ( void  )

Definition at line 623 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:252

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 481 of file library.cpp.

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

References tim::enabled, get_current_components(), 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 647 of file library.cpp.

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

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 523 of file library.cpp.

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

References tim::enabled, 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 502 of file library.cpp.

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

References tim::enabled, tim::enumerate_components(), 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 652 of file library.cpp.

653  {
654  return timemory_get_begin_record_types(name, ctypes);
655  }
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:502

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 143 of file library.cpp.

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

◆ timemory_init_library()

void timemory_init_library ( int  argc,
char **  argv 
)

Initializes timemory. Not strictly necessary but highly recommended.

Definition at line 211 of file library.cpp.

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

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 618 of file library.cpp.

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

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 194 of file library.cpp.

194 { return get_library_state()[0]; }

References get_library_state().

◆ timemory_named_init_library()

void timemory_named_init_library ( char *  name)

Definition at line 199 of file library.cpp.

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

References timemory_init_library().

◆ timemory_pause()

void timemory_pause ( void  )

Turn off timemory collection.

Definition at line 312 of file library.cpp.

312 { 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 398 of file library.cpp.

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

Referenced by timemory_pop_components_().

◆ timemory_pop_components_()

void timemory_pop_components_ ( void  )

Definition at line 635 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:398

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:572
void timemory_pop_region(const char *name)
Definition: library.cpp:586

Definition at line 586 of file library.cpp.

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

Referenced by timemory_pop_region_().

◆ timemory_pop_region_()

void timemory_pop_region_ ( const char *  name)

Definition at line 661 of file library.cpp.

661 { 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:367

Definition at line 367 of file library.cpp.

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

Referenced by timemory_push_components_().

◆ timemory_push_components_()

void timemory_push_components_ ( const char *  components)

Definition at line 630 of file library.cpp.

631  {
633  }
components
Definition: settings.cpp:1394

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 376 of file library.cpp.

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

◆ 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 572 of file library.cpp.

573  {
575  if(!lk)
576  return;
577  auto& region_map = get_region_map();
578  lk.release();
579  auto idx = timemory_get_begin_record(name);
581  region_map[name].push(idx);
582  }

Referenced by timemory_push_region_().

◆ timemory_push_region_()

void timemory_push_region_ ( const char *  name)

Definition at line 659 of file library.cpp.

659 { 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 357 of file library.cpp.

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

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

◆ timemory_resume()

void timemory_resume ( void  )

Turn on timemory collection.

Definition at line 317 of file library.cpp.

317 { 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:321

Definition at line 321 of file library.cpp.

322  {
325  tim::get_env<std::string>("TIMEMORY_GLOBAL_COMPONENTS", _component_string);
326  // tim::set_env("TIMEMORY_COMPONENTS", _component_string, 0);
327  static thread_local auto& _stack = get_components_stack();
328  if(_stack.empty())
330  }

References get_default_components().

Referenced by timemory_set_default_().

◆ timemory_set_default_()

void timemory_set_default_ ( const char *  components)

Definition at line 625 of file library.cpp.

626  {
628  }

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:334

Definition at line 334 of file library.cpp.

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

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 50 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 51 of file library.cpp.

Referenced by timemory_delete_record().