Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StackedTimer.hpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TEUCHOS_STACKED_TIMER_HPP
11#define TEUCHOS_STACKED_TIMER_HPP
12
14#include "Teuchos_Comm.hpp"
15#include "Teuchos_DefaultComm.hpp"
16#include "Teuchos_CommHelpers.hpp"
17#include "Teuchos_RCP.hpp"
18#include "Teuchos_Array.hpp"
19#include "Teuchos_EnvVariables.hpp"
21#include "Teuchos_Behavior.hpp"
22#include "TeuchosComm_config.h" // for HAVE_TEUCHOSCOMM_MAGISTRATE
23#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
24#include "checkpoint/checkpoint.h"
25#endif
26#ifdef HAVE_TEUCHOSCORE_KOKKOS
27#include "Kokkos_Core.hpp"
28#endif
29#include <string>
30#include <vector>
31#include <stack>
32#include <cassert>
33#include <chrono>
34#include <climits>
35#include <cstdlib> // for atoi
36#include <ctime> // for timestamp support
37#include <iostream>
38
39#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
40namespace Kokkos {
41namespace Tools {
42extern void pushRegion (const std::string&);
43extern void popRegion ();
44} // namespace Profiling
45} // namespace Kokkos
46#endif
47
48
49namespace Teuchos {
50
52TEUCHOSCOMM_LIB_DLL_EXPORT void error_out(const std::string& msg, const bool fail_all = false);
53
63class BaseTimer {
64
65public:
66
67 using Clock = std::chrono::high_resolution_clock;
68
69 BaseTimer() : accumulation_(0.0), accumulationSquared_(0.0), count_started_(0), count_updates_(0), running_(false) {}
70
71#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
73 explicit BaseTimer(magistrate::SERIALIZE_CONSTRUCT_TAG) {}
74
77
78
79 template<typename Serializer>
80 void serialize(Serializer& s) {
81
82 // Timers must be stopped when storing data
83 if (s.isPacking()) {
84 TEUCHOS_ASSERT(!running_);
85 }
86
87 // Don't serialize start_time_ or running_, these are only used
88 // when timer is running.
89 s | accumulation_
90 | accumulationSquared_
91 | count_started_
92 | count_updates_;
93
94 if (s.isUnpacking()) {
95 running_ = false;
96 }
97 }
98#endif
99
101 void start(){
102 if (running_)
103 error_out("Base_Timer:start Failed timer already running");
104 start_time_ = Clock::now();
105
106 count_started_++;
107 running_ = true;
108 }
109
111 void stop(){
112 if (!running_)
113 error_out("Base_Timer:stop Failed timer not running");
114 auto elapsed = std::chrono::duration_cast<std::chrono::duration<double>>(Clock::now() - start_time_).count();
115 accumulation_ += elapsed;
116 accumulationSquared_ += elapsed*elapsed;
117 running_ = false;
118 }
119
121 unsigned long long incrementUpdates(unsigned long long count=1) {count_updates_ += count; return count_updates_;}
122
124 double accumulatedTime() const {return accumulation_;}
125
127 void setAccumulatedTime(double accum = 0) { accumulation_ = accum; }
128
130 void setAccumulatedTimeSquared(double accumSq=0) {accumulationSquared_=accumSq;}
131
double accumulatedTimePerUpdate() const {
141 if (count_updates_ > 0) {
142 return accumulation_/count_updates_;
143 } else {
144 return 0;
145 }
146 }
147
148
157 if (count_started_> 0) {
158 return accumulation_/count_started_;
159 } else {
160 return 0;
161 }
162 }
163
171 double timePerCallStdDev() const {
172 if (count_started_ > 0) {
174 return sqrt(std::max<double>(accumulationSquared_ / count_started_ - mean*mean, 0.0));
175 } else {
176 return 0;
177 }
178 }
179
186 double difference(const BaseTimer &from) const {
187 return accumulation_ - from.accumulation_;
188 }
189
191 void reset() {
192 if (running_)
193 error_out("BaseTimer, cannot reset a running timer");
194 accumulation_ = 0.0;
195 count_started_ = count_updates_ = 0;
196 }
197
199 bool running() const { return running_;}
200
202 unsigned long numCalls() const { return count_started_; }
203
205 unsigned long long numUpdates() const { return count_updates_; }
206
209 { count_started_ = num_calls; }
210
212 void overrideNumUpdatesForUnitTesting(const unsigned long long num_updates)
213 { count_updates_ = num_updates; }
214
215 struct TimeInfo {
216 TimeInfo():time(0.0), stdDev(0.0), count(0), updates(0), running(false){}
217 TimeInfo(BaseTimer* t): time(t->accumulation_), stdDev(t->timePerCallStdDev()), count(t->count_started_), updates(t->count_updates_), running(t->running()) {}
218 bool operator ==(const TimeInfo& ti) const
219 {return (time == ti.time) &&
220 (stdDev == ti.stdDev) &&
221 (count == ti.count) &&
222 (updates == ti.updates) &&
223 (running == ti.running);}
224 double time;
225 double stdDev;
226 unsigned long count;
227 unsigned long long updates;
228 bool running;
229 };
230
231protected:
232 double accumulation_; // total time
233 double accumulationSquared_; // Sum of squares of elapsed times
234 unsigned long count_started_; // Number of times this timer has been started
235 unsigned long long count_updates_; // Total count of items updated during this timer
236 Clock::time_point start_time_;
237 bool running_;
238
239 friend struct TimeInfo;
240};
241
259class TEUCHOSCOMM_LIB_DLL_EXPORT StackedTimer
260{
261protected:
262
271 class LevelTimer : public BaseTimer {
272 protected:
273
274 // TODO: implement operator=
275
276 unsigned level_;
277 std::string name_;
278 LevelTimer *parent_;
279 std::vector<LevelTimer> sub_timers_;
280 public:
282 LevelTimer();
283
291 LevelTimer(int level,
292 const char* name = "RootTimer",
293 LevelTimer *parent=nullptr,
294 bool start_timer=true) :
295 BaseTimer(),
296 level_(level),
297 name_(name),
298 parent_(parent)
299 {
300 if ( start_timer )
301 BaseTimer::start();
302 }
303
306 BaseTimer(src), level_(src.level_), name_(src.name_),parent_(src.parent_), sub_timers_(src.sub_timers_)
307 {
308 for (unsigned i=0;i<sub_timers_.size();++i)
309 sub_timers_[i].parent_ = this;
310 }
311
312#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
314 LevelTimer(magistrate::SERIALIZE_CONSTRUCT_TAG) : parent_(nullptr) {}
315
316 // For serialization
318
319
320 template<typename Serializer>
321 void serialize(Serializer& s) {
322
323 s | level_;
324 s | name_;
325
326 // Manually handle the sub timers vector. The parent pointer
327 // needs to be registered before the object is constructed.
328 size_t sub_timer_size = sub_timers_.size();
330
331 if (s.isUnpacking()) {
332 sub_timers_.resize(sub_timer_size);
333 for (auto& child : sub_timers_) {
334 child.parent_ = this;
335 }
336 }
337 for (size_t i=0; i < sub_timers_.size(); ++i) {
338 s | sub_timers_[i];
339 }
340 }
341#endif
342
348 LevelTimer* start(const char* sub_name) {
349 for (unsigned i=0;i<sub_timers_.size();i++ )
350 if (sub_name == sub_timers_[i].name_ ) {
351 sub_timers_[i].BaseTimer::start();
352 return &sub_timers_[i];
353 }
354 sub_timers_.push_back(LevelTimer(level_+1,sub_name,this,true));
355 return &sub_timers_[sub_timers_.size()-1];
356 }
357
365 LevelTimer* stop(const std::string &name = "RootTimer") {
366 if (name != name_)
367 error_out("Stopping timer "+name+" But top level running timer is "+name_);
368 BaseTimer::stop();
369 return parent_;
370 }
371
372
377 std::string get_full_name() const {
378 std::string parent_name("");
379 if ((parent_ != nullptr))
380 parent_name = parent_->get_full_name() + "@";
381
382 std::string my_name(name_);
383
384 std::string full_name = parent_name + my_name;
385 return full_name;
386 }
387
388 std::string get_name() const {
389 std::string my_name(name_);
390 return my_name;
391 }
392
399 int count=1;
400 for (unsigned i=0;i<sub_timers_.size(); ++i)
401 count += sub_timers_[i].countTimers();
402 return count;
403 }
404
405 void addTimerNames(Array<std::string> &names, unsigned &pos) {
406 names[pos++] = get_full_name();
407 for (unsigned i=0;i<sub_timers_.size(); ++i)
408 sub_timers_[i].addTimerNames(names, pos);
409 }
410
416 double accumulatedTime(const std::string &locate_name="") {
417
418 if (locate_name == "")
419 return BaseTimer::accumulatedTime();
420
421 std::string first_name,second_name;
422
423 size_t i = locate_name.find_first_of('@');
424 if ( i >= locate_name.size() ) {
426 second_name = "";
427 } else {
428 first_name.assign(locate_name,0,i);
429 second_name.assign(locate_name,i+1,locate_name.size()-i-1);
430 }
431 for (unsigned j=0;j<sub_timers_.size();++j)
432 if ( first_name == sub_timers_[j].name_)
433 return sub_timers_[j].accumulatedTime(second_name);
434 return 0;
435 }
436
438 unsigned level() const
439 {return level_;}
440
441 protected:
448 void splitString(const std::string &locate_name, std::string &first_name, std::string &second_name) {
449 size_t i = locate_name.find_first_of('@');
450 if ( i >= locate_name.size() ) {
452 second_name = "";
453 } else {
454 first_name.assign(locate_name,0,i);
455 second_name.assign(locate_name,i+1,locate_name.size()-i-1);
456 }
457 }
458
459 public:
465 double accumulatedTimePerUpdate(const std::string &locate_name="") {
466
467 if (locate_name == "")
468 return BaseTimer::accumulatedTimePerUpdate();
469
470 std::string first_name,second_name;
471 splitString(locate_name, first_name, second_name);
472
473 for (unsigned j=0;j<sub_timers_.size();j++)
474 if ( first_name == sub_timers_[j].name_)
475 return sub_timers_[j].accumulatedTimePerUpdate(second_name);
476 return 0;
477 }
478
484 double accumulatedTimePerTimerCall(const std::string &locate_name="") {
485
486 if (locate_name == "")
487 return BaseTimer::accumulatedTimePerTimerCall();
488
489 std::string first_name,second_name;
490 splitString(locate_name, first_name, second_name);
491
492 for (unsigned j=0;j<sub_timers_.size();j++)
493 if ( first_name == sub_timers_[j].name_)
494 return sub_timers_[j].accumulatedTimePerTimerCall(second_name);
495 return 0;
496 }
497
501 void pack();
502
509
514 void report(std::ostream &os);
515
521 const BaseTimer* findBaseTimer(const std::string &name) const;
522
529 BaseTimer::TimeInfo findTimer(const std::string &name,bool& found);
530
531 }; // LevelTimer
532
533
534public:
540 explicit StackedTimer(const char *name, const bool start_base_timer = true)
541 : timer_(0,name,nullptr,false),
542 global_mpi_aggregation_called_(false),
543 enable_verbose_(false),
544 verbose_timestamp_levels_(0), // 0 disables
545 verbose_ostream_(Teuchos::rcpFromRef(std::cout)),
546 enable_timers_(true)
547 {
548 top_ = &timer_;
550 this->startBaseTimer();
551
552 auto check_verbose = Teuchos::getEnvironmentVariableValue("TEUCHOS_ENABLE_VERBOSE_TIMERS");
553 if (check_verbose != nullptr)
554 enable_verbose_ = true;
555
556 auto check_timestamp = Teuchos::getEnvironmentVariableValue("TEUCHOS_ENABLE_VERBOSE_TIMESTAMP_LEVELS");
557 if (check_timestamp != nullptr) {
558 verbose_timestamp_levels_ = std::atoi(check_timestamp);
559 }
560 }
561
562#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
563 explicit StackedTimer(magistrate::SERIALIZE_CONSTRUCT_TAG) {}
564
565 template<typename Serializer>
566 void serialize(Serializer& s) {
567 s | timer_;
568 s | enable_verbose_;
569 s | verbose_timestamp_levels_;
570 s | enable_timers_;
571
572 if (s.isUnpacking()) {
573 // Timer is always stopped before serializing
574 top_ = &timer_;
575 // Can't serialize an ostream pointer so just set to std::cout
576 verbose_ostream_ = Teuchos::rcpFromRef(std::cout);
577 global_mpi_aggregation_called_ = false;
578 }
579 }
580#endif
581
582 std::string name() {
583 return timer_.get_full_name();
584 }
585
590#ifdef HAVE_TEUCHOSCORE_KOKKOS
591 // Fence before starting timer to ignore async kernels started before this timer starts
592 if (Behavior::fenceTimers()) {
593 Kokkos::fence("timer_fence_begin_"+timer_.get_name());
594 }
595#endif
596 timer_.BaseTimer::start();
597#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
599 ::Kokkos::Tools::pushRegion(timer_.get_name());
600 }
601#endif
602 }
603
608#ifdef HAVE_TEUCHOSCORE_KOKKOS
609 // Fence before stopping the timer to include async kokkos kernels launched within this timer
610 if (Behavior::fenceTimers()) {
611 Kokkos::fence("timer_fence_end_"+timer_.get_name());
612 }
613#endif
614#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
616 ::Kokkos::Tools::popRegion();
617 }
618#endif
619 timer_.BaseTimer::stop();
620 }
621
627 void start(const std::string name,
628 const bool push_kokkos_profiling_region = true) {
629 if (enable_timers_) {
630 if (top_ == nullptr) {
631 top_ = timer_.start(name.c_str());
632 } else {
633#ifdef HAVE_TEUCHOSCORE_KOKKOS
634 // Fence before starting timer to ignore async kernels started before this timer starts
635 if (Behavior::fenceTimers()) {
636 Kokkos::fence("timer_fence_begin_"+name);
637 }
638#endif
639 top_ = top_->start(name.c_str());
640#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
642 ::Kokkos::Tools::pushRegion(name);
643 }
644#endif
645 }
646 }
647 if (enable_verbose_) {
648 if (!verbose_timestamp_levels_) {
649 *verbose_ostream_ << "STARTING: " << name << std::endl;
650 }
651 // gcc 4.X is incomplete in c++11 standard - missing
652 // std::put_time. We'll disable this feature for gcc 4.
653#if !defined(__GNUC__) || ( defined(__GNUC__) && (__GNUC__ > 4) )
654 else if (top_ != nullptr) {
655 if ( top_->level() <= verbose_timestamp_levels_) {
656 auto now = std::chrono::system_clock::now();
657 auto now_time = std::chrono::system_clock::to_time_t(now);
658 auto gmt = gmtime(&now_time);
659 auto timestamp = std::put_time(gmt, "%Y-%m-%d %H:%M:%S");
660 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
661 *verbose_ostream_ << "STARTING: " << name << " LEVEL: " << top_->level() << " COUNT: " << timer_.numCalls() << " TIMESTAMP: " << timestamp << "." << ms.count() << std::endl;
662 }
663 }
664#endif
665 }
666 }
667
673 void stop(const std::string &name,
674 const bool pop_kokkos_profiling_region = true) {
675 if (enable_timers_) {
676 if (top_) {
677#ifdef HAVE_TEUCHOSCORE_KOKKOS
678 // Fence before stopping the timer to include async kokkos kernels launched within this timer
679 if (Behavior::fenceTimers()) {
680 Kokkos::fence("timer_fence_end_"+name);
681 }
682#endif
683#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
685 ::Kokkos::Tools::popRegion();
686 }
687#endif
688 top_ = top_->stop(name);
689 } else {
690 timer_.BaseTimer::stop();
691 }
692 }
693 if (enable_verbose_) {
694 if (!verbose_timestamp_levels_) {
695 *verbose_ostream_ << "STOPPING: " << name << std::endl;
696 }
697 // gcc 4.X is incomplete in c++11 standard - missing
698 // std::put_time. We'll disable this feature for gcc 4.
699#if !defined(__GNUC__) || ( defined(__GNUC__) && (__GNUC__ > 4) )
700 // The stop adjusts the top level, need to adjust by +1 for printing
701 else if (top_ != nullptr) {
702 if ( (top_->level()+1) <= verbose_timestamp_levels_) {
703 auto now = std::chrono::system_clock::now();
704 auto now_time = std::chrono::system_clock::to_time_t(now);
705 auto gmt = gmtime(&now_time);
706 auto timestamp = std::put_time(gmt, "%Y-%m-%d %H:%M:%S");
707 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
708 *verbose_ostream_ << "STOPPING: " << name << " LEVEL: " << top_->level()+1 << " COUNT: " << timer_.numCalls() << " TIMESTAMP: " << timestamp << "." << ms.count() << std::endl;
709 }
710 }
711#endif
712 }
713 }
714
719 void incrementUpdates(const long long i = 1) {
720 top_->incrementUpdates(i);
721 }
722
728 double accumulatedTime(const std::string &name="") {
729 if (top_) // Top is null for the head node when nothing is running
730 return top_->accumulatedTime(name);
731 else
732 return timer_.accumulatedTime(name);
733 }
734
740 double accumulatedTimePerUpdate(const std::string &name="") {
741 if (top_) // Top is null for the head node when nothing is running
742 return top_->accumulatedTimePerUpdate(name);
743 else
744 return timer_.accumulatedTimePerUpdate(name);
745 }
751 double accumulatedTimePerTimerCall(const std::string &name="") {
752 if (top_) // Top is null for the head node when nothing is running
753 return top_->accumulatedTimePerTimerCall(name);
754 else
755 return timer_.accumulatedTimePerTimerCall(name);
756 }
757
763 const BaseTimer* findBaseTimer(const std::string &name) const {
764 const BaseTimer* baseTimer = timer_.findBaseTimer(name);
765 TEUCHOS_TEST_FOR_EXCEPTION(baseTimer == nullptr, std::runtime_error,
766 "StackedTimer::findBaseTimer() failed to find a timer named \"" << name << "\"!\n");
767 return baseTimer;
768 }
769
775 BaseTimer::TimeInfo findTimer(const std::string &name) {
776 bool foundTimer = false;
777 const auto timeInfo = timer_.findTimer(name,foundTimer);
778 TEUCHOS_TEST_FOR_EXCEPTION(!foundTimer, std::runtime_error,
779 "StackedTimer::findTimer() failed to find a timer named \"" << name << "\"!\n");
780 return timeInfo;
781 }
782
783 void report(std::ostream &os) {
784 timer_.report(os);
785 }
786
802 OutputOptions() : output_fraction(false), output_total_updates(false), output_histogram(false),
803 output_minmax(false), output_proc_minmax(false), num_histogram(10), max_levels(INT_MAX),
804 print_warnings(true), align_columns(false), print_names_before_values(true),
805 drop_time(-1.0), output_per_proc_stddev(false) {}
806 bool output_fraction;
807 bool output_total_updates;
808 bool output_histogram;
809 bool output_minmax;
810 bool output_proc_minmax;
811 int num_histogram;
812 int max_levels;
813 bool print_warnings;
814 bool align_columns;
815 bool print_names_before_values;
816 double drop_time;
817 bool output_per_proc_stddev;
818 };
819
826 void report(std::ostream &os, Teuchos::RCP<const Teuchos::Comm<int> > comm, OutputOptions options = OutputOptions());
827
837 void reportXML(std::ostream &os, const std::string& datestamp, const std::string& timestamp, Teuchos::RCP<const Teuchos::Comm<int> > comm);
838
870 std::string reportWatchrXML(const std::string& name, Teuchos::RCP<const Teuchos::Comm<int> > comm);
871
873 void enableVerbose(const bool enable_verbose);
874
876 void enableVerboseTimestamps(const unsigned levels);
877
879 void setVerboseOstream(const Teuchos::RCP<std::ostream>& os);
880
883 void disableTimers();
884
887 void enableTimers();
888
894 void aggregateMpiData(Teuchos::RCP<const Teuchos::Comm<int> > comm, OutputOptions options = OutputOptions());
895
904 double getMpiAverageTime(const std::string& flat_timer_name);
905
914 double getMpiAverageCount(const std::string& flat_timer_name);
915
924 bool isTimer(const std::string& flat_timer_name);
925
936 std::stack<std::string> stopAllTimers();
937
946 void startTimers(std::stack<std::string> timers_to_start);
947
948
949protected:
954
955 // Global MPI aggregation arrays
956 Array<std::string> flat_names_;
957 Array<double> min_;
958 Array<double> max_;
959 Array<int> procmin_;
960 Array<int> procmax_;
961 Array<double> sum_;
962 Array<double> sum_sq_;
963 Array<Array<int>> hist_;
964 Array<double> per_proc_stddev_min_;
965 Array<double> per_proc_stddev_max_;
968 Array<int> active_;
969 bool global_mpi_aggregation_called_;
970
973 std::string::size_type timer_names_;
974 std::string::size_type average_time_;
975 std::string::size_type fraction_;
976 std::string::size_type count_;
977 std::string::size_type total_updates_;
978 std::string::size_type min_;
979 std::string::size_type max_;
980 std::string::size_type procmin_;
981 std::string::size_type procmax_;
982 std::string::size_type stddev_;
983 std::string::size_type histogram_;
985 timer_names_(0),
986 average_time_(0),
987 fraction_(0),
988 count_(0),
989 total_updates_(0),
990 min_(0),
991 max_(0),
992 procmax_(0),
993 stddev_(0),
994 histogram_(0){}
995 } alignments_;
996
999
1002
1005
1008
1012 void flatten();
1013
1018 void merge(Teuchos::RCP<const Teuchos::Comm<int> > comm);
1019
1023 void collectRemoteData(Teuchos::RCP<const Teuchos::Comm<int> > comm, const OutputOptions &options );
1024
1028 int getFlatNameIndex(const std::string& flat_timer_name);
1029
1036 double computeColumnWidthsForAligment(std::string prefix, int print_level,
1037 std::vector<bool> &printed, double parent_time,
1038 const OutputOptions &options);
1039
1043 double printLevel(std::string prefix, int level, std::ostream &os, std::vector<bool> &printed,
1044 double parent_time, const OutputOptions &options);
1045
1050 double printLevelXML(std::string prefix, int level, std::ostream &os, std::vector<bool> &printed, double parent_time, const std::string& rootName = "");
1051
1052}; //StackedTimer
1053
1054
1055} //namespace Teuchos
1056
1057#endif /* TEUCHOS_STACKED_TIMER_HPP */
Templated array class derived from the STL std::vector.
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Common capabilities for collecting and reporting performance data collectively across MPI processes.
Reference-counted pointer class and non-member templated function implementations.
The basic timer used internally, uses std::chrono::high_resolution_clock.
void setAccumulatedTime(double accum=0)
Setter for accumulated time.
double difference(const BaseTimer &from) const
Return the difference between two timers in seconds,.
void reset()
Reset all the timer stats, throws if it is already running.
void start()
Start a currently stopped timer.
double accumulatedTimePerTimerCall() const
return the average time per timer start/stop
double accumulatedTimePerUpdate() const
return the average time per item updated
void stop()
Stop a current running timer and accumulate time difference.
void overrideNumUpdatesForUnitTesting(const unsigned long long num_updates)
Sets the number of counts for this timer. This is only used for unit testing.
double accumulatedTime() const
Get the total accumulated time since last reset or construction when the timer is running.
double timePerCallStdDev() const
return the std dev in time per timer start/stop
void overrideNumCallsForUnitTesting(const unsigned long num_calls)
Sets the number of calls to start() for this timer. This is only used for unit testing.
unsigned long long numUpdates() const
Returns the number of updates added to this timer.
void setAccumulatedTimeSquared(double accumSq=0)
Setter for squared accumulated time.
unsigned long numCalls() const
Returns the number of calls to start().
unsigned long long incrementUpdates(unsigned long long count=1)
Increment the total number of items updated between a start stop.
bool running() const
Returns true if the timer is currently accumulating time.
Smart reference counting pointer class for automatic garbage collection.
Strategy interface for the indirect serializing and deserializing objects of a given type handled usi...
Timer info at a given level and all the children.
double accumulatedTime(const std::string &locate_name="")
LevelTimer * start(const char *sub_name)
void splitString(const std::string &locate_name, std::string &first_name, std::string &second_name)
split a string into two parts split by a '@' if no '@' first gets the full string
double accumulatedTimePerTimerCall(const std::string &locate_name="")
LevelTimer(const LevelTimer &src)
Copy constructor.
LevelTimer * stop(const std::string &name="RootTimer")
unsigned level() const
Returns the level of the timer in the stack.
double accumulatedTimePerUpdate(const std::string &locate_name="")
LevelTimer * unpack(unsigned from)
LevelTimer(int level, const char *name="RootTimer", LevelTimer *parent=nullptr, bool start_timer=true)
This class allows one to push and pop timers on and off a stack.
LevelTimer * top_
Current level running.
void start(const std::string name, const bool push_kokkos_profiling_region=true)
BaseTimer::TimeInfo findTimer(const std::string &name)
void stop(const std::string &name, const bool pop_kokkos_profiling_region=true)
void startBaseTimer(const bool push_kokkos_profiling_region=true)
void stopBaseTimer(const bool pop_kokkos_profiling_region=true)
const BaseTimer * findBaseTimer(const std::string &name) const
Teuchos::RCP< std::ostream > verbose_ostream_
For debugging, this is the ostream used for printing.
double accumulatedTimePerUpdate(const std::string &name="")
void incrementUpdates(const long long i=1)
bool enable_timers_
Used to disable timers for asynchronous work.
unsigned verbose_timestamp_levels_
If set to a value greater than 0, verbose mode will print that many levels of timers with timestamps....
double accumulatedTime(const std::string &name="")
LevelTimer timer_
Base timer.
bool enable_verbose_
If set to true, prints to the debug ostream. At construction, default value is set from environment v...
double accumulatedTimePerTimerCall(const std::string &name="")
StackedTimer(const char *name, const bool start_base_timer=true)
#define TEUCHOS_ASSERT(assertion_test)
This macro is throws when an assert fails.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
const char * getEnvironmentVariableValue(const char name[])
Read a process environment variable by name.
void error_out(const std::string &msg, const bool)
Error reporting function for stacked timer.
Stores the column widths for output alignment.