Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ProfilerMessenger.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
32
34
35#include "G4Profiler.hh"
36#include "G4UIdirectory.hh"
37#include "G4UIcmdWithABool.hh"
38#include "G4UIcmdWithAString.hh"
39#include "G4TiMemory.hh"
40
41//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42
44
46{
47 profileDirectory = new G4UIdirectory("/profiler/");
48 profileDirectory->SetGuidance("Profiler controls.");
49
50 profileOutputDirectory = new G4UIdirectory("/profiler/output/");
51 profileOutputDirectory->SetGuidance(
52 "Control the output modes of the profiler.");
53
54#define CREATE_DIR(IDX, DIR, GUIDANCE) \
55 profileTypeDirs.at(IDX) = new G4UIdirectory(DIR); \
56 profileTypeDirs.at(IDX)->SetGuidance(GUIDANCE)
57
58 CREATE_DIR(Type::Run, "/profiler/run/",
59 "Profiler controls at the G4Run level");
60 CREATE_DIR(Type::Event, "/profiler/event/",
61 "Profiler controls at the G4Event level");
62 CREATE_DIR(Type::Track, "/profiler/track/",
63 "Profiler controls at the G4Track level");
64 CREATE_DIR(Type::Step, "/profiler/step/",
65 "Profiler controls at the G4Step level");
66 CREATE_DIR(Type::User, "/profiler/user/",
67 "Profiler controls within user code");
68
69#define SET_ENABLED_CMD(IDX, CMD, CMDLINE, DEFAULT, GUIDANCE) \
70 profileEnableCmds.at(IDX).second = CMDLINE; \
71 profileEnableCmds.at(IDX).first = new G4UIcmdWithABool(CMD, this); \
72 profileEnableCmds.at(IDX).first->SetDefaultValue(DEFAULT); \
73 profileEnableCmds.at(IDX).first->SetGuidance(GUIDANCE); \
74 profileEnableCmds.at(IDX).first->AvailableForStates(G4State_PreInit, \
75 G4State_Idle)
76
77 SET_ENABLED_CMD(Type::Run, "/profiler/run/enable", "run", true,
78 "Record metrics for each G4Run");
79 SET_ENABLED_CMD(Type::Event, "/profiler/event/enable", "event", true,
80 "Record metrics for each G4Event");
81 SET_ENABLED_CMD(Type::Track, "/profiler/track/enable", "track", false,
82 "Record metrics for each G4Track");
83 SET_ENABLED_CMD(Type::Step, "/profiler/step/enable", "step", false,
84 "Record metrics for each G4Step");
85 SET_ENABLED_CMD(Type::User, "/profiler/user/enable", "user", true,
86 "Record metrics for user specified profiling instances");
87
88#define SET_COMPONENTS_CMD(IDX, CMD, CMDLINE, DEFAULTS, GUIDANCE) \
89 profileCompCmds.at(IDX).second = CMDLINE; \
90 profileCompCmds.at(IDX).first = new G4UIcmdWithAString(CMD, this); \
91 profileCompCmds.at(IDX).first->SetDefaultValue(DEFAULTS); \
92 profileCompCmds.at(IDX).first->SetGuidance(GUIDANCE); \
93 profileCompCmds.at(IDX).first->AvailableForStates(G4State_PreInit, \
94 G4State_Idle)
95
96 G4String comps = "wall_clock, cpu_clock, cpu_util, peak_rss";
97
99 Type::Run, "/profiler/run/components", "--run-components", comps,
100 "Measurment types to record for each G4Run (see `timemory-avail -s`)");
102 Type::Event, "/profiler/event/components", "--event-components", comps,
103 "Measurment types to record for each G4Event (see `timemory-avail -s`)");
105 Type::Track, "/profiler/track/components", "--track-components", comps,
106 "Measurment types to record for each G4Track (see `timemory-avail -s`)");
108 Type::Step, "/profiler/step/components", "--step-components", comps,
109 "Measurment types to record for each G4Step (see `timemory-avail -s`)");
110 SET_COMPONENTS_CMD(Type::User, "/profiler/user/components",
111 "--user-components", comps,
112 "Measurment types to record for user specified profiling "
113 "instances (see `timemory-avail -s`)");
114
115#define SET_OUTPUT_CMD(CMD, CMDLINE, DEFAULT, GUIDANCE) \
116 profileGeneralCmds.push_back({ new G4UIcmdWithABool(CMD, this), CMDLINE }); \
117 profileGeneralCmds.back().first->SetDefaultValue(DEFAULT); \
118 profileGeneralCmds.back().first->SetGuidance(GUIDANCE); \
119 profileGeneralCmds.back().first->AvailableForStates(G4State_PreInit, \
120 G4State_Idle)
121
122 SET_OUTPUT_CMD("/profiler/output/dart", "--dart", false,
123 "Enabled Dart output (CTest/CDash data tracking)");
124 SET_OUTPUT_CMD("/profiler/output/json", "--json", true,
125 "Enabled JSON output");
126 SET_OUTPUT_CMD("/profiler/output/text", "--text", true,
127 "Enabled text output");
128 SET_OUTPUT_CMD("/profiler/output/cout", "--cout", false,
129 "Enabled output to console");
130 SET_OUTPUT_CMD("/profiler/output/plot", "--plot", false,
131 "Enabled plotting JSON output");
132
133 SET_OUTPUT_CMD("/profiler/tree", "--tree", true,
134 "Display the results as a call-stack hierarchy.");
135 SET_OUTPUT_CMD("/profiler/flat", "--flat", false,
136 "Display the results as a flat call-stack");
137 SET_OUTPUT_CMD("/profiler/timeline", "--timeline", false,
138 "Do not merge duplicate entries at the same call-stack "
139 "position. May be combined with tree or flat profiles.");
141 "/profiler/per_thread", "--per-thread", false,
142 "Display the results for each individual thread (default: aggregation)");
144 "/profiler/per_event", "--per-event", false,
145 "Display the results for each individual G4event (default: aggregation)");
146}
147
148//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
149
151{
152 delete profileDirectory;
153 for(auto& itr : profileTypeDirs)
154 delete itr;
155 for(auto& itr : profileEnableCmds)
156 delete itr.first;
157 for(auto& itr : profileGeneralCmds)
158 delete itr.first;
159 for(auto& itr : profileCompCmds)
160 delete itr.first;
161}
162
163//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
164
166{
167 for(size_t i = 0; i < static_cast<size_t>(G4ProfileType::TypeEnd); ++i)
168 {
169 G4UIcmdWithABool* ui = profileEnableCmds.at(i).first;
170 if(command == ui)
171 {
173 return;
174 }
175 }
176
177 // pass the commands to the timemory argparser
178 std::vector<std::string> command_line = { "G4ProfilerMessenger" };
179
180 for(auto& itr : profileGeneralCmds)
181 {
182 G4UIcmdWithABool* ui = itr.first;
183 if(command == ui)
184 {
185 command_line.push_back(itr.second);
186 command_line.push_back(value);
187 break;
188 }
189 }
190
191 for(auto& itr : profileCompCmds)
192 {
193 G4UIcmdWithAString* ui = itr.first;
194 if(command == ui)
195 {
196 command_line.push_back(itr.second);
197#if defined(GEANT4_USE_TIMEMORY)
198 for(auto vitr : tim::delimit(value, ", ;"))
199 command_line.push_back(vitr);
200#endif
201 break;
202 }
203 }
204
205 if(command_line.size() > 1)
206 G4Profiler::Configure(command_line);
207}
208
209//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
#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 SetNewValue(G4UIcommand *, G4String)
static void Configure(const std::vector< std::string > &args)
Definition: G4Profiler.cc:91
static void SetEnabled(size_t v, bool val)
Definition: G4Profiler.hh:113
static G4bool GetNewBoolValue(const char *paramString)
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156