68 const int myRank = Teuchos::rank(*comm);
71 timer.
start(
"Total Time");
73 for (
int i=0; i < 10; ++i) {
75 timer.
start(
"Assembly");
76 std::this_thread::sleep_for(std::chrono::milliseconds{100});
77 timer.
stop(
"Assembly");
82 std::this_thread::sleep_for(std::chrono::milliseconds{50});
87 const std::string label =
"Rank 0 ONLY";
89 std::this_thread::sleep_for(std::chrono::milliseconds{50});
94 timer.
start(
"Not Rank 0");
95 std::this_thread::sleep_for(std::chrono::milliseconds{50});
97 timer.
stop(
"Not Rank 0");
105 timer.
stop(
"Total Time");
130 std::stringstream sout1;
131 timer.
report(sout1, comm, options);
135 std::stringstream sout2;
136 timer.
report(sout2, comm, options);
140 std::vector<std::tuple<std::string,double,unsigned long>> lineChecks;
141 lineChecks.push_back(std::make_tuple(
"My New Timer:",0.0,1));
142 lineChecks.push_back(std::make_tuple(
"Total Time:",2.0,1));
143 lineChecks.push_back(std::make_tuple(
"Assembly:",1.0,10));
144 lineChecks.push_back(std::make_tuple(
"Solve:",1.0,10));
145 lineChecks.push_back(std::make_tuple(
"Prec:",0.5,10));
154 #if !defined(__GNUC__) \
155 || ( defined(__GNUC__) && (__GNUC__ > 4) ) \
156 || ( defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC__MINOR__ > 8) )
159 const double timerTolerance = 0.25;
160 std::istringstream is(sout1.str());
161 for (
const auto& check : lineChecks) {
164 std::getline(is,line);
165 std::smatch regexSMatch;
166 std::regex timerName(std::get<0>(check));
167 std::regex_search(line,regexSMatch,timerName);
171 std::regex delimiter(
":\\s|\\s\\[|\\]\\s");
172 std::sregex_token_iterator tok(line.begin(), line.end(),delimiter,-1);
174 const std::string timeAsString = (++tok)->str();
175 const double time = std::stod(timeAsString);
178 const std::string countAsString = (++tok)->str();
179 const unsigned long count = std::stoul(countAsString);
186 timer.
report(out, comm, options);
204 TEST_ASSERT(timeMonitorDefaultStackedTimer != timer);
208 timer->start(
"Total Time");
210 for (
int i=0; i < 10; ++i) {
212 timer->start(
"Assembly");
216 std::this_thread::sleep_for(std::chrono::milliseconds{25});
220 std::this_thread::sleep_for(std::chrono::milliseconds{75});
223 std::this_thread::sleep_for(std::chrono::milliseconds{100});
225 timer->stop(
"Assembly");
226 timer->start(
"Solve");
230 std::this_thread::sleep_for(std::chrono::milliseconds{50});
234 std::this_thread::sleep_for(std::chrono::milliseconds{50});
237 std::this_thread::sleep_for(std::chrono::milliseconds{100});
239 timer->stop(
"Solve");
240 std::this_thread::sleep_for(std::chrono::milliseconds{100});
243 timer->stop(
"Total Time");
245 assert(
size(*comm)>0);
248 TEST_EQUALITY((timer->findTimer(
"Total Time@Assembly")).count, 10);
251 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER
252 TEST_EQUALITY((timer->findTimer(
"Total Time@Solve@Prec")).count, 10);
253 TEST_EQUALITY((timer->findTimer(
"Total Time@Solve@GMRES")).count, 10);
260 timer->report(out, comm, options);
280 timer.
start(
"Outer");
281 timer.
start(
"Inner");
287 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER