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"
20#include "Teuchos_Behavior.hpp"
21#include "TeuchosComm_config.h" // for HAVE_TEUCHOSCOMM_MAGISTRATE
22#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
23#include "checkpoint/checkpoint.h"
24#endif
25#ifdef HAVE_TEUCHOSCORE_KOKKOS
26#include "Kokkos_Core.hpp"
27#endif
28#include <string>
29#include <vector>
30#include <stack>
31#include <cassert>
32#include <chrono>
33#include <climits>
34#include <cstdlib> // for std::getenv and atoi
35#include <ctime> // for timestamp support
36#include <iostream>
37
38#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
39namespace Kokkos {
40namespace Tools {
41extern void pushRegion (const std::string&);
42extern void popRegion ();
43} // namespace Profiling
44} // namespace Kokkos
45#endif
46
47
48namespace Teuchos {
49
51TEUCHOSCOMM_LIB_DLL_EXPORT void error_out(const std::string& msg, const bool fail_all = false);
52
62class BaseTimer {
63
64public:
65
66 using Clock = std::chrono::high_resolution_clock;
67
68 BaseTimer() : accumulation_(0.0), accumulationSquared_(0.0), count_started_(0), count_updates_(0), running_(false) {}
69
70#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
72 explicit BaseTimer(magistrate::SERIALIZE_CONSTRUCT_TAG) {}
73
76
77
78 template<typename Serializer>
79 void serialize(Serializer& s) {
80
81 // Timers must be stopped when storing data
82 if (s.isPacking()) {
83 TEUCHOS_ASSERT(!running_);
84 }
85
86 // Don't serialize start_time_ or running_, these are only used
87 // when timer is running.
88 s | accumulation_
89 | accumulationSquared_
90 | count_started_
91 | count_updates_;
92
93 if (s.isUnpacking()) {
94 running_ = false;
95 }
96 }
97#endif
98
100 void start(){
101 if (running_)
102 error_out("Base_Timer:start Failed timer already running");
103 start_time_ = Clock::now();
104
105 count_started_++;
106 running_ = true;
107 }
108
110 void stop(){
111 if (!running_)
112 error_out("Base_Timer:stop Failed timer not running");
113 auto elapsed = std::chrono::duration_cast<std::chrono::duration<double>>(Clock::now() - start_time_).count();
114 accumulation_ += elapsed;
115 accumulationSquared_ += elapsed*elapsed;
116 running_ = false;
117 }
118
120 unsigned long long incrementUpdates(unsigned long long count=1) {count_updates_ += count; return count_updates_;}
121
123 double accumulatedTime() const {return accumulation_;}
124
126 void setAccumulatedTime(double accum = 0) { accumulation_ = accum; }
127
129 void setAccumulatedTimeSquared(double accumSq=0) {accumulationSquared_=accumSq;}
130
double accumulatedTimePerUpdate() const {
140 if (count_updates_ > 0) {
141 return accumulation_/count_updates_;
142 } else {
143 return 0;
144 }
145 }
146
147
156 if (count_started_> 0) {
157 return accumulation_/count_started_;
158 } else {
159 return 0;
160 }
161 }
162
170 double timePerCallStdDev() const {
171 if (count_started_ > 0) {
173 return sqrt(std::max<double>(accumulationSquared_ / count_started_ - mean*mean, 0.0));
174 } else {
175 return 0;
176 }
177 }
178
185 double difference(const BaseTimer &from) const {
186 return accumulation_ - from.accumulation_;
187 }
188
190 void reset() {
191 if (running_)
192 error_out("BaseTimer, cannot reset a running timer");
193 accumulation_ = 0.0;
194 count_started_ = count_updates_ = 0;
195 }
196
198 bool running() const { return running_;}
199
201 unsigned long numCalls() const { return count_started_; }
202
204 unsigned long long numUpdates() const { return count_updates_; }
205
208 { count_started_ = num_calls; }
209
211 void overrideNumUpdatesForUnitTesting(const unsigned long long num_updates)
212 { count_updates_ = num_updates; }
213
214 struct TimeInfo {
215 TimeInfo():time(0.0), stdDev(0.0), count(0), updates(0), running(false){}
216 TimeInfo(BaseTimer* t): time(t->accumulation_), stdDev(t->timePerCallStdDev()), count(t->count_started_), updates(t->count_updates_), running(t->running()) {}
217 bool operator ==(const TimeInfo& ti)
218 {return (time == ti.time) &&
219 (stdDev == ti.stdDev) &&
220 (count == ti.count) &&
221 (updates == ti.updates) &&
222 (running == ti.running);}
223 double time;
224 double stdDev;
225 unsigned long count;
226 unsigned long long updates;
227 bool running;
228 };
229
230protected:
231 double accumulation_; // total time
232 double accumulationSquared_; // Sum of squares of elapsed times
233 unsigned long count_started_; // Number of times this timer has been started
234 unsigned long long count_updates_; // Total count of items updated during this timer
235 Clock::time_point start_time_;
236 bool running_;
237
238 friend struct TimeInfo;
239};
240
258class TEUCHOSCOMM_LIB_DLL_EXPORT StackedTimer
259{
260protected:
261
270 class LevelTimer : public BaseTimer {
271 protected:
272
273 // TODO: implement operator=
274
275 unsigned level_;
276 std::string name_;
277 LevelTimer *parent_;
278 std::vector<LevelTimer> sub_timers_;
279 public:
281 LevelTimer();
282
290 LevelTimer(int level,
291 const char* name = "RootTimer",
292 LevelTimer *parent=nullptr,
293 bool start_timer=true) :
294 BaseTimer(),
295 level_(level),
296 name_(name),
297 parent_(parent)
298 {
299 if ( start_timer )
300 BaseTimer::start();
301 }
302
305 BaseTimer(src), level_(src.level_), name_(src.name_),parent_(src.parent_), sub_timers_(src.sub_timers_)
306 {
307 for (unsigned i=0;i<sub_timers_.size();++i)
308 sub_timers_[i].parent_ = this;
309 }
310
311#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
313 LevelTimer(magistrate::SERIALIZE_CONSTRUCT_TAG) : parent_(nullptr) {}
314
315 // For serialization
317
318
319 template<typename Serializer>
320 void serialize(Serializer& s) {
321
322 s | level_;
323 s | name_;
324
325 // Manually handle the sub timers vector. The parent pointer
326 // needs to be registered before the object is constructed.
327 size_t sub_timer_size = sub_timers_.size();
329
330 if (s.isUnpacking()) {
331 sub_timers_.resize(sub_timer_size);
332 for (auto& child : sub_timers_) {
333 child.parent_ = this;
334 }
335 }
336 for (size_t i=0; i < sub_timers_.size(); ++i) {
337 s | sub_timers_[i];
338 }
339 }
340#endif
341
347 LevelTimer* start(const char* sub_name) {
348 for (unsigned i=0;i<sub_timers_.size();i++ )
349 if (sub_name == sub_timers_[i].name_ ) {
350 sub_timers_[i].BaseTimer::start();
351 return &sub_timers_[i];
352 }
353 sub_timers_.push_back(LevelTimer(level_+1,sub_name,this,true));
354 return &sub_timers_[sub_timers_.size()-1];
355 }
356
364 LevelTimer* stop(const std::string &name = "RootTimer") {
365 if (name != name_)
366 error_out("Stopping timer "+name+" But top level running timer is "+name_);
367 BaseTimer::stop();
368 return parent_;
369 }
370
371
376 std::string get_full_name() const {
377 std::string parent_name("");
378 if ((parent_ != nullptr))
379 parent_name = parent_->get_full_name() + "@";
380
381 std::string my_name(name_);
382
383 std::string full_name = parent_name + my_name;
384 return full_name;
385 }
386
387 std::string get_name() const {
388 std::string my_name(name_);
389 return my_name;
390 }
391
398 int count=1;
399 for (unsigned i=0;i<sub_timers_.size(); ++i)
400 count += sub_timers_[i].countTimers();
401 return count;
402 }
403
404 void addTimerNames(Array<std::string> &names, unsigned &pos) {
405 names[pos++] = get_full_name();
406 for (unsigned i=0;i<sub_timers_.size(); ++i)
407 sub_timers_[i].addTimerNames(names, pos);
408 }
409
415 double accumulatedTime(const std::string &locate_name="") {
416
417 if (locate_name == "")
418 return BaseTimer::accumulatedTime();
419
420 std::string first_name,second_name;
421
422 size_t i = locate_name.find_first_of('@');
423 if ( i >= locate_name.size() ) {
425 second_name = "";
426 } else {
427 first_name.assign(locate_name,0,i);
428 second_name.assign(locate_name,i+1,locate_name.size()-i-1);
429 }
430 for (unsigned j=0;j<sub_timers_.size();++j)
431 if ( first_name == sub_timers_[j].name_)
432 return sub_timers_[j].accumulatedTime(second_name);
433 return 0;
434 }
435
437 unsigned level() const
438 {return level_;}
439
440 protected:
447 void splitString(const std::string &locate_name, std::string &first_name, std::string &second_name) {
448 size_t i = locate_name.find_first_of('@');
449 if ( i >= locate_name.size() ) {
451 second_name = "";
452 } else {
453 first_name.assign(locate_name,0,i);
454 second_name.assign(locate_name,i+1,locate_name.size()-i-1);
455 }
456 }
457
458 public:
464 double accumulatedTimePerUpdate(const std::string &locate_name="") {
465
466 if (locate_name == "")
467 return BaseTimer::accumulatedTimePerUpdate();
468
469 std::string first_name,second_name;
470 splitString(locate_name, first_name, second_name);
471
472 for (unsigned j=0;j<sub_timers_.size();j++)
473 if ( first_name == sub_timers_[j].name_)
474 return sub_timers_[j].accumulatedTimePerUpdate(second_name);
475 return 0;
476 }
477
483 double accumulatedTimePerTimerCall(const std::string &locate_name="") {
484
485 if (locate_name == "")
486 return BaseTimer::accumulatedTimePerTimerCall();
487
488 std::string first_name,second_name;
489 splitString(locate_name, first_name, second_name);
490
491 for (unsigned j=0;j<sub_timers_.size();j++)
492 if ( first_name == sub_timers_[j].name_)
493 return sub_timers_[j].accumulatedTimePerTimerCall(second_name);
494 return 0;
495 }
496
500 void pack();
501
508
513 void report(std::ostream &os);
514
520 const BaseTimer* findBaseTimer(const std::string &name) const;
521
528 BaseTimer::TimeInfo findTimer(const std::string &name,bool& found);
529
530 }; // LevelTimer
531
532
533public:
539 explicit StackedTimer(const char *name, const bool start_base_timer = true)
540 : timer_(0,name,nullptr,false),
541 global_mpi_aggregation_called_(false),
542 enable_verbose_(false),
543 verbose_timestamp_levels_(0), // 0 disables
544 verbose_ostream_(Teuchos::rcpFromRef(std::cout)),
545 enable_timers_(true)
546 {
547 top_ = &timer_;
549 this->startBaseTimer();
550
551 auto check_verbose = std::getenv("TEUCHOS_ENABLE_VERBOSE_TIMERS");
552 if (check_verbose != nullptr)
553 enable_verbose_ = true;
554
555 auto check_timestamp = std::getenv("TEUCHOS_ENABLE_VERBOSE_TIMESTAMP_LEVELS");
556 if (check_timestamp != nullptr) {
557 verbose_timestamp_levels_ = std::atoi(check_timestamp);
558 }
559 }
560
561#ifdef HAVE_TEUCHOSCOMM_MAGISTRATE
562 explicit StackedTimer(magistrate::SERIALIZE_CONSTRUCT_TAG) {}
563
564 template<typename Serializer>
565 void serialize(Serializer& s) {
566 s | timer_;
567 s | enable_verbose_;
568 s | verbose_timestamp_levels_;
569 s | enable_timers_;
570
571 if (s.isUnpacking()) {
572 // Timer is always stopped before serializing
573 top_ = &timer_;
574 // Can't serialize an ostream pointer so just set to std::cout
575 verbose_ostream_ = Teuchos::rcpFromRef(std::cout);
576 global_mpi_aggregation_called_ = false;
577 }
578 }
579#endif
580
581 std::string name() {
582 return timer_.get_full_name();
583 }
584
589#ifdef HAVE_TEUCHOSCORE_KOKKOS
590 // Fence before starting timer to ignore async kernels started before this timer starts
591 if (Behavior::fenceTimers()) {
592 Kokkos::fence("timer_fence_begin_"+timer_.get_name());
593 }
594#endif
595 timer_.BaseTimer::start();
596#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
598 ::Kokkos::Tools::pushRegion(timer_.get_name());
599 }
600#endif
601 }
602
607#ifdef HAVE_TEUCHOSCORE_KOKKOS
608 // Fence before stopping the timer to include async kokkos kernels launched within this timer
609 if (Behavior::fenceTimers()) {
610 Kokkos::fence("timer_fence_end_"+timer_.get_name());
611 }
612#endif
613#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
615 ::Kokkos::Tools::popRegion();
616 }
617#endif
618 timer_.BaseTimer::stop();
619 }
620
626 void start(const std::string name,
627 const bool push_kokkos_profiling_region = true) {
628 if (enable_timers_) {
629 if (top_ == nullptr) {
630 top_ = timer_.start(name.c_str());
631 } else {
632#ifdef HAVE_TEUCHOSCORE_KOKKOS
633 // Fence before starting timer to ignore async kernels started before this timer starts
634 if (Behavior::fenceTimers()) {
635 Kokkos::fence("timer_fence_begin_"+name);
636 }
637#endif
638 top_ = top_->start(name.c_str());
639#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
641 ::Kokkos::Tools::pushRegion(name);
642 }
643#endif
644 }
645 }
646 if (enable_verbose_) {
647 if (!verbose_timestamp_levels_) {
648 *verbose_ostream_ << "STARTING: " << name << std::endl;
649 }
650 // gcc 4.X is incomplete in c++11 standard - missing
651 // std::put_time. We'll disable this feature for gcc 4.
652#if !defined(__GNUC__) || ( defined(__GNUC__) && (__GNUC__ > 4) )
653 else if (top_ != nullptr) {
654 if ( top_->level() <= verbose_timestamp_levels_) {
655 auto now = std::chrono::system_clock::now();
656 auto now_time = std::chrono::system_clock::to_time_t(now);
657 auto gmt = gmtime(&now_time);
658 auto timestamp = std::put_time(gmt, "%Y-%m-%d %H:%M:%S");
659 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
660 *verbose_ostream_ << "STARTING: " << name << " LEVEL: " << top_->level() << " COUNT: " << timer_.numCalls() << " TIMESTAMP: " << timestamp << "." << ms.count() << std::endl;
661 }
662 }
663#endif
664 }
665 }
666
672 void stop(const std::string &name,
673 const bool pop_kokkos_profiling_region = true) {
674 if (enable_timers_) {
675 if (top_) {
676#ifdef HAVE_TEUCHOSCORE_KOKKOS
677 // Fence before stopping the timer to include async kokkos kernels launched within this timer
678 if (Behavior::fenceTimers()) {
679 Kokkos::fence("timer_fence_end_"+name);
680 }
681#endif
682#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
684 ::Kokkos::Tools::popRegion();
685 }
686#endif
687 top_ = top_->stop(name);
688 } else {
689 timer_.BaseTimer::stop();
690 }
691 }
692 if (enable_verbose_) {
693 if (!verbose_timestamp_levels_) {
694 *verbose_ostream_ << "STOPPING: " << name << std::endl;
695 }
696 // gcc 4.X is incomplete in c++11 standard - missing
697 // std::put_time. We'll disable this feature for gcc 4.
698#if !defined(__GNUC__) || ( defined(__GNUC__) && (__GNUC__ > 4) )
699 // The stop adjusts the top level, need to adjust by +1 for printing
700 else if (top_ != nullptr) {
701 if ( (top_->level()+1) <= verbose_timestamp_levels_) {
702 auto now = std::chrono::system_clock::now();
703 auto now_time = std::chrono::system_clock::to_time_t(now);
704 auto gmt = gmtime(&now_time);
705 auto timestamp = std::put_time(gmt, "%Y-%m-%d %H:%M:%S");
706 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
707 *verbose_ostream_ << "STOPPING: " << name << " LEVEL: " << top_->level()+1 << " COUNT: " << timer_.numCalls() << " TIMESTAMP: " << timestamp << "." << ms.count() << std::endl;
708 }
709 }
710#endif
711 }
712 }
713
718 void incrementUpdates(const long long i = 1) {
719 top_->incrementUpdates(i);
720 }
721
727 double accumulatedTime(const std::string &name="") {
728 if (top_) // Top is null for the head node when nothing is running
729 return top_->accumulatedTime(name);
730 else
731 return timer_.accumulatedTime(name);
732 }
733
739 double accumulatedTimePerUpdate(const std::string &name="") {
740 if (top_) // Top is null for the head node when nothing is running
741 return top_->accumulatedTimePerUpdate(name);
742 else
743 return timer_.accumulatedTimePerUpdate(name);
744 }
750 double accumulatedTimePerTimerCall(const std::string &name="") {
751 if (top_) // Top is null for the head node when nothing is running
752 return top_->accumulatedTimePerTimerCall(name);
753 else
754 return timer_.accumulatedTimePerTimerCall(name);
755 }
756
762 const BaseTimer* findBaseTimer(const std::string &name) const {
763 const BaseTimer* baseTimer = timer_.findBaseTimer(name);
764 TEUCHOS_TEST_FOR_EXCEPTION(baseTimer == nullptr, std::runtime_error,
765 "StackedTimer::findBaseTimer() failed to find a timer named \"" << name << "\"!\n");
766 return baseTimer;
767 }
768
774 BaseTimer::TimeInfo findTimer(const std::string &name) {
775 bool foundTimer = false;
776 const auto timeInfo = timer_.findTimer(name,foundTimer);
777 TEUCHOS_TEST_FOR_EXCEPTION(!foundTimer, std::runtime_error,
778 "StackedTimer::findTimer() failed to find a timer named \"" << name << "\"!\n");
779 return timeInfo;
780 }
781
782 void report(std::ostream &os) {
783 timer_.report(os);
784 }
785
801 OutputOptions() : output_fraction(false), output_total_updates(false), output_histogram(false),
802 output_minmax(false), output_proc_minmax(false), num_histogram(10), max_levels(INT_MAX),
803 print_warnings(true), align_columns(false), print_names_before_values(true),
804 drop_time(-1.0), output_per_proc_stddev(false) {}
805 bool output_fraction;
806 bool output_total_updates;
807 bool output_histogram;
808 bool output_minmax;
809 bool output_proc_minmax;
810 int num_histogram;
811 int max_levels;
812 bool print_warnings;
813 bool align_columns;
814 bool print_names_before_values;
815 double drop_time;
816 bool output_per_proc_stddev;
817 };
818
825 void report(std::ostream &os, Teuchos::RCP<const Teuchos::Comm<int> > comm, OutputOptions options = OutputOptions());
826
836 void reportXML(std::ostream &os, const std::string& datestamp, const std::string& timestamp, Teuchos::RCP<const Teuchos::Comm<int> > comm);
837
869 std::string reportWatchrXML(const std::string& name, Teuchos::RCP<const Teuchos::Comm<int> > comm);
870
872 void enableVerbose(const bool enable_verbose);
873
875 void enableVerboseTimestamps(const unsigned levels);
876
878 void setVerboseOstream(const Teuchos::RCP<std::ostream>& os);
879
882 void disableTimers();
883
886 void enableTimers();
887
893 void aggregateMpiData(Teuchos::RCP<const Teuchos::Comm<int> > comm, OutputOptions options = OutputOptions());
894
903 double getMpiAverageTime(const std::string& flat_timer_name);
904
913 double getMpiAverageCount(const std::string& flat_timer_name);
914
923 bool isTimer(const std::string& flat_timer_name);
924
935 std::stack<std::string> stopAllTimers();
936
945 void startTimers(std::stack<std::string> timers_to_start);
946
947
948protected:
953
954 // Global MPI aggregation arrays
955 Array<std::string> flat_names_;
956 Array<double> min_;
957 Array<double> max_;
958 Array<int> procmin_;
959 Array<int> procmax_;
960 Array<double> sum_;
961 Array<double> sum_sq_;
962 Array<Array<int>> hist_;
963 Array<double> per_proc_stddev_min_;
964 Array<double> per_proc_stddev_max_;
967 Array<int> active_;
968 bool global_mpi_aggregation_called_;
969
972 std::string::size_type timer_names_;
973 std::string::size_type average_time_;
974 std::string::size_type fraction_;
975 std::string::size_type count_;
976 std::string::size_type total_updates_;
977 std::string::size_type min_;
978 std::string::size_type max_;
979 std::string::size_type procmin_;
980 std::string::size_type procmax_;
981 std::string::size_type stddev_;
982 std::string::size_type histogram_;
984 timer_names_(0),
985 average_time_(0),
986 fraction_(0),
987 count_(0),
988 total_updates_(0),
989 min_(0),
990 max_(0),
991 procmax_(0),
992 stddev_(0),
993 histogram_(0){}
994 } alignments_;
995
998
1001
1004
1007
1011 void flatten();
1012
1017 void merge(Teuchos::RCP<const Teuchos::Comm<int> > comm);
1018
1022 void collectRemoteData(Teuchos::RCP<const Teuchos::Comm<int> > comm, const OutputOptions &options );
1023
1027 int getFlatNameIndex(const std::string& flat_timer_name);
1028
1035 double computeColumnWidthsForAligment(std::string prefix, int print_level,
1036 std::vector<bool> &printed, double parent_time,
1037 const OutputOptions &options);
1038
1042 double printLevel(std::string prefix, int level, std::ostream &os, std::vector<bool> &printed,
1043 double parent_time, const OutputOptions &options);
1044
1049 double printLevelXML(std::string prefix, int level, std::ostream &os, std::vector<bool> &printed, double parent_time, const std::string& rootName = "");
1050
1051}; //StackedTimer
1052
1053
1054} //namespace Teuchos
1055
1056#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,...
void error_out(const std::string &msg, const bool)
Error reporting function for stacked timer.
Stores the column widths for output alignment.