https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
18class PerfGraph;
20class PerfNode;
21void dataStore(std::ostream &, PerfGraph &, void *);
22
23namespace moose
24{
25namespace internal
26{
27class PerfGraphRegistry;
28class PerfGraphSectionInfo;
29}
30}
31
32namespace moose
33{
34namespace internal
35{
36
44{
45public:
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
80class PerfGraphRegistry : private GeneralRegistry<std::string, PerfGraphSectionInfo>
81{
82public:
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
142private:
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
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
181void dataStore(std::ostream & stream, moose::internal::PerfGraphSectionInfo & info, void * context);
182void dataLoad(std::istream & stream, moose::internal::PerfGraphSectionInfo & info, void * context);
unsigned int PerfID
Definition MooseTypes.h:240
void dataLoad(std::istream &stream, moose::internal::PerfGraphSectionInfo &info, void *context)
void dataStore(std::ostream &, PerfGraph &, void *)
Definition PerfGraph.C:511
const PerfGraphSectionInfo & itemNonLocking(const std::size_t id) const
std::size_t id(const std::string &key) const
const PerfGraphSectionInfo & item(const std::size_t id) const
This is effectively a functor that runs on a separate thread and watches the state of the call stack ...
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode.
Definition PerfGraph.h:44
A node in the PerfGraph.
Definition PerfNode.h:26
The place where all timed sections will be stored.
const PerfGraphSectionInfo & readSectionInfo(PerfID section_id) const
Special accessor just for PerfGraph so that no locking is needed in PerfGraph.
friend PerfGraph
This is only here so that PerfGraph can access readSectionInfo.
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID @section_name The name of the section.
friend PerfGraphRegistry & getPerfGraphRegistry()
So it can be constructed.
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
bool sectionExists(const PerfID section_id) const
Whether or not a section with that id has been registered @section_id 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.
const PerfGraphSectionInfo & sectionInfo(const PerfID section_id) const
Given a PerfID return the PerfGraphSectionInfo @section_id The ID.
bool sectionExists(const std::string &section_name) const
Whether or not a section with that name has been registered @section_name The name of the section.
Used to hold metadata about the registered sections Note: this is a class instead of a struct because...
unsigned int _level
Print level (verbosity level)
std::string _live_message
Message to print while the section is running.
bool _print_dots
Whether or not to print dots while this section runs.
PerfGraphSectionInfo(const PerfID id, const std::string &name, const unsigned int level, const std::string &live_message, const bool print_dots)
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.