Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ProfilerMessenger Class Reference

#include <G4ProfilerMessenger.hh>

+ Inheritance diagram for G4ProfilerMessenger:

Public Member Functions

 G4ProfilerMessenger ()
 
 ~G4ProfilerMessenger () override
 
 G4ProfilerMessenger (const G4ProfilerMessenger &)=delete
 
G4ProfilerMessengeroperator= (const G4ProfilerMessenger &)=delete
 
 G4ProfilerMessenger (G4ProfilerMessenger &&)=default
 
G4ProfilerMessengeroperator= (G4ProfilerMessenger &&)=default
 
void SetNewValue (G4UIcommand *, G4String) override
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()=default
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String LtoS (G4long l)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (const G4String &s)
 
G4long StoL (const G4String &s)
 
G4double StoD (const G4String &s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 

Detailed Description

Definition at line 47 of file G4ProfilerMessenger.hh.

Constructor & Destructor Documentation

◆ G4ProfilerMessenger() [1/3]

G4ProfilerMessenger::G4ProfilerMessenger ( )

Definition at line 43 of file G4ProfilerMessenger.cc.

44{
45 profileDirectory = new G4UIdirectory("/profiler/");
46 profileDirectory->SetGuidance("Profiler controls.");
47
48 profileOutputDirectory = new G4UIdirectory("/profiler/output/");
49 profileOutputDirectory->SetGuidance("Control the output modes of the profiler.");
50
51#define CREATE_DIR(IDX, DIR, GUIDANCE) \
52 profileTypeDirs.at(IDX) = new G4UIdirectory(DIR); \
53 profileTypeDirs.at(IDX)->SetGuidance(GUIDANCE)
54
55 CREATE_DIR(Type::Run, "/profiler/run/", "Profiler controls at the G4Run level");
56 CREATE_DIR(Type::Event, "/profiler/event/", "Profiler controls at the G4Event level");
57 CREATE_DIR(Type::Track, "/profiler/track/", "Profiler controls at the G4Track level");
58 CREATE_DIR(Type::Step, "/profiler/step/", "Profiler controls at the G4Step level");
59 CREATE_DIR(Type::User, "/profiler/user/", "Profiler controls within user code");
60
61#define SET_ENABLED_CMD(IDX, CMD, CMDLINE, DEFAULT, GUIDANCE) \
62 profileEnableCmds.at(IDX).second = CMDLINE; \
63 profileEnableCmds.at(IDX).first = new G4UIcmdWithABool(CMD, this); \
64 profileEnableCmds.at(IDX).first->SetDefaultValue(DEFAULT); \
65 profileEnableCmds.at(IDX).first->SetGuidance(GUIDANCE); \
66 profileEnableCmds.at(IDX).first->AvailableForStates(G4State_PreInit, G4State_Idle)
67
68 SET_ENABLED_CMD(Type::Run, "/profiler/run/enable", "run", true, "Record metrics for each G4Run");
69 SET_ENABLED_CMD(Type::Event, "/profiler/event/enable", "event", true,
70 "Record metrics for each G4Event");
71 SET_ENABLED_CMD(Type::Track, "/profiler/track/enable", "track", false,
72 "Record metrics for each G4Track");
73 SET_ENABLED_CMD(Type::Step, "/profiler/step/enable", "step", false,
74 "Record metrics for each G4Step");
75 SET_ENABLED_CMD(Type::User, "/profiler/user/enable", "user", true,
76 "Record metrics for user specified profiling instances");
77
78#define SET_COMPONENTS_CMD(IDX, CMD, CMDLINE, DEFAULTS, GUIDANCE) \
79 profileCompCmds.at(IDX).second = CMDLINE; \
80 profileCompCmds.at(IDX).first = new G4UIcmdWithAString(CMD, this); \
81 profileCompCmds.at(IDX).first->SetDefaultValue(DEFAULTS); \
82 profileCompCmds.at(IDX).first->SetGuidance(GUIDANCE); \
83 profileCompCmds.at(IDX).first->AvailableForStates(G4State_PreInit, G4State_Idle)
84
85 G4String comps = "wall_clock, cpu_clock, cpu_util, peak_rss";
86
87 SET_COMPONENTS_CMD(Type::Run, "/profiler/run/components", "--run-components", comps,
88 "Measurment types to record for each G4Run (see `timemory-avail -s`)");
89 SET_COMPONENTS_CMD(Type::Event, "/profiler/event/components", "--event-components", comps,
90 "Measurment types to record for each G4Event (see `timemory-avail -s`)");
91 SET_COMPONENTS_CMD(Type::Track, "/profiler/track/components", "--track-components", comps,
92 "Measurment types to record for each G4Track (see `timemory-avail -s`)");
93 SET_COMPONENTS_CMD(Type::Step, "/profiler/step/components", "--step-components", comps,
94 "Measurment types to record for each G4Step (see `timemory-avail -s`)");
95 SET_COMPONENTS_CMD(Type::User, "/profiler/user/components", "--user-components", comps,
96 "Measurment types to record for user specified profiling "
97 "instances (see `timemory-avail -s`)");
98
99#define SET_OUTPUT_CMD(CMD, CMDLINE, DEFAULT, GUIDANCE) \
100 profileGeneralCmds.push_back({new G4UIcmdWithABool(CMD, this), CMDLINE}); \
101 profileGeneralCmds.back().first->SetDefaultValue(DEFAULT); \
102 profileGeneralCmds.back().first->SetGuidance(GUIDANCE); \
103 profileGeneralCmds.back().first->AvailableForStates(G4State_PreInit, G4State_Idle)
104
105 SET_OUTPUT_CMD("/profiler/output/dart", "--dart", false,
106 "Enabled Dart output (CTest/CDash data tracking)");
107 SET_OUTPUT_CMD("/profiler/output/json", "--json", true, "Enabled JSON output");
108 SET_OUTPUT_CMD("/profiler/output/text", "--text", true, "Enabled text output");
109 SET_OUTPUT_CMD("/profiler/output/cout", "--cout", false, "Enabled output to console");
110 SET_OUTPUT_CMD("/profiler/output/plot", "--plot", false, "Enabled plotting JSON output");
111
112 SET_OUTPUT_CMD("/profiler/tree", "--tree", true,
113 "Display the results as a call-stack hierarchy.");
114 SET_OUTPUT_CMD("/profiler/flat", "--flat", false, "Display the results as a flat call-stack");
115 SET_OUTPUT_CMD("/profiler/timeline", "--timeline", false,
116 "Do not merge duplicate entries at the same call-stack "
117 "position. May be combined with tree or flat profiles.");
118 SET_OUTPUT_CMD("/profiler/per_thread", "--per-thread", false,
119 "Display the results for each individual thread (default: aggregation)");
120 SET_OUTPUT_CMD("/profiler/per_event", "--per-event", false,
121 "Display the results for each individual G4event (default: aggregation)");
122}
#define SET_ENABLED_CMD(IDX, CMD, CMDLINE, DEFAULT, GUIDANCE)
#define SET_COMPONENTS_CMD(IDX, CMD, CMDLINE, DEFAULTS, GUIDANCE)
#define SET_OUTPUT_CMD(CMD, CMDLINE, DEFAULT, GUIDANCE)
#define CREATE_DIR(IDX, DIR, GUIDANCE)
void SetGuidance(const char *aGuidance)

◆ ~G4ProfilerMessenger()

G4ProfilerMessenger::~G4ProfilerMessenger ( )
override

Definition at line 126 of file G4ProfilerMessenger.cc.

127{
128 delete profileDirectory;
129 delete profileOutputDirectory;
130 for (auto& itr : profileTypeDirs) {
131 delete itr;
132 }
133 for (auto& itr : profileEnableCmds) {
134 delete itr.first;
135 }
136 for (auto& itr : profileGeneralCmds) {
137 delete itr.first;
138 }
139 for (auto& itr : profileCompCmds) {
140 delete itr.first;
141 }
142}

◆ G4ProfilerMessenger() [2/3]

G4ProfilerMessenger::G4ProfilerMessenger ( const G4ProfilerMessenger & )
delete

◆ G4ProfilerMessenger() [3/3]

G4ProfilerMessenger::G4ProfilerMessenger ( G4ProfilerMessenger && )
default

Member Function Documentation

◆ operator=() [1/2]

G4ProfilerMessenger & G4ProfilerMessenger::operator= ( const G4ProfilerMessenger & )
delete

◆ operator=() [2/2]

G4ProfilerMessenger & G4ProfilerMessenger::operator= ( G4ProfilerMessenger && )
default

◆ SetNewValue()

void G4ProfilerMessenger::SetNewValue ( G4UIcommand * command,
G4String value )
overridevirtual

Reimplemented from G4UImessenger.

Definition at line 146 of file G4ProfilerMessenger.cc.

147{
148 for (size_t i = 0; i < static_cast<size_t>(G4ProfileType::TypeEnd); ++i) {
149 G4UIcmdWithABool* ui = profileEnableCmds.at(i).first;
150 if (command == ui) {
152 return;
153 }
154 }
155
156 // pass the commands to the timemory argparser
157 std::vector<std::string> command_line = {"G4ProfilerMessenger"};
158
159 for (auto& itr : profileGeneralCmds) {
160 G4UIcmdWithABool* ui = itr.first;
161 if (command == ui) {
162 command_line.push_back(itr.second.c_str());
163 command_line.push_back(value);
164 break;
165 }
166 }
167
168 for (auto& itr : profileCompCmds) {
169 G4UIcmdWithAString* ui = itr.first;
170 if (command == ui) {
171 command_line.push_back(itr.second);
172#if defined(GEANT4_USE_TIMEMORY)
173 for (auto vitr : tim::delimit(value, ", ;"))
174 command_line.push_back(vitr);
175#endif
176 break;
177 }
178 }
179
180 if (command_line.size() > 1) {
181 G4Profiler::Configure(command_line);
182 }
183}
static void Configure(const std::vector< std::string > &args)
Definition G4Profiler.cc:91
static void SetEnabled(size_t v, bool val)
static G4bool GetNewBoolValue(const char *paramString)

The documentation for this class was generated from the following files: