Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
PerfGraphRegistry.h
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 #pragma once
11 
12 #include "GeneralRegistry.h"
13 #include "MooseTypes.h"
14 
15 #include <mutex>
16 
17 // Forward Declarations
18 class PerfGraph;
19 class PerfGraphLivePrint;
20 class PerfNode;
21 void dataStore(std::ostream &, PerfGraph &, void *);
22 
23 namespace moose
24 {
25 namespace internal
26 {
27 class PerfGraphRegistry;
28 class PerfGraphSectionInfo;
29 }
30 }
31 
32 namespace moose
33 {
34 namespace internal
35 {
36 
44 {
45 public:
46  PerfGraphSectionInfo() = default;
48  const std::string & name,
49  const unsigned int level,
50  const std::string & live_message,
51  const bool print_dots)
52  : _id(id), _name(name), _level(level), _live_message(live_message), _print_dots(print_dots)
53  {
54  }
55 
58 
60  std::string _name;
61 
63  unsigned int _level;
64 
66  std::string _live_message;
67 
70 };
71 
76 
80 class PerfGraphRegistry : private GeneralRegistry<std::string, PerfGraphSectionInfo>
81 {
82 public:
90  PerfID registerSection(const std::string & section_name, const unsigned int level);
91 
101  PerfID registerSection(const std::string & section_name,
102  const unsigned int level,
103  const std::string & live_message,
104  const bool print_dots = true);
105 
111  PerfID sectionID(const std::string & section_name) const { return id(section_name); }
112 
118  const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
119  {
120  return item(section_id);
121  }
122 
128  bool sectionExists(const std::string & section_name) const { return keyExists(section_name); }
129 
135  bool sectionExists(const PerfID section_id) const { return idExists(section_id); }
136 
140  std::size_t numSections() const { return size(); }
141 
142 private:
144 
148  PerfID actuallyRegisterSection(const std::string & section_name,
149  const unsigned int level,
150  const std::string & live_message,
151  const bool print_dots = true);
152 
165  const PerfGraphSectionInfo & readSectionInfo(PerfID section_id) const
166  {
167  return itemNonLocking(section_id);
168  };
169 
173  friend PerfGraph;
174  // For accessing _id_to_section_info when storing the PerfGraph
175  friend void ::dataStore(std::ostream &, PerfGraph &, void *);
176 };
177 
178 }
179 }
180 
181 void dataStore(std::ostream & stream, moose::internal::PerfGraphSectionInfo & info, void * context);
182 void dataLoad(std::istream & stream, moose::internal::PerfGraphSectionInfo & info, void * context);
std::string name(const ElemQuality q)
The place where all timed sections will be stored.
std::string _live_message
Message to print while the section is running.
bool sectionExists(const std::string &section_name) const
Whether or not a section with that name has been registered The name of the section.
MPI_Info info
const PerfGraphSectionInfo & itemNonLocking(const std::size_t id) const
void dataLoad(std::istream &stream, moose::internal::PerfGraphSectionInfo &info, void *context)
unsigned int _level
Print level (verbosity level)
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
std::size_t id(const std::string &key) const
friend PerfGraphRegistry & getPerfGraphRegistry()
So it can be constructed.
const PerfGraphSectionInfo & item(const std::size_t id) const
friend PerfGraph
This is only here so that PerfGraph can access readSectionInfo.
This is effectively a functor that runs on a separate thread and watches the state of the call stack ...
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
Given a PerfID return the PerfGraphSectionInfo The ID.
bool _print_dots
Whether or not to print dots while this section runs.
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
bool sectionExists(const PerfID section_id) const
Whether or not a section with that id has been registered The ID.
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.
PerfGraphSectionInfo(const PerfID id, const std::string &name, const unsigned int level, const std::string &live_message, const bool print_dots)
bool keyExists(const std::string &key) const
void dataStore(std::ostream &, PerfGraph &, void *)
Definition: PerfGraph.C:490
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode...
Definition: PerfGraph.h:43
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.
const PerfGraphSectionInfo & readSectionInfo(PerfID section_id) const
Special accessor just for PerfGraph so that no locking is needed in PerfGraph.
A node in the PerfGraph.
Definition: PerfNode.h:24