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.
settings.cpp
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2020, The Regents of the University of California,
4 // through Lawrence Berkeley National Laboratory (subject to receipt of any
5 // required approvals from the U.S. Dept. of Energy). All rights reserved.
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 
25 #ifndef TIMEMORY_SETTINGS_SETTINGS_CPP_
26 # define TIMEMORY_SETTINGS_SETTINGS_CPP_
27 
29 # include "timemory/backends/dmp.hpp"
30 # include "timemory/defines.h"
31 # include "timemory/mpl/policy.hpp"
34 # include "timemory/tpls/cereal/archives.hpp"
41 
42 # include <fstream>
43 
44 namespace tim
45 {
46 //
47 //--------------------------------------------------------------------------------------//
48 //
49 template <typename Archive>
50 void
52 {
53  if(settings::instance())
54  ar(cereal::make_nvp("settings", *settings::instance()));
55 }
56 //
57 //--------------------------------------------------------------------------------------//
58 //
59 template <typename Archive>
60 void
62 {
63  ar(cereal::make_nvp("settings", _obj));
64 }
65 //
66 //--------------------------------------------------------------------------------------//
67 //
69 std::shared_ptr<settings>
71 {
72  // do not take reference to ensure push/pop w/o template parameters do not change
73  // the settings
74  static auto _instance = shared_instance<TIMEMORY_API>();
75  return _instance;
76 }
77 //
78 //--------------------------------------------------------------------------------------//
79 //
81 settings*
83 {
84  // do not take reference to ensure push/pop w/o template parameters do not change
85  // the settings
86  static auto _instance = shared_instance();
87  return _instance.get();
88 }
89 //
90 //--------------------------------------------------------------------------------------//
91 //
94 settings::command_line()
95 {
96  return instance()->get_environment();
97 }
98 //
99 //--------------------------------------------------------------------------------------//
100 //
103 settings::environment()
104 {
105  return instance()->get_environment();
106 }
107 //
108 //--------------------------------------------------------------------------------------//
109 //
113 {
114 # if defined(TIMEMORY_UNIX)
115  strvector_t _environ;
116  if(environ != nullptr)
117  {
118  int idx = 0;
119  while(environ[idx] != nullptr)
120  _environ.push_back(environ[idx++]);
121  }
122  return _environ;
123 # else
124  return std::vector<std::string>();
125 # endif
126 }
127 //
128 //--------------------------------------------------------------------------------------//
129 //
132 get_local_datetime(const char* dt_format, std::time_t* dt_curr)
133 {
134  char mbstr[100];
135  if(!dt_curr)
137 
138  if(std::strftime(mbstr, sizeof(mbstr), dt_format, std::localtime(dt_curr)))
139  return std::string{ mbstr };
140  return std::string{};
141 }
142 //
143 //--------------------------------------------------------------------------------------//
144 //
148 {
149  for(auto& itr : str)
150  itr = ::tolower(itr);
151  return str;
152 }
153 //
154 //--------------------------------------------------------------------------------------//
155 //
159 {
160  for(auto& itr : str)
161  itr = ::toupper(itr);
162  return str;
163 }
164 //
165 //--------------------------------------------------------------------------------------//
166 //
170 {
171  auto _dir = input_path();
172  auto _prefix = input_prefix();
173 
174  return filepath::osrepr(_dir + std::string("/") + _prefix);
175 }
176 //
177 //--------------------------------------------------------------------------------------//
178 //
182 {
183  static auto _settings = instance();
184 
185  auto _dir = (_settings)
186  ? _settings->get_output_path()
187  : get_env<std::string>(TIMEMORY_SETTINGS_KEY("OUTPUT_PATH"), ".");
188  auto _prefix = (_settings)
189  ? _settings->get_output_prefix()
190  : get_env<std::string>(TIMEMORY_SETTINGS_KEY("OUTPUT_PREFIX"), "");
191  auto _time_output = (_settings)
192  ? _settings->get_time_output()
193  : get_env<bool>(TIMEMORY_SETTINGS_KEY("TIME_OUTPUT"), false);
194  auto _time_format =
195  (_settings)
196  ? _settings->get_time_format()
197  : get_env<std::string>(TIMEMORY_SETTINGS_KEY("TIME_FORMAT"), "%F_%I.%M_%p");
198 
199  if(_time_output)
200  {
201  // get the statically stored launch time
202  auto* _launch_time = get_launch_time(TIMEMORY_API{});
203  auto _local_datetime = get_local_datetime(_time_format.c_str(), _launch_time);
204  if(_dir.find(_local_datetime) == std::string::npos)
205  {
206  if(_dir.length() > 0 && _dir[_dir.length() - 1] != '/')
207  _dir += "/";
208  _dir += _local_datetime;
209  }
210  }
211 
212  // always return zero if fake. if makedir failed, don't prefix with directory
213  auto ret = (fake) ? 0 : makedir(_dir);
214  return (ret == 0) ? filepath::osrepr(_dir + std::string("/") + _prefix)
215  : filepath::osrepr(std::string("./") + _prefix);
216 }
217 //
218 //--------------------------------------------------------------------------------------//
219 //
221 void
223 {
224  auto& _cmdline = command_line();
225  _cmdline.clear();
226  for(int i = 0; i < argc; ++i)
227  _cmdline.push_back(std::string(argv[i]));
228 }
229 //
230 //--------------------------------------------------------------------------------------//
231 //
235  bool _mpi_init, const int32_t _mpi_rank, bool fake,
236  std::string _explicit)
237 {
238  // if there isn't an explicit prefix, get the <OUTPUT_PATH>/<OUTPUT_PREFIX>
239  auto _prefix = (!_explicit.empty()) ? _explicit : get_global_output_prefix(fake);
240 
241  // return on empty
242  if(_prefix.empty())
243  return "";
244 
245  auto only_ascii = [](char c) { return !isascii(c); };
246 
247  _prefix.erase(std::remove_if(_prefix.begin(), _prefix.end(), only_ascii),
248  _prefix.end());
249 
250  // if explicit prefix is provided, then make the directory
251  if(!_explicit.empty())
252  {
253  auto ret = makedir(_prefix);
254  if(ret != 0)
255  _prefix = filepath::osrepr(std::string("./"));
256  }
257 
258  // add the mpi rank if not root
259  auto _rank_suffix = (_mpi_init && _mpi_rank >= 0)
260  ? (std::string("_") + std::to_string(_mpi_rank))
261  : std::string("");
262 
263  // add period before extension
264  if(_ext.find('.') != 0)
265  _ext = std::string(".") + _ext;
266  auto plast = static_cast<intmax_t>(_prefix.length()) - 1;
267  // add dash if not empty, not ends in '/', and last char is alphanumeric
268  if(!_prefix.empty() && _prefix[plast] != '/' && isalnum(_prefix[plast]))
269  _prefix += "-";
270  // create the path
271  std::string fpath = _prefix + _tag + _rank_suffix + _ext;
272  using strpairvec_t = std::vector<std::pair<std::string, std::string>>;
273  for(auto&& itr : strpairvec_t{ { "--", "-" }, { "__", "_" }, { "//", "/" } })
274  {
275  auto pos = std::string::npos;
276  while((pos = fpath.find(itr.first)) != std::string::npos)
277  fpath.replace(pos, itr.first.length(), itr.second);
278  }
279  return filepath::osrepr(fpath);
280 }
281 //
282 //--------------------------------------------------------------------------------------//
283 //
287  bool _mpi_init, const int32_t _mpi_rank,
288  std::string _explicit)
289 {
290  if(settings::input_path().empty())
292 
293  if(settings::input_prefix().empty())
295 
296  auto _prefix = (_explicit.length() > 0) ? _explicit : get_global_input_prefix();
297 
298  auto only_ascii = [](char c) { return !isascii(c); };
299 
300  _prefix.erase(std::remove_if(_prefix.begin(), _prefix.end(), only_ascii),
301  _prefix.end());
302 
303  if(_explicit.length() > 0)
304  _prefix = filepath::osrepr(std::string("./"));
305 
306  auto _rank_suffix = (_mpi_init && _mpi_rank >= 0)
307  ? (std::string("_") + std::to_string(_mpi_rank))
308  : std::string("");
309  if(_ext.find('.') != 0)
310  _ext = std::string(".") + _ext;
311  auto plast = _prefix.length() - 1;
312  if(_prefix.length() > 0 && _prefix[plast] != '/' && isalnum(_prefix[plast]))
313  _prefix += "_";
314  auto fpath = utility::path(_prefix + _tag + _rank_suffix + _ext);
315  while(fpath.find("//") != std::string::npos)
316  fpath.replace(fpath.find("//"), 2, "/");
317  return std::move(fpath);
318 }
319 //
320 //--------------------------------------------------------------------------------------//
321 //
323 void
324 settings::parse(std::shared_ptr<settings> _settings)
325 {
326  if(_settings)
327  parse(_settings.get());
328 }
329 //
330 //--------------------------------------------------------------------------------------//
331 //
332 // function to parse the environment for settings
333 //
334 // Nearly all variables will parse env when first access but this allows provides a
335 // way to reparse the environment so that default settings (possibly from previous
336 // invocation) can be overwritten
337 //
339 void
341 {
342  if(!_settings)
343  {
344  PRINT_HERE("%s", "nullptr to tim::settings");
345  return;
346  }
347 
348  if(_settings->get_suppress_parsing())
349  {
350  static auto _once = false;
351  if(!_once)
352  {
353  PRINT_HERE("%s", "settings parsing has been suppressed");
354  _once = true;
355  }
356  return;
357  }
358 
359  for(const auto& itr : *_settings)
360  {
361  itr.second->parse();
362  }
363 }
364 //
365 //--------------------------------------------------------------------------------------//
366 //
369 : m_data(data_type{})
370 {
371  // PRINT_HERE("%s", "");
372  initialize();
373 }
374 //
375 //--------------------------------------------------------------------------------------//
376 //
379 : m_data(data_type{})
380 , m_order(rhs.m_order)
381 , m_command_line(rhs.m_command_line)
382 , m_environment(rhs.m_environment)
383 {
384  for(auto& itr : rhs.m_data)
385  m_data.emplace(itr.first, itr.second->clone());
386  for(auto& itr : m_order)
387  {
388  if(m_data.find(itr) == m_data.end())
389  {
390  auto ritr = rhs.m_data.find(itr);
391  if(ritr == rhs.m_data.end())
392  {
393  TIMEMORY_EXCEPTION(string_t("Error! Missing ordered entry: ") + itr)
394  }
395  else
396  {
397  m_data.emplace(itr, ritr->second->clone());
398  }
399  }
400  }
401 }
402 //
403 //--------------------------------------------------------------------------------------//
404 //
406 settings&
408 {
409  // PRINT_HERE("%s", "");
410  if(this == &rhs)
411  return *this;
412 
413  for(auto& itr : rhs.m_data)
414  m_data[itr.first] = itr.second->clone();
415  m_order = rhs.m_order;
416  m_command_line = rhs.m_command_line;
417  m_environment = rhs.m_environment;
418  for(auto& itr : m_order)
419  {
420  if(m_data.find(itr) == m_data.end())
421  {
422  auto ritr = rhs.m_data.find(itr);
423  if(ritr == rhs.m_data.end())
424  {
425  TIMEMORY_EXCEPTION(string_t("Error! Missing ordered entry: ") + itr)
426  }
427  else
428  {
429  m_data.emplace(itr, ritr->second->clone());
430  }
431  }
432  }
433  return *this;
434 }
435 //
436 //--------------------------------------------------------------------------------------//
437 //
439 void
440 settings::initialize_core()
441 {
442  // PRINT_HERE("%s", "");
443  auto homedir = get_env<string_t>("HOME");
444 
446  string_t, config_file, TIMEMORY_SETTINGS_KEY("CONFIG_FILE"),
447  "Configuration file for timemory",
448  TIMEMORY_JOIN(';', TIMEMORY_JOIN('/', homedir, ".timemory.cfg"),
449  TIMEMORY_JOIN('/', homedir, ".timemory.json"),
450  TIMEMORY_JOIN('/', homedir, ".config", "timemory.cfg"),
451  TIMEMORY_JOIN('/', homedir, ".config", "timemory.json")),
452  strvector_t({ "-C", "--timemory-config" }));
453 
455  bool, suppress_config, TIMEMORY_SETTINGS_KEY("SUPPRESS_CONFIG"),
456  "Disable processing of setting configuration files", false,
457  strvector_t({ "--timemory-suppress-config", "--timemory-no-config" }));
458 
460  bool, suppress_parsing, TIMEMORY_SETTINGS_KEY("SUPPRESS_PARSING"),
461  "Disable parsing environment", false,
462  strvector_t({ "--timemory-suppress-parsing" }), -1, 1);
463 
465  bool, enabled, TIMEMORY_SETTINGS_KEY("ENABLED"), "Activation state of timemory",
466  TIMEMORY_DEFAULT_ENABLED, strvector_t({ "--timemory-enabled" }), -1, 1);
467 
469  "Verbosity level", 0,
470  strvector_t({ "--timemory-verbose" }), 1);
471 
473  "Enable debug output", false,
474  strvector_t({ "--timemory-debug" }), -1, 1);
475 
477  bool, flat_profile, TIMEMORY_SETTINGS_KEY("FLAT_PROFILE"),
478  "Set the label hierarchy mode to default to flat",
479  scope::get_fields()[scope::flat::value],
480  strvector_t({ "--timemory-flat-profile" }), -1, 1);
481 
483  bool, timeline_profile, TIMEMORY_SETTINGS_KEY("TIMELINE_PROFILE"),
484  "Set the label hierarchy mode to default to timeline",
485  scope::get_fields()[scope::timeline::value],
486  strvector_t({ "--timemory-timeline-profile" }), -1, 1);
487 
489  uint16_t, max_depth, TIMEMORY_SETTINGS_KEY("MAX_DEPTH"),
490  "Set the maximum depth of label hierarchy reporting",
491  std::numeric_limits<uint16_t>::max(), strvector_t({ "--timemory-max-depth" }), 1);
492 }
493 //
494 //--------------------------------------------------------------------------------------//
495 //
497 void
498 settings::initialize_components()
499 {
500  // PRINT_HERE("%s", "");
502  string_t, global_components, TIMEMORY_SETTINGS_KEY("GLOBAL_COMPONENTS"),
503  "A specification of components which is used by multiple variadic bundlers and "
504  "user_bundles as the fall-back set of components if their specific variable is "
505  "not set. E.g. user_mpip_bundle will use this if TIMEMORY_MPIP_COMPONENTS is not "
506  "specified",
507  "", strvector_t({ "--timemory-global-components" }));
508 
510  string_t, ompt_components, TIMEMORY_SETTINGS_KEY("OMPT_COMPONENTS"),
511  "A specification of components which will be added "
512  "to structures containing the 'user_ompt_bundle'. Priority: TRACE_COMPONENTS -> "
513  "PROFILER_COMPONENTS -> COMPONENTS -> GLOBAL_COMPONENTS",
514  "", strvector_t({ "--timemory-ompt-components" }));
515 
517  string_t, mpip_components, TIMEMORY_SETTINGS_KEY("MPIP_COMPONENTS"),
518  "A specification of components which will be added "
519  "to structures containing the 'user_mpip_bundle'. Priority: TRACE_COMPONENTS -> "
520  "PROFILER_COMPONENTS -> COMPONENTS -> GLOBAL_COMPONENTS",
521  "", strvector_t({ "--timemory-mpip-components" }));
522 
524  string_t, ncclp_components, TIMEMORY_SETTINGS_KEY("NCCLP_COMPONENTS"),
525  "A specification of components which will be added "
526  "to structures containing the 'user_ncclp_bundle'. Priority: MPIP_COMPONENTS -> "
527  "TRACE_COMPONENTS -> PROFILER_COMPONENTS -> COMPONENTS -> GLOBAL_COMPONENTS",
528  "", strvector_t({ "--timemory-ncclp-components" }));
529 
531  string_t, trace_components, TIMEMORY_SETTINGS_KEY("TRACE_COMPONENTS"),
532  "A specification of components which will be used by the interfaces which are "
533  "designed for full profiling. These components will be subjected to throttling. "
534  "Priority: COMPONENTS -> GLOBAL_COMPONENTS",
535  "", strvector_t({ "--timemory-trace-components" }));
536 
538  string_t, profiler_components, TIMEMORY_SETTINGS_KEY("PROFILER_COMPONENTS"),
539  "A specification of components which will be used by the interfaces which are "
540  "designed for full python profiling. This specification will be overridden by a "
541  "trace_components specification. Priority: COMPONENTS -> GLOBAL_COMPONENTS",
542  "", strvector_t({ "--timemory-profiler-components" }));
543 
545  string_t, kokkos_components, TIMEMORY_SETTINGS_KEY("KOKKOS_COMPONENTS"),
546  "A specification of components which will be used by the interfaces which are "
547  "designed for kokkos profiling. Priority: TRACE_COMPONENTS -> "
548  "PROFILER_COMPONENTS -> COMPONENTS -> GLOBAL_COMPONENTS",
549  "", strvector_t({ "--timemory-kokkos-components" }));
550 
552  string_t, components, TIMEMORY_SETTINGS_KEY("COMPONENTS"),
553  "A specification of components which is used by the library interface. This "
554  "falls back to TIMEMORY_GLOBAL_COMPONENTS.",
555  "", strvector_t({ "--timemory-components" }));
556 }
557 //
558 //--------------------------------------------------------------------------------------//
559 //
561 void
562 settings::initialize_io()
563 {
564  // PRINT_HERE("%s", "");
566  TIMEMORY_SETTINGS_KEY("AUTO_OUTPUT"),
567  "Generate output at application termination", true,
568  strvector_t({ "--timemory-auto-output" }), -1, 1);
569 
571  bool, cout_output, TIMEMORY_SETTINGS_KEY("COUT_OUTPUT"), "Write output to stdout",
572  true, strvector_t({ "--timemory-cout-output" }), -1, 1);
573 
575  bool, file_output, TIMEMORY_SETTINGS_KEY("FILE_OUTPUT"), "Write output to files",
576  true, strvector_t({ "--timemory-file-output" }), -1, 1);
577 
579  TIMEMORY_SETTINGS_KEY("TEXT_OUTPUT"),
580  "Write text output files", true,
581  strvector_t({ "--timemory-text-output" }), -1, 1);
582 
584  TIMEMORY_SETTINGS_KEY("JSON_OUTPUT"),
585  "Write json output files", true,
586  strvector_t({ "--timemory-json-output" }), -1, 1);
587 
589  TIMEMORY_SETTINGS_KEY("TREE_OUTPUT"),
590  "Write hierarchical json output files", true,
591  strvector_t({ "--timemory-tree-output" }), -1, 1);
592 
594  TIMEMORY_SETTINGS_KEY("DART_OUTPUT"),
595  "Write dart measurements for CDash", false,
596  strvector_t({ "--timemory-dart-output" }), -1, 1);
597 
599  bool, time_output, TIMEMORY_SETTINGS_KEY("TIME_OUTPUT"),
600  "Output data to subfolder w/ a timestamp (see also: TIMEMORY_TIME_FORMAT)", false,
601  strvector_t({ "--timemory-time-output" }), -1, 1);
602 
604  bool, plot_output, TIMEMORY_SETTINGS_KEY("PLOT_OUTPUT"),
605  "Generate plot outputs from json outputs", TIMEMORY_DEFAULT_PLOTTING,
606  strvector_t({ "--timemory-plot-output" }), -1, 1);
607 
609  bool, diff_output, TIMEMORY_SETTINGS_KEY("DIFF_OUTPUT"),
610  "Generate a difference output vs. a pre-existing output (see also: "
611  "TIMEMORY_INPUT_PATH and TIMEMORY_INPUT_PREFIX)",
612  false, strvector_t({ "--timemory-diff-output" }), -1, 1);
613 
615  bool, flamegraph_output, TIMEMORY_SETTINGS_KEY("FLAMEGRAPH_OUTPUT"),
616  "Write a json output for flamegraph visualization (use chrome://tracing)", true,
617  strvector_t({ "--timemory-flamegraph-output" }), -1, 1);
618 
620  bool, ctest_notes, TIMEMORY_SETTINGS_KEY("CTEST_NOTES"),
621  "Write a CTestNotes.txt for each text output", false,
622  strvector_t({ "--timemory-ctest-notes" }), -1, 1);
623 
625  string_t, output_path, TIMEMORY_SETTINGS_KEY("OUTPUT_PATH"),
626  "Explicitly specify the output folder for results", "timemory-output",
627  strvector_t({ "--timemory-output-path" }), 1); // folder
628 
630  TIMEMORY_SETTINGS_KEY("OUTPUT_PREFIX"),
631  "Explicitly specify a prefix for all output files",
632  "", strvector_t({ "--timemory-output-prefix" }),
633  1); // file prefix
634 
636  string_t, input_path, TIMEMORY_SETTINGS_KEY("INPUT_PATH"),
637  "Explicitly specify the input folder for difference "
638  "comparisons (see also: TIMEMORY_DIFF_OUTPUT)",
639  "", strvector_t({ "--timemory-input-path" }), 1); // folder
640 
642  string_t, input_prefix, TIMEMORY_SETTINGS_KEY("INPUT_PREFIX"),
643  "Explicitly specify the prefix for input files used in difference comparisons "
644  "(see also: TIMEMORY_DIFF_OUTPUT)",
645  "", strvector_t({ "--timemory-input-prefix" }), 1); // file prefix
646 
648  string_t, input_extensions, TIMEMORY_SETTINGS_KEY("INPUT_EXTENSIONS"),
649  "File extensions used when searching for input files used in difference "
650  "comparisons (see also: TIMEMORY_DIFF_OUTPUT)",
651  "json,xml", strvector_t({ "--timemory-input-extensions" })); // extensions
652 }
653 //
654 //--------------------------------------------------------------------------------------//
655 //
657 void
658 settings::initialize_format()
659 {
660  // PRINT_HERE("%s", "");
662  string_t, time_format, TIMEMORY_SETTINGS_KEY("TIME_FORMAT"),
663  "Customize the folder generation when TIMEMORY_TIME_OUTPUT is enabled (see also: "
664  "strftime)",
665  "%F_%I.%M_%p", strvector_t({ "--timemory-time-format" }), 1);
666 
668  TIMEMORY_SETTINGS_KEY("PRECISION"),
669  "Set the global output precision for components",
670  -1, strvector_t({ "--timemory-precision" }), 1);
671 
673  "Set the global output width for components", -1,
674  strvector_t({ "--timemory-width" }), 1);
675 
677  TIMEMORY_SETTINGS_KEY("MAX_WIDTH"),
678  "Set the maximum width for component label outputs",
679  120, strvector_t({ "--timemory-max-width" }), 1);
680 
682  bool, scientific, TIMEMORY_SETTINGS_KEY("SCIENTIFIC"),
683  "Set the global numerical reporting to scientific format", false,
684  strvector_t({ "--timemory-scientific" }), -1, 1);
685 
687  int16_t, timing_precision, TIMEMORY_SETTINGS_KEY("TIMING_PRECISION"),
688  "Set the precision for components with 'is_timing_category' type-trait", -1);
689 
691  int16_t, timing_width, TIMEMORY_SETTINGS_KEY("TIMING_WIDTH"),
692  "Set the output width for components with 'is_timing_category' type-trait", -1);
693 
695  string_t, timing_units, TIMEMORY_SETTINGS_KEY("TIMING_UNITS"),
696  "Set the units for components with 'uses_timing_units' type-trait", "",
697  strvector_t({ "--timemory-timing-units" }), 1);
698 
700  TIMEMORY_SETTINGS_KEY("TIMING_SCIENTIFIC"),
701  "Set the numerical reporting format for components "
702  "with 'is_timing_category' type-trait",
703  false);
704 
706  int16_t, memory_precision, TIMEMORY_SETTINGS_KEY("MEMORY_PRECISION"),
707  "Set the precision for components with 'is_memory_category' type-trait", -1);
708 
710  int16_t, memory_width, TIMEMORY_SETTINGS_KEY("MEMORY_WIDTH"),
711  "Set the output width for components with 'is_memory_category' type-trait", -1);
712 
714  string_t, memory_units, TIMEMORY_SETTINGS_KEY("MEMORY_UNITS"),
715  "Set the units for components with 'uses_memory_units' type-trait", "",
716  strvector_t({ "--timemory-memory-units" }), 1);
717 
719  TIMEMORY_SETTINGS_KEY("MEMORY_SCIENTIFIC"),
720  "Set the numerical reporting format for components "
721  "with 'is_memory_category' type-trait",
722  false);
723 
725  int64_t, separator_frequency, TIMEMORY_SETTINGS_KEY("SEPARATOR_FREQ"),
726  "Frequency of dashed separator lines in text output", 0);
727 }
728 //
729 //--------------------------------------------------------------------------------------//
730 //
732 void
733 settings::initialize_parallel()
734 {
735  // PRINT_HERE("%s", "");
737  size_t, max_thread_bookmarks, TIMEMORY_SETTINGS_KEY("MAX_THREAD_BOOKMARKS"),
738  "Maximum number of times a worker thread bookmarks the call-graph location w.r.t."
739  " the master thread. Higher values tend to increase the finalization merge time",
740  50);
741 
743  bool, collapse_threads, TIMEMORY_SETTINGS_KEY("COLLAPSE_THREADS"),
744  "Enable/disable combining thread-specific data", true,
745  strvector_t({ "--timemory-collapse-threads" }), -1, 1);
746 
748  bool, collapse_processes, TIMEMORY_SETTINGS_KEY("COLLAPSE_PROCESSES"),
749  "Enable/disable combining process-specific data", true,
750  strvector_t({ "--timemory-collapse-processes" }), -1, 1);
751 
753  bool, cpu_affinity, TIMEMORY_SETTINGS_KEY("CPU_AFFINITY"),
754  "Enable pinning threads to CPUs (Linux-only)", false,
755  strvector_t({ "--timemory-cpu-affinity" }), -1, 1);
756 
758  process::id_t, target_pid, TIMEMORY_SETTINGS_KEY("TARGET_PID"),
759  "Process ID for the components which require this", process::get_target_id());
760 
762  bool, mpi_init, TIMEMORY_SETTINGS_KEY("MPI_INIT"),
763  "Enable/disable timemory calling MPI_Init / MPI_Init_thread during certain "
764  "timemory_init(...) invocations",
765  false, strvector_t({ "--timemory-mpi-init" }), -1, 1);
766 
768  bool, mpi_finalize, TIMEMORY_SETTINGS_KEY("MPI_FINALIZE"),
769  "Enable/disable timemory calling MPI_Finalize during "
770  "timemory_finalize(...) invocations",
771  false, strvector_t({ "--timemory-mpi-finalize" }), -1, 1);
772 
774  bool, mpi_thread, TIMEMORY_SETTINGS_KEY("MPI_THREAD"),
775  "Call MPI_Init_thread instead of MPI_Init (see also: TIMEMORY_MPI_INIT)",
776  mpi::use_mpi_thread(), strvector_t({ "--timemory-mpi-thread" }), -1, 1);
777 
779  string_t, mpi_thread_type, TIMEMORY_SETTINGS_KEY("MPI_THREAD_TYPE"),
780  "MPI_Init_thread mode: 'single', 'serialized', "
781  "'funneled', or 'multiple' (see also: "
782  "TIMEMORY_MPI_INIT and TIMEMORY_MPI_THREAD)",
783  mpi::use_mpi_thread_type(), strvector_t({ "--timemory-mpi-thread-type" }), 1);
784 
786  bool, upcxx_init, TIMEMORY_SETTINGS_KEY("UPCXX_INIT"),
787  "Enable/disable timemory calling upcxx::init() during certain "
788  "timemory_init(...) invocations",
789  false, strvector_t({ "--timemory-upcxx-init" }), -1, 1);
790 
792  bool, upcxx_finalize, TIMEMORY_SETTINGS_KEY("UPCXX_FINALIZE"),
793  "Enable/disable timemory calling upcxx::finalize() during "
794  "timemory_finalize()",
795  false, strvector_t({ "--timemory-upcxx-finalize" }), -1, 1);
796 
798  int32_t, node_count, TIMEMORY_SETTINGS_KEY("NODE_COUNT"),
799  "Total number of nodes used in application. Setting this value > 1 will result "
800  "in aggregating N processes into groups of N / NODE_COUNT",
801  0, strvector_t({ "--timemory-node-count" }), 1);
802 }
803 //
804 //--------------------------------------------------------------------------------------//
805 //
807 void
808 settings::initialize_tpls()
809 {
810  // PRINT_HERE("%s", "");
812  bool, papi_threading, TIMEMORY_SETTINGS_KEY("PAPI_THREADING"),
813  "Enable multithreading support when using PAPI", true,
814  strvector_t({ "--timemory-papi-threading" }), -1, 1);
815 
817  bool, papi_multiplexing, TIMEMORY_SETTINGS_KEY("PAPI_MULTIPLEXING"),
818  "Enable multiplexing when using PAPI", false,
819  strvector_t({ "--timemory-papi-multiplexing" }), -1, 1);
820 
822  bool, papi_fail_on_error, TIMEMORY_SETTINGS_KEY("PAPI_FAIL_ON_ERROR"),
823  "Configure PAPI errors to trigger a runtime error", false,
824  strvector_t({ "--timemory-papi-fail-on-error" }), -1, 1);
825 
827  bool, papi_quiet, TIMEMORY_SETTINGS_KEY("PAPI_QUIET"),
828  "Configure suppression of reporting PAPI errors/warnings", false,
829  strvector_t({ "--timemory-papi-quiet" }), -1, 1);
830 
832  string_t, papi_events, TIMEMORY_SETTINGS_KEY("PAPI_EVENTS"),
833  "PAPI presets and events to collect (see also: papi_avail)", "",
834  strvector_t({ "--timemory-papi-events" }));
835 
837  bool, papi_attach, TIMEMORY_SETTINGS_KEY("PAPI_ATTACH"),
838  "Configure PAPI to attach to another process (see also: TIMEMORY_TARGET_PID)",
839  false);
840 
842  int, papi_overflow, TIMEMORY_SETTINGS_KEY("PAPI_OVERFLOW"),
843  "Value at which PAPI hw counters trigger an overflow callback", 0,
844  strvector_t({ "--timemory-papi-overflow" }), 1);
845 
847  uint64_t, cuda_event_batch_size, TIMEMORY_SETTINGS_KEY("CUDA_EVENT_BATCH_SIZE"),
848  "Batch size for create cudaEvent_t in cuda_event components", 5);
849 
851  bool, nvtx_marker_device_sync, TIMEMORY_SETTINGS_KEY("NVTX_MARKER_DEVICE_SYNC"),
852  "Use cudaDeviceSync when stopping NVTX marker (vs. cudaStreamSychronize)", true);
853 
855  int32_t, cupti_activity_level, TIMEMORY_SETTINGS_KEY("CUPTI_ACTIVITY_LEVEL"),
856  "Default group of kinds tracked via CUpti Activity API", 1,
857  strvector_t({ "--timemory-cupti-activity-level" }), 1);
858 
860  TIMEMORY_SETTINGS_KEY("CUPTI_ACTIVITY_KINDS"),
861  "Specific cupti activity kinds to track", "",
862  strvector_t({ "--timemory-cupti-activity-kinds" }));
863 
865  string_t, cupti_events, TIMEMORY_SETTINGS_KEY("CUPTI_EVENTS"),
866  "Hardware counter event types to collect on NVIDIA GPUs", "",
867  strvector_t({ "--timemory-cupti-events" }));
868 
870  string_t, cupti_metrics, TIMEMORY_SETTINGS_KEY("CUPTI_METRICS"),
871  "Hardware counter metric types to collect on NVIDIA GPUs", "",
872  strvector_t({ "--timemory-cupti-metrics" }));
873 
875  TIMEMORY_SETTINGS_KEY("CUPTI_DEVICE"),
876  "Target device for CUPTI data collection", 0,
877  strvector_t({ "--timemory-cupti-device" }), 1);
878 
879  insert<int>("TIMEMORY_CUPTI_PCSAMPLING_PERIOD", "cupti_pcsampling_period",
880  "The period for PC sampling. Must be >= 5 and <= 31", 8,
881  strvector_t{ "--timemory-cupti-pcsampling-period" });
882 
883  insert<bool>(
884  "TIMEMORY_CUPTI_PCSAMPLING_PER_LINE", "cupti_pcsampling_per_line",
885  "Report the PC samples per-line or collapse into one entry for entire function",
886  false, strvector_t{ "--timemory-cupti-pcsampling-per-line" });
887 
888  insert<bool>(
889  "TIMEMORY_CUPTI_PCSAMPLING_REGION_TOTALS", "cupti_pcsampling_region_totals",
890  "When enabled, region markers will report total samples from all child functions",
891  true, strvector_t{ "--timemory-cupti-pcsampling-region-totals" });
892 
893  insert<bool>("TIMEMORY_CUPTI_PCSAMPLING_SERIALIZED", "cupti_pcsampling_serialized",
894  "Serialize all the kernel functions", false,
895  strvector_t{ "--timemory-cupti-pcsampling-serialize" });
896 
897  insert<size_t>("TIMEMORY_CUPTI_PCSAMPLING_NUM_COLLECT",
898  "cupti_pcsampling_num_collect", "Number of PCs to be collected",
899  size_t{ 100 },
900  strvector_t{ "--timemory-cupti-pcsampling-num-collect" });
901 
902  insert<std::string>("TIMEMORY_CUPTI_PCSAMPLING_STALL_REASONS",
903  "cupti_pcsampling_stall_reasons",
904  "The PC sampling stall reasons to count", std::string{},
905  strvector_t{ "--timemory-cupti-pcsampling-stall-reasons" });
906 
908  TIMEMORY_SETTINGS_KEY("CRAYPAT"),
909  "Configure the CrayPAT categories to collect",
910  get_env<std::string>("PAT_RT_PERFCTR", ""))
911 
913  string_t, python_exe, TIMEMORY_SETTINGS_KEY("PYTHON_EXE"),
914  "Configure the python executable to use", TIMEMORY_PYTHON_PLOTTER,
915  strvector_t({ "--timemory-python-exe" }));
916 }
917 //
918 //--------------------------------------------------------------------------------------//
919 //
921 void
922 settings::initialize_roofline()
923 {
924  // PRINT_HERE("%s", "");
926  string_t, roofline_mode, TIMEMORY_SETTINGS_KEY("ROOFLINE_MODE"),
927  "Configure the roofline collection mode. Options: 'op' 'ai'.", "op",
928  strvector_t({ "--timemory-roofline-mode" }), 1, 1, strvector_t({ "op", "ai" }));
929 
931  string_t, cpu_roofline_mode, TIMEMORY_SETTINGS_KEY("ROOFLINE_MODE_CPU"),
932  "Configure the roofline collection mode for CPU specifically. Options: 'op', "
933  "'ai'",
934  "op", strvector_t({ "--timemory-cpu-roofline-mode" }), 1, 1,
935  strvector_t({ "op", "ai" }));
936 
938  string_t, gpu_roofline_mode, TIMEMORY_SETTINGS_KEY("ROOFLINE_MODE_GPU"),
939  "Configure the roofline collection mode for GPU specifically. Options: 'op' "
940  "'ai'.",
941  static_cast<tsettings<string_t>*>(
942  m_data[TIMEMORY_SETTINGS_KEY("ROOFLINE_MODE")].get())
943  ->get(),
944  strvector_t({ "--timemory-gpu-roofline-mode" }), 1, 1,
945  strvector_t({ "op", "ai" }));
946 
948  string_t, cpu_roofline_events, TIMEMORY_SETTINGS_KEY("ROOFLINE_EVENTS_CPU"),
949  "Configure custom hw counters to add to the cpu roofline", "");
950 
952  string_t, gpu_roofline_events, TIMEMORY_SETTINGS_KEY("ROOFLINE_EVENTS_GPU"),
953  "Configure custom hw counters to add to the gpu roofline", "");
954 
956  TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS"),
957  "Configure roofline labels/descriptions/output-files "
958  "encode the list of data types",
959  false);
960 
962  bool, roofline_type_labels_cpu, TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS_CPU"),
963  "Configure labels, etc. for the roofline components "
964  "for CPU (see also: TIMEMORY_ROOFLINE_TYPE_LABELS)",
965  static_cast<tsettings<bool>*>(
966  m_data[TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS")].get())
967  ->get());
968 
970  bool, roofline_type_labels_gpu, TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS_GPU"),
971  "Configure labels, etc. for the roofline components "
972  "for GPU (see also: TIMEMORY_ROOFLINE_TYPE_LABELS)",
973  static_cast<tsettings<bool>*>(
974  m_data[TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS")].get())
975  ->get());
976 
978  TIMEMORY_SETTINGS_KEY("INSTRUCTION_ROOFLINE"),
979  "Configure the roofline to include the hw counters "
980  "required for generating an instruction roofline",
981  false);
982 }
983 //
984 //--------------------------------------------------------------------------------------//
985 //
987 settings::initialize_miscellaneous()
988 {
989  // PRINT_HERE("%s", "");
991  bool, add_secondary, TIMEMORY_SETTINGS_KEY("ADD_SECONDARY"),
992  "Enable/disable components adding secondary (child) entries when available. E.g. "
993  "suppress individual CUDA kernels, etc. when using Cupti components",
994  true, strvector_t({ "--timemory-add-secondary" }), -1, 1);
995 
997  size_t, throttle_count, TIMEMORY_SETTINGS_KEY("THROTTLE_COUNT"),
998  "Minimum number of laps before checking whether a key should be throttled", 10000,
999  strvector_t({ "--timemory-throttle-count" }), 1);
1000 
1002  size_t, throttle_value, TIMEMORY_SETTINGS_KEY("THROTTLE_VALUE"),
1003  "Average call time in nanoseconds when # laps > throttle_count that triggers "
1004  "throttling",
1005  10000, strvector_t({ "--timemory-throttle-value" }), 1);
1006 
1008  bool, enable_signal_handler, TIMEMORY_SETTINGS_KEY("ENABLE_SIGNAL_HANDLER"),
1009  "Enable signals in timemory_init", false,
1010  strvector_t({ "--timemory-enable-signal-handler" }), -1, 1)
1011 
1013  bool, allow_signal_handler, TIMEMORY_SETTINGS_KEY("ALLOW_SIGNAL_HANDLER"),
1014  "Allow signal handling to be activated", signal_settings::allow(),
1015  strvector_t({ "--timemory-allow-signal-handler" }), -1, 1);
1016 
1018  bool, enable_all_signals, TIMEMORY_SETTINGS_KEY("ENABLE_ALL_SIGNALS"),
1019  "Enable catching all signals", signal_settings::enable_all());
1020 
1022  bool, disable_all_signals, TIMEMORY_SETTINGS_KEY("DISABLE_ALL_SIGNALS"),
1023  "Disable catching any signals", signal_settings::disable_all());
1024 
1026  bool, destructor_report, TIMEMORY_SETTINGS_KEY("DESTRUCTOR_REPORT"),
1027  "Configure default setting for auto_{list,tuple,hybrid} to write to stdout during"
1028  " destruction of the bundle",
1029  false, strvector_t({ "--timemory-destructor-report" }), -1, 1);
1030 
1032  bool, stack_clearing, TIMEMORY_SETTINGS_KEY("STACK_CLEARING"),
1033  "Enable/disable stopping any markers still running during finalization", true,
1034  strvector_t({ "--timemory-stack-clearing" }), -1, 1);
1035 
1037  bool, banner, TIMEMORY_SETTINGS_KEY("BANNER"),
1038  "Notify about tim::manager creation and destruction",
1039  (get_env<bool>(TIMEMORY_SETTINGS_KEY("LIBRARY_CTOR"), false)));
1040 
1042  std::string, TIMEMORY_SETTINGS_KEY("NETWORK_INTERFACE"),
1043  "Default network interface", std::string{},
1044  strvector_t({ "--timemory-network-interface" }), -1, 1);
1045 }
1046 //
1047 //--------------------------------------------------------------------------------------//
1048 //
1050 void
1051 settings::initialize_ert()
1052 {
1053  // PRINT_HERE("%s", "");
1055  TIMEMORY_SETTINGS_KEY("ERT_NUM_THREADS"),
1056  "Number of threads to use when running ERT", 0);
1057 
1059  TIMEMORY_SETTINGS_KEY("ERT_NUM_THREADS_CPU"),
1060  "Number of threads to use when running ERT on CPU",
1061  std::thread::hardware_concurrency());
1062 
1064  uint64_t, ert_num_threads_gpu, TIMEMORY_SETTINGS_KEY("ERT_NUM_THREADS_GPU"),
1065  "Number of threads which launch kernels when running ERT on the GPU", 1);
1066 
1068  uint64_t, ert_num_streams, TIMEMORY_SETTINGS_KEY("ERT_NUM_STREAMS"),
1069  "Number of streams to use when launching kernels in ERT on the GPU", 1);
1070 
1072  uint64_t, ert_grid_size, TIMEMORY_SETTINGS_KEY("ERT_GRID_SIZE"),
1073  "Configure the grid size (number of blocks) for ERT on GPU (0 == auto-compute)",
1074  0);
1075 
1077  uint64_t, ert_block_size, TIMEMORY_SETTINGS_KEY("ERT_BLOCK_SIZE"),
1078  "Configure the block size (number of threads per block) for ERT on GPU", 1024);
1079 
1081  uint64_t, ert_alignment, TIMEMORY_SETTINGS_KEY("ERT_ALIGNMENT"),
1082  "Configure the alignment (in bits) when running ERT on CPU (0 == 8 * sizeof(T))",
1083  0);
1084 
1086  uint64_t, ert_min_working_size, TIMEMORY_SETTINGS_KEY("ERT_MIN_WORKING_SIZE"),
1087  "Configure the minimum working size when running ERT (0 == device specific)", 0);
1088 
1090  uint64_t, ert_min_working_size_cpu,
1091  TIMEMORY_SETTINGS_KEY("ERT_MIN_WORKING_SIZE_CPU"),
1092  "Configure the minimum working size when running ERT on CPU", 64);
1093 
1095  uint64_t, ert_min_working_size_gpu,
1096  TIMEMORY_SETTINGS_KEY("ERT_MIN_WORKING_SIZE_GPU"),
1097  "Configure the minimum working size when running ERT on GPU", 10 * 1000 * 1000);
1098 
1100  uint64_t, ert_max_data_size, TIMEMORY_SETTINGS_KEY("ERT_MAX_DATA_SIZE"),
1101  "Configure the max data size when running ERT on CPU", 0);
1102 
1104  uint64_t, ert_max_data_size_cpu, TIMEMORY_SETTINGS_KEY("ERT_MAX_DATA_SIZE_CPU"),
1105  "Configure the max data size when running ERT on CPU", 0);
1106 
1108  uint64_t, ert_max_data_size_gpu, TIMEMORY_SETTINGS_KEY("ERT_MAX_DATA_SIZE_GPU"),
1109  "Configure the max data size when running ERT on GPU", 500 * 1000 * 1000);
1110 
1112  string_t, ert_skip_ops, TIMEMORY_SETTINGS_KEY("ERT_SKIP_OPS"),
1113  "Skip these number of ops (i.e. ERT_FLOPS) when were set at compile time", "");
1114 }
1115 //
1116 //--------------------------------------------------------------------------------------//
1117 //
1119 void
1120 settings::initialize_dart()
1121 {
1122  // PRINT_HERE("%s", "");
1124  string_t, dart_type, TIMEMORY_SETTINGS_KEY("DART_TYPE"),
1125  "Only echo this measurement type (see also: TIMEMORY_DART_OUTPUT)", "",
1126  strvector_t({ "--timemory-dart-type" }));
1127 
1129  uint64_t, dart_count, TIMEMORY_SETTINGS_KEY("DART_COUNT"),
1130  "Only echo this number of dart tags (see also: TIMEMORY_DART_OUTPUT)", 1,
1131  strvector_t({ "--timemory-dart-count" }), 1);
1132 
1134  bool, dart_label, TIMEMORY_SETTINGS_KEY("DART_LABEL"),
1135  "Echo the category instead of the label (see also: TIMEMORY_DART_OUTPUT)", true,
1136  strvector_t({ "--timemory-dart-label" }), -1, 1);
1137 }
1138 //
1139 //--------------------------------------------------------------------------------------//
1140 //
1142 void
1144 {
1145  // m_data.clear();
1146  if(m_data.empty())
1147  m_data.reserve(160);
1148 
1149  initialize_core();
1150  initialize_components();
1151  initialize_io();
1152  initialize_format();
1153  initialize_parallel();
1154  initialize_tpls();
1155  initialize_roofline();
1156  initialize_miscellaneous();
1157  initialize_ert();
1158  initialize_dart();
1159 }
1160 //
1161 //--------------------------------------------------------------------------------------//
1162 //
1164 bool
1166 {
1167  std::ifstream ifs(inp);
1168  if(!ifs)
1169  {
1170  TIMEMORY_EXCEPTION(string_t("Error reading configuration file: ") + inp)
1171  }
1172  return read(ifs, inp);
1173 }
1174 //
1175 //--------------------------------------------------------------------------------------//
1176 //
1178 bool
1179 settings::read(std::istream& ifs, std::string inp)
1180 {
1181  if(inp.find(".json") != std::string::npos || inp == "json")
1182  {
1184  auto ia = policy_type::get(ifs);
1185  try
1186  {
1187  ia->setNextName("timemory");
1188  ia->startNode();
1189  {
1190  try
1191  {
1192  ia->setNextName("metadata");
1193  ia->startNode();
1194  // settings
1195  (*ia)(cereal::make_nvp("settings", *this));
1196  ia->finishNode();
1197  } catch(...)
1198  {
1199  // settings
1200  (*ia)(cereal::make_nvp("settings", *this));
1201  }
1202  }
1203  ia->finishNode();
1204  } catch(tim::cereal::Exception& e)
1205  {
1206  PRINT_HERE("Exception reading %s :: %s", inp.c_str(), e.what());
1207 # if defined(TIMEMORY_INTERNAL_TESTING)
1209 # endif
1210  return false;
1211  }
1212  return true;
1213  }
1214 # if defined(TIMEMORY_USE_XML)
1215  else if(inp.find(".xml") != std::string::npos || inp == "xml")
1216  {
1218  auto ia = policy_type::get(ifs);
1219  ia->setNextName("timemory");
1220  ia->startNode();
1221  {
1222  try
1223  {
1224  ia->setNextName("metadata");
1225  ia->startNode();
1226  // settings
1227  (*ia)(cereal::make_nvp("settings", *this));
1228  ia->finishNode();
1229  } catch(...)
1230  {
1231  // settings
1232  (*ia)(cereal::make_nvp("settings", *this));
1233  }
1234  }
1235  ia->finishNode();
1236  return true;
1237  }
1238 # endif
1239  else
1240  {
1241  if(inp.empty())
1242  inp = "text";
1243 
1244  std::string line = "";
1245 
1246  auto is_comment = [](const std::string& s) {
1247  if(s.empty())
1248  return true;
1249  for(const auto& itr : s)
1250  {
1251  if(std::isprint(itr))
1252  return (itr == '#') ? true : false;
1253  }
1254  // if there were no printable characters, treat as comment
1255  return true;
1256  };
1257 
1258  int expected = 0;
1259  int valid = 0;
1260  while(ifs)
1261  {
1262  std::getline(ifs, line);
1263  if(!ifs)
1264  continue;
1265  if(is_comment(line))
1266  continue;
1267  ++expected;
1268  // tokenize the string
1269  auto delim = tim::delimit(line, "\n=,; ");
1270  if(delim.size() > 0)
1271  {
1272  string_t key = delim.front();
1273  string_t val = "";
1274  // combine into another string separated by commas
1275  for(size_t i = 1; i < delim.size(); ++i)
1276  val += "," + delim.at(i);
1277  // if there was any fields, remove the leading comma
1278  if(val.length() > 0)
1279  val = val.substr(1);
1280  auto incr = valid;
1281  for(auto itr : *this)
1282  {
1283  if(itr.second->matches(key))
1284  {
1285  if(get_debug() || get_verbose() > 0)
1286  fprintf(stderr, "[timemory::settings]['%s']> %-30s :: %s\n",
1287  inp.c_str(), key.c_str(), val.c_str());
1288  ++valid;
1289  itr.second->parse(val);
1290  }
1291  }
1292 
1293  if(incr == valid)
1294  {
1295  fprintf(stderr,
1296  "[timemory::settings]['%s']> WARNING! Unknown setting "
1297  "ignored: '%s' (value = '%s')\n",
1298  inp.c_str(), key.c_str(), val.c_str());
1299  }
1300  }
1301  }
1302  return (expected == valid);
1303  }
1304  return false;
1305 }
1306 //
1307 //--------------------------------------------------------------------------------------//
1308 //
1311  TIMEMORY_SETTINGS_KEY("SUPPRESS_PARSING"))
1313  TIMEMORY_SETTINGS_KEY("SUPPRESS_CONFIG"))
1326  TIMEMORY_SETTINGS_KEY("FLAMEGRAPH_OUTPUT"))
1332  TIMEMORY_SETTINGS_KEY("COLLAPSE_THREADS"))
1334  TIMEMORY_SETTINGS_KEY("COLLAPSE_PROCESSES"))
1342  TIMEMORY_SETTINGS_KEY("TIMING_PRECISION"))
1345  TIMEMORY_SETTINGS_KEY("TIMING_UNITS"))
1347  TIMEMORY_SETTINGS_KEY("TIMING_SCIENTIFIC"))
1349  TIMEMORY_SETTINGS_KEY("MEMORY_PRECISION"))
1352  TIMEMORY_SETTINGS_KEY("MEMORY_UNITS"))
1354  TIMEMORY_SETTINGS_KEY("MEMORY_SCIENTIFIC"))
1357  TIMEMORY_SETTINGS_KEY("OUTPUT_PREFIX"))
1360  TIMEMORY_SETTINGS_KEY("INPUT_PREFIX"))
1362  TIMEMORY_SETTINGS_KEY("INPUT_EXTENSIONS"))
1367  TIMEMORY_SETTINGS_KEY("MAX_THREAD_BOOKMARKS"))
1370  TIMEMORY_SETTINGS_KEY("STACK_CLEARING"))
1373  TIMEMORY_SETTINGS_KEY("THROTTLE_COUNT"))
1375  TIMEMORY_SETTINGS_KEY("THROTTLE_VALUE"))
1377  TIMEMORY_SETTINGS_KEY("GLOBAL_COMPONENTS"))
1379  TIMEMORY_SETTINGS_KEY("TUPLE_COMPONENTS"))
1381  TIMEMORY_SETTINGS_KEY("LIST_COMPONENTS"))
1383  TIMEMORY_SETTINGS_KEY("OMPT_COMPONENTS"))
1385  TIMEMORY_SETTINGS_KEY("MPIP_COMPONENTS"))
1387  TIMEMORY_SETTINGS_KEY("NCCLP_COMPONENTS"))
1389  TIMEMORY_SETTINGS_KEY("TRACE_COMPONENTS"))
1391  TIMEMORY_SETTINGS_KEY("PROFILER_COMPONENTS"))
1393  TIMEMORY_SETTINGS_KEY("KOKKOS_COMPONENTS"))
1399  TIMEMORY_SETTINGS_KEY("MPI_THREAD_TYPE"))
1402  TIMEMORY_SETTINGS_KEY("UPCXX_FINALIZE"))
1404  TIMEMORY_SETTINGS_KEY("PAPI_THREADING"))
1406  TIMEMORY_SETTINGS_KEY("PAPI_MULTIPLEXING"))
1408  TIMEMORY_SETTINGS_KEY("PAPI_FAIL_ON_ERROR"))
1414  TIMEMORY_SETTINGS_KEY("CUDA_EVENT_BATCH_SIZE"))
1416  TIMEMORY_SETTINGS_KEY("NVTX_MARKER_DEVICE_SYNC"))
1418  TIMEMORY_SETTINGS_KEY("CUPTI_ACTIVITY_LEVEL"))
1420  TIMEMORY_SETTINGS_KEY("CUPTI_ACTIVITY_KINDS"))
1422  TIMEMORY_SETTINGS_KEY("CUPTI_EVENTS"))
1424  TIMEMORY_SETTINGS_KEY("CUPTI_METRICS"))
1427  TIMEMORY_SETTINGS_KEY("ROOFLINE_MODE"))
1429  TIMEMORY_SETTINGS_KEY("ROOFLINE_MODE_CPU"))
1431  TIMEMORY_SETTINGS_KEY("ROOFLINE_MODE_GPU"))
1433  TIMEMORY_SETTINGS_KEY("ROOFLINE_EVENTS_CPU"))
1435  TIMEMORY_SETTINGS_KEY("ROOFLINE_EVENTS_GPU"))
1437  TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS"))
1439  TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS_CPU"))
1441  TIMEMORY_SETTINGS_KEY("ROOFLINE_TYPE_LABELS_GPU"))
1443  TIMEMORY_SETTINGS_KEY("INSTRUCTION_ROOFLINE"))
1445  TIMEMORY_SETTINGS_KEY("ERT_NUM_THREADS"))
1447  TIMEMORY_SETTINGS_KEY("ERT_NUM_THREADS_CPU"))
1449  TIMEMORY_SETTINGS_KEY("ERT_NUM_THREADS_GPU"))
1451  TIMEMORY_SETTINGS_KEY("ERT_NUM_STREAMS"))
1453  TIMEMORY_SETTINGS_KEY("ERT_GRID_SIZE"))
1455  TIMEMORY_SETTINGS_KEY("ERT_BLOCK_SIZE"))
1457  TIMEMORY_SETTINGS_KEY("ERT_ALIGNMENT"))
1459  TIMEMORY_SETTINGS_KEY("ERT_MIN_WORKING_SIZE"))
1461  TIMEMORY_SETTINGS_KEY("ERT_MIN_WORKING_SIZE_CPU"))
1463  TIMEMORY_SETTINGS_KEY("ERT_MIN_WORKING_SIZE_GPU"))
1465  TIMEMORY_SETTINGS_KEY("ERT_MAX_DATA_SIZE"))
1467  TIMEMORY_SETTINGS_KEY("ERT_MAX_DATA_SIZE_CPU"))
1469  TIMEMORY_SETTINGS_KEY("ERT_MAX_DATA_SIZE_GPU"))
1471  TIMEMORY_SETTINGS_KEY("ERT_SKIP_OPS"))
1476  TIMEMORY_SETTINGS_KEY("DESTRUCTOR_REPORT"))
1478 // stream
1480  TIMEMORY_SETTINGS_KEY("SEPARATOR_FREQ"))
1481 // signals
1483  TIMEMORY_SETTINGS_KEY("ENABLE_SIGNAL_HANDLER"))
1485  TIMEMORY_SETTINGS_KEY("ALLOW_SIGNAL_HANDLER"))
1487  TIMEMORY_SETTINGS_KEY("ENABLE_ALL_SIGNALS"))
1489  TIMEMORY_SETTINGS_KEY("DISABLE_ALL_SIGNALS"))
1490 // miscellaneous ref
1493  TIMEMORY_SETTINGS_KEY("TIMELINE_PROFILE"))
1494 TIMEMORY_SETTINGS_REFERENCE_DEF(process::id_t, target_pid,
1495  TIMEMORY_SETTINGS_KEY("TARGET_PID"))
1496 //
1497 //--------------------------------------------------------------------------------------//
1498 //
1499 } // namespace tim
1500 
1501 # include "timemory/tpls/cereal/archives.hpp"
1502 
1504 
1505 #endif // TIMEMORY_SETTINGS_SETTINGS_CPP_
1506 
1507 // #include "timemory/settings/extern.hpp"
#define TIMEMORY_DEFAULT_ENABLED
Definition: api.hpp:200
#define TIMEMORY_DEFAULT_PLOTTING
Definition: api.hpp:196
#define TIMEMORY_PYTHON_PLOTTER
Definition: api.hpp:204
static bool & enable_all()
Definition: signals.hpp:256
static bool & disable_all()
Definition: signals.hpp:264
std::string string_t
Definition: library.cpp:56
const string_t const string_t & _dir
Definition: definition.hpp:52
input_type & get_fields()
Definition: types.hpp:401
Definition: kokkosp.cpp:38
dart_count
Definition: settings.cpp:1364
cupti_events
Definition: settings.cpp:1421
timing_precision
Definition: settings.cpp:1341
roofline_mode
Definition: settings.cpp:1426
max_depth
Definition: settings.cpp:1335
diff_output
Definition: settings.cpp:1324
input_path
Definition: settings.cpp:1358
mpip_components
Definition: settings.cpp:1384
cpu_affinity
Definition: settings.cpp:1368
TIMEMORY_SETTINGS_MEMBER_DEF(string_t, config_file, TIMEMORY_SETTINGS_KEY("CONFIG_FILE")) TIMEMORY_SETTINGS_MEMBER_DEF(bool
input_prefix
Definition: settings.cpp:1359
papi_multiplexing
Definition: settings.cpp:1405
upcxx_finalize
Definition: settings.cpp:1401
ert_num_streams
Definition: settings.cpp:1450
char const std::string & _prefix
Definition: definition.hpp:59
mpi_thread_type
Definition: settings.cpp:1398
ert_min_working_size
Definition: settings.cpp:1458
separator_frequency
Definition: settings.cpp:1479
enable_signal_handler
Definition: settings.cpp:1482
cpu_roofline_mode
Definition: settings.cpp:1428
ert_grid_size
Definition: settings.cpp:1452
throttle_value
Definition: settings.cpp:1374
flat_profile
Definition: settings.cpp:1491
max_thread_bookmarks
Definition: settings.cpp:1366
papi_events
Definition: settings.cpp:1410
gpu_roofline_events
Definition: settings.cpp:1434
ert_max_data_size
Definition: settings.cpp:1464
TIMEMORY_SETTINGS_INLINE std::string get_local_datetime(const char *dt_format, std::time_t *dt_curr)
Definition: settings.cpp:132
ert_min_working_size_cpu
Definition: settings.cpp:1460
time_format
Definition: settings.cpp:1336
ert_num_threads_gpu
Definition: settings.cpp:1448
node_count
Definition: settings.cpp:1474
memory_scientific
Definition: settings.cpp:1353
add_secondary
Definition: settings.cpp:1371
tree_output
Definition: settings.cpp:1320
ert_max_data_size_gpu
Definition: settings.cpp:1468
profiler_components
Definition: settings.cpp:1390
papi_overflow
Definition: settings.cpp:1412
std::string string_t
Definition: utility.hpp:105
text_output
Definition: settings.cpp:1318
json_output
Definition: settings.cpp:1319
upcxx_init
Definition: settings.cpp:1400
list_components
Definition: settings.cpp:1380
timing_width
Definition: settings.cpp:1343
cupti_activity_kinds
Definition: settings.cpp:1419
collapse_threads
Definition: settings.cpp:1331
allow_signal_handler
Definition: settings.cpp:1484
ert_alignment
Definition: settings.cpp:1456
cpu_roofline_events
Definition: settings.cpp:1432
memory_units
Definition: settings.cpp:1351
instruction_roofline
Definition: settings.cpp:1442
suppress_parsing
Definition: settings.cpp:1310
papi_attach
Definition: settings.cpp:1411
scientific
Definition: settings.cpp:1340
tuple_components
Definition: settings.cpp:1378
ert_min_working_size_gpu
Definition: settings.cpp:1462
output_prefix
Definition: settings.cpp:1356
craypat_categories
Definition: settings.cpp:1472
char ** argv
Definition: definition.hpp:59
timing_units
Definition: settings.cpp:1344
suppress_config
Definition: settings.cpp:1312
ompt_components
Definition: settings.cpp:1382
ert_block_size
Definition: settings.cpp:1454
cupti_activity_level
Definition: settings.cpp:1417
char argparse::argument_parser tim::settings * _settings
Definition: definition.hpp:277
ert_num_threads_cpu
Definition: settings.cpp:1446
papi_threading
Definition: settings.cpp:1403
file_output
Definition: settings.cpp:1317
disable_all_signals
Definition: settings.cpp:1488
cupti_metrics
Definition: settings.cpp:1423
time_output
Definition: settings.cpp:1322
ert_max_data_size_cpu
Definition: settings.cpp:1466
enable_all_signals
Definition: settings.cpp:1486
tim::mpl::apply< std::string > string
Definition: macros.hpp:52
size_t pos
Definition: definition.hpp:129
cupti_device
Definition: settings.cpp:1425
dart_label
Definition: settings.cpp:1365
roofline_type_labels_gpu
Definition: settings.cpp:1440
ncclp_components
Definition: settings.cpp:1386
dart_output
Definition: settings.cpp:1321
ert_num_threads
Definition: settings.cpp:1444
python_exe
Definition: settings.cpp:1477
output_path
Definition: settings.cpp:1355
roofline_type_labels
Definition: settings.cpp:1436
input_extensions
Definition: settings.cpp:1361
cuda_event_batch_size
Definition: settings.cpp:1413
auto_output
Definition: settings.cpp:1315
mpi_init
Definition: settings.cpp:1395
collapse_processes
Definition: settings.cpp:1333
precision
Definition: settings.cpp:1337
memory_precision
Definition: settings.cpp:1348
stack_clearing
Definition: settings.cpp:1369
TIMEMORY_SETTINGS_KEY("SUPPRESS_PARSING")) TIMEMORY_SETTINGS_MEMBER_DEF(bool
int makedir(std::string _dir, int umask)
Definition: utility.cpp:66
papi_fail_on_error
Definition: settings.cpp:1407
papi_quiet
Definition: settings.cpp:1409
auto get(const auto_bundle< Tag, Types... > &_obj)
roofline_type_labels_cpu
Definition: settings.cpp:1438
cout_output
Definition: settings.cpp:1316
ctest_notes
Definition: settings.cpp:1327
destructor_report
Definition: settings.cpp:1475
throttle_count
Definition: settings.cpp:1372
max_width
Definition: settings.cpp:1339
mpi_finalize
Definition: settings.cpp:1396
gpu_roofline_mode
Definition: settings.cpp:1430
timeline_profile
Definition: settings.cpp:1492
memory_width
Definition: settings.cpp:1350
dart_type
Definition: settings.cpp:1363
flamegraph_output
Definition: settings.cpp:1325
nvtx_marker_device_sync
Definition: settings.cpp:1415
timing_scientific
Definition: settings.cpp:1346
trace_components
Definition: settings.cpp:1388
global_components
Definition: settings.cpp:1376
components
Definition: settings.cpp:1394
ert_skip_ops
Definition: settings.cpp:1470
kokkos_components
Definition: settings.cpp:1392
plot_output
Definition: settings.cpp:1323
ContainerT delimit(const std::string &line, const std::string &delimiters="\"',;: ", PredicateT &&predicate=[](const std::string &s) -> std::string { return s;})
Definition: utility.hpp:666
mpi_thread
Definition: settings.cpp:1397
char ** environ
#define TIMEMORY_SETTINGS_MEMBER_IMPL(TYPE, FUNC, ENV_VAR, DESC, INIT)
Definition: macros.hpp:147
#define TIMEMORY_SETTINGS_HIDDEN_MEMBER_ARG_IMPL(TYPE, ENV_VAR, DESC, INIT,...)
Definition: macros.hpp:187
#define TIMEMORY_SETTINGS_INLINE
Definition: macros.hpp:51
#define TIMEMORY_SETTINGS_MEMBER_ARG_IMPL(TYPE, FUNC, ENV_VAR, DESC, INIT,...)
Definition: macros.hpp:173
#define TIMEMORY_SETTINGS_EXTERN_TEMPLATE(...)
Definition: macros.hpp:302
#define TIMEMORY_SETTINGS_REFERENCE_ARG_IMPL(TYPE, FUNC, ENV_VAR, DESC, INIT,...)
Definition: macros.hpp:213
#define TIMEMORY_SETTINGS_REFERENCE_IMPL(TYPE, FUNC, ENV_VAR, DESC, INIT)
Definition: macros.hpp:200
#define TIMEMORY_SETTINGS_REFERENCE_DEF(TYPE, FUNC, ENV_VAR)
Definition: macros.hpp:121
Declare the settings types.
arg_result get(size_t _idx, Tp &_value)
Definition: argparse.hpp:675
Provides a static get() function which returns a shared pointer to an instance of the given archive f...
Definition: policy.hpp:92
bool read(const string_t &)
read a configuration file
Definition: settings.cpp:1165
static pointer_t shared_instance()
static void store_command_line(int argc, char **argv)
Definition: settings.cpp:222
strvector_t & get_environment()
Definition: settings.hpp:237
Tp get(Sp &&_key, bool _exact=true)
Definition: settings.hpp:621
static std::time_t * get_launch_time(Tag={})
Definition: settings.hpp:420
static string_t compose_output_filename(const string_t &_tag, string_t _ext, bool _mpi_init=false, int32_t _mpi_rank=-1, bool fake=false, std::string _explicit="")
Definition: settings.cpp:234
static void serialize_settings(Archive &)
Definition: settings.cpp:51
void initialize()
Definition: settings.cpp:1143
static string_t toupper(string_t str)
Definition: settings.cpp:158
static string_t get_global_input_prefix()
Definition: settings.cpp:169
static string_t compose_input_filename(const string_t &_tag, string_t _ext, bool _mpi_init=false, int32_t _mpi_rank=-1, std::string _explicit="")
Definition: settings.cpp:286
std::unordered_map< string_view_t, value_type > data_type
Definition: settings.hpp:82
static string_t get_global_output_prefix(bool fake=false)
Definition: settings.cpp:181
settings & operator=(const settings &)
Definition: settings.cpp:407
static void parse(settings *=instance< TIMEMORY_API >())
Definition: settings.cpp:340
static strvector_t get_global_environment()
Definition: settings.cpp:112
static settings * instance()
Definition: settings.hpp:502
std::vector< std::string > strvector_t
Definition: settings.hpp:80
static string_t tolower(string_t str)
Definition: settings.cpp:147
The declaration for the types for utility without definitions.
#define TIMEMORY_CONDITIONAL_DEMANGLED_BACKTRACE(CONDITION, DEPTH)
Definition: macros.hpp:197
#define PRINT_HERE(...)
Definition: macros.hpp:147
#define TIMEMORY_EXCEPTION(...)
Definition: types.hpp:137
#define TIMEMORY_JOIN(delim,...)
Definition: macros.hpp:89