www.mooseframework.org
PerformanceData.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "PerformanceData.h"
11 
12 #include "FEProblem.h"
13 #include "SubProblem.h"
14 
15 registerMooseObjectReplaced("MooseApp", PerformanceData, "02/01/2019 00:00", PerfGraphData);
16 
17 template <>
20 {
22 
23  MooseEnum column_options("n_calls total_time average_time total_time_with_sub "
24  "average_time_with_sub percent_of_active_time "
25  "percent_of_active_time_with_sub",
26  "total_time_with_sub");
27  params.addParam<MooseEnum>(
28  "column", column_options, "The column you want the value of (Default: total_time_with_sub).");
29 
30  MooseEnum common_categories("Application Execution Output Setup Utility", "Execution", true);
31  params.addParam<MooseEnum>("category", common_categories, "The category for the event");
32 
33  MooseEnum common_events("ACTIVE ALIVE solve() compute_residual() compute_jacobian()", "", true);
35  "event",
36  common_events,
37  "The name or \"label\" of the event. Must match event name exactly "
38  "including parenthesis if applicable. (\"ALIVE\" and \"ACTIVE\" are "
39  "also valid events, category and column are ignored for these "
40  "cases).");
41 
42  params.addClassDescription("Provides programmatic access to Performance Log Data");
43  return params;
44 }
45 
47  : GeneralPostprocessor(parameters),
48  _column(getParam<MooseEnum>("column").getEnum<PerfLogCols>()),
49  _category(getParam<MooseEnum>("category")),
50  _event(getParam<MooseEnum>("event"))
51 {
52  // Notify the OutputWarehouse that logging has been requested
54 }
55 
56 Real
58 {
59  if (_event == "ALIVE")
60  return Moose::perf_log.get_elapsed_time();
61 
62  Real total_time = Moose::perf_log.get_active_time();
63  if (_event == "ACTIVE")
64  return total_time;
65 
66  PerfData perf_data = Moose::perf_log.get_perf_data(_event, _category);
67  if (perf_data.count == 0)
68  return 0.0;
69 
70  switch (_column)
71  {
72  case N_CALLS:
73  return perf_data.count;
74  case TOTAL_TIME:
75  return perf_data.tot_time;
76  case AVERAGE_TIME:
77  return perf_data.tot_time / static_cast<double>(perf_data.count);
79  return perf_data.tot_time_incl_sub;
81  return perf_data.tot_time_incl_sub / static_cast<double>(perf_data.count);
83  return (total_time != 0.) ? perf_data.tot_time / total_time * 100. : 0.;
85  return (total_time != 0.) ? perf_data.tot_time_incl_sub / total_time * 100. : 0.;
86  default:
87  mooseError("Invalid column!");
88  }
89 
90  return 0;
91 }
void setLoggingRequested()
Sets a Boolean indicating that at least one object is requesting performance logging in this applicat...
MooseEnum _category
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< GeneralPostprocessor >()
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
registerMooseObjectReplaced("MooseApp", PerformanceData, "02/01/2019 00:00", PerfGraphData)
virtual Real getValue() override
This will return the elapsed wall time.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
PerfLog perf_log
Perflog to be used by applications.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
InputParameters validParams< PerformanceData >()
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:177
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
PerformanceData(const InputParameters &parameters)
PerfLogCols _column
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:1055