https://mooseframework.inl.gov
PerfGraphRegistry.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "PerfGraphRegistry.h"
11 
12 #include "DataIO.h"
13 
14 namespace moose
15 {
16 namespace internal
17 {
18 
19 PerfGraphRegistry &
21 {
22  // In C++11 this is even thread safe! (Lookup "Static Initializers")
23  static PerfGraphRegistry perf_graph_registry_singleton;
24 
25  return perf_graph_registry_singleton;
26 }
27 
29  : GeneralRegistry<std::string, PerfGraphSectionInfo>("PerfGraphRegistry")
30 {
31 }
32 
33 unsigned int
34 PerfGraphRegistry::registerSection(const std::string & section_name, unsigned int level)
35 {
36  return actuallyRegisterSection(section_name, level, "", false);
37 }
38 
39 PerfID
40 PerfGraphRegistry::registerSection(const std::string & section_name,
41  unsigned int level,
42  const std::string & live_message,
43  const bool print_dots)
44 {
45  if (section_name == "")
46  mooseError("Section name not provided when registering timed section!");
47 
48  if (live_message == "")
49  mooseError("Live message not provided when registering timed section!");
50 
51  return actuallyRegisterSection(section_name, level, live_message, print_dots);
52 }
53 
54 PerfID
55 PerfGraphRegistry::actuallyRegisterSection(const std::string & section_name,
56  unsigned int level,
57  const std::string & live_message,
58  const bool print_dots)
59 {
60  const auto create_item = [&section_name, &level, &live_message, &print_dots](const std::size_t id)
61  { return PerfGraphSectionInfo(id, section_name, level, live_message, print_dots); };
62  return registerItem(section_name, create_item);
63 }
64 
65 }
66 }
67 
68 void
69 dataStore(std::ostream & stream, moose::internal::PerfGraphSectionInfo & info, void * context)
70 {
71  dataStore(stream, info._id, context);
72  dataStore(stream, info._name, context);
73  dataStore(stream, info._level, context);
74  dataStore(stream, info._live_message, context);
75  dataStore(stream, info._print_dots, context);
76 }
77 
78 void
79 dataLoad(std::istream & stream, moose::internal::PerfGraphSectionInfo & info, void * context)
80 {
81  dataLoad(stream, info._id, context);
82  dataLoad(stream, info._name, context);
83  dataLoad(stream, info._level, context);
84  dataLoad(stream, info._live_message, context);
85  dataLoad(stream, info._print_dots, context);
86 }
The place where all timed sections will be stored.
MPI_Info info
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
void dataStore(std::ostream &stream, moose::internal::PerfGraphSectionInfo &info, void *context)
Used to hold metadata about the registered sections Note: this is a class instead of a struct because...
unsigned int PerfID
Definition: MooseTypes.h:212
void dataLoad(std::istream &stream, moose::internal::PerfGraphSectionInfo &info, void *context)
std::size_t id(const std::string &key) const
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::size_t registerItem(const std::string &key, CreateItem &create_item)
Registers an item with key key if said key does not exist.
PerfID actuallyRegisterSection(const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true)
The internal function that actually carries out the registration.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.