53 level_(std::numeric_limits<unsigned>::max()),name_(
"INVALID"),parent_(nullptr)
64 for (
unsigned i=0; i<level_; ++i)
66 os << name_<<
":"<<
accumulatedTime()<<
" [" << count_started_<<
"] ("<< count_updates_ <<
")"<<std::endl;
68 for (
size_t i=0; i<sub_timers_.size(); ++i) {
69 t_total += sub_timers_[i].accumulatedTime();
70 sub_timers_[i].report(os);
72 if ( sub_timers_.size() == 0 )
74 for (
unsigned i=0; i<=level_; ++i)
83 if (get_full_name() == name) {
87 for (
unsigned i=0;i<sub_timers_.size(); ++i){
88 t = sub_timers_[i].findBaseTimer(name);
99 auto full_name = get_full_name();
100 if (full_name.size() > name.size())
102 if ( strncmp(full_name.c_str(), name.c_str(), full_name.size()))
104 if (get_full_name() == name) {
109 for (
unsigned i=0;i<sub_timers_.size(); ++i){
110 t = sub_timers_[i].findTimer(name,found);
164 hist_[i].resize(num_names);
172 updates.
resize(num_names);
180 for (
int i=0;i<num_names; ++i) {
185 used[i] = t.count==0? 0:1;
187 updates[i] = t.updates;
197 for (
int i=0;i<num_names;++i)
201 for (
int i=0;i<num_names;++i)
207 int commRank = comm->getRank();
208 for (
int i=0;i<num_names; ++i) {
209 if (used[i] && (
min_[i]==time[i]))
210 procmin[i] = commRank;
213 if (used[i] && (
max_[i]==time[i]))
214 procmax[i] = commRank;
224 for (
int i=0;i<num_names; ++i) {
230 int bin=(time[i]-
min_[i])/dh;
231 bins[i] = std::max(std::min(bin,options.
num_histogram-1) , 0);
237 for (
int i=0;i<num_names; ++i) {
248 for (
int i=0;i<num_names; ++i)
255 std::pair<std::string, std::string>
getPrefix(
const std::string &name) {
256 for (std::size_t i=name.size()-1; i>0; --i)
257 if (name[i] ==
'@') {
258 return std::pair<std::string, std::string>(name.substr(0,i), name.substr(i+1));
260 return std::pair<std::string, std::string>(std::string(
""), name);
266 std::vector<bool> &printed,
272 double total_time = 0.0;
280 if ( (level != print_level) || (level >= options.
max_levels) )
283 if ( prefix != split_names.first)
288 std::ostringstream os;
289 for (
int l=0; l<level; ++l)
292 os << split_names.second <<
": ";
298 std::ostringstream os;
305 std::ostringstream os;
306 os <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
312 std::ostringstream os;
319 std::ostringstream os;
327 std::ostringstream os;
328 os <<
" {min=" <<
min_[i];
332 std::ostringstream os;
333 os <<
", max=" <<
max_[i];
339 std::ostringstream os;
346 std::ostringstream os;
353 std::ostringstream os;
361 std::ostringstream os;
365 os <<
", "<<
hist_[h][i];
379 std::ostringstream tmp;
380 for (
int l=0; l<=level; ++l)
382 tmp <<
"Remainder: ";
386 std::ostringstream tmp;
391 std::ostringstream tmp;
410 double total_time = 0.0;
419 if ( (level != print_level) || (level >= options.
max_levels) )
422 if ( prefix != split_names.first)
427 std::ostringstream tmp;
428 for (
int l=0; l<level; ++l) {
432 tmp << split_names.second <<
": ";
439 std::ostringstream tmp;
447 std::ostringstream tmp;
448 tmp <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
460 std::ostringstream tmp;
468 std::ostringstream tmp;
477 std::ostringstream tmp;
478 tmp <<
" {min="<<
min_[i];
484 std::ostringstream tmp;
485 tmp <<
", max="<<
max_[i];
493 std::ostringstream tmp;
502 std::ostringstream tmp;
511 std::ostringstream tmp;
522 for (
size_t j=0; j < offset; ++j)
528 std::ostringstream tmp;
532 tmp <<
", "<<
hist_[h][i];
548 std::ostringstream tmp;
550 for (
int l=0; l<level; ++l) {
554 tmp << split_names.second <<
": ";
565 std::ostringstream tmp;
566 for (
int l=0; l<=level; ++l)
568 tmp <<
"Remainder: ";
574 std::ostringstream tmp;
583 std::ostringstream tmp;
597 for (
size_t j=0; j < offset; ++j)
600 std::ostringstream tmp;
602 for (
int l=0; l<=level; ++l)
604 tmp <<
"Remainder: ";
652 StackedTimer::printLevelXML (std::string prefix,
int print_level, std::ostream& os, std::vector<bool> &printed,
double parent_time,
const std::string& rootName)
654 constexpr
int indSpaces = 2;
655 int indent = indSpaces * print_level;
657 double total_time = 0.0;
663 if ( level != print_level)
666 if ( prefix != split_names.first)
669 for (
int j = 0; j < indent; j++)
671 os <<
"<timing name=\"";
672 if(level == 0 && rootName.length())
680 std::ostringstream osInner;
682 std::string innerContents = osInner.str();
683 if(innerContents.length())
689 for (
int j = 0; j < indent + indSpaces; j++)
691 os <<
"<timing name=\"Remainder\" value=\"" << (
sum_[i]/
active_[i] - sub_time) <<
"\"/>\n";
694 for (
int j = 0; j < indent; j++)
711 if (rank(*comm) == 0 ) {
713 os <<
"*** Teuchos::StackedTimer::report() - Remainder for a level will be ***"
714 <<
"\n*** incorrect if a timer in the level does not exist on every rank ***"
715 <<
"\n*** of the MPI Communicator. ***"
719 os <<
"Teuchos::StackedTimer::report() - max_levels manually set to " << options.
max_levels
720 <<
". \nTo print more levels, increase value of OutputOptions::max_levels." << std::endl;
725 os <<
"Teuchos::StackedTimer::report() - option print_names_before_values=false "
726 <<
"\nrequires that the option align_columns=true too. Setting the value for "
727 <<
"\nalign_column to true."
745 if (rank(*comm) == 0 ) {
747 os <<
"<?xml version=\"1.0\"?>\n";
748 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
750 os <<
"</performance-report>\n";
756 const char* rawWatchrDir = getenv(
"WATCHR_PERF_DIR");
757 const char* rawBuildName = getenv(
"WATCHR_BUILD_NAME");
758 const char* rawGitSHA = getenv(
"TRILINOS_GIT_SHA");
759 const char* rawBuildDateOverride = getenv(
"WATCHR_BUILD_DATE");
763 std::string watchrDir = rawWatchrDir;
764 if(!watchrDir.length())
770 std::string buildName = rawBuildName ? rawBuildName :
"";
771 std::string datestamp;
772 std::string timestamp;
778 tstruct = gmtime(&t);
779 if(rawBuildDateOverride)
782 int year = 0, month = 0, day = 0;
783 sscanf(rawBuildDateOverride,
"%d_%d_%d", &year, &month, &day);
785 if(year <= 2000 || year > 2100)
786 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid year or is not in YYYY_MM_DD format.");
787 if(month < 1 || month > 12)
788 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid month or is not in YYYY_MM_DD format.");
789 if(day < 1 || day > 31)
790 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid day or is not in YYYY_MM_DD format.");
791 snprintf(buf, 256,
"%04d_%02d_%02d", year, month, day);
793 strftime(buf, 256,
"T%H:%M:%S", tstruct);
794 std::string justTime = buf;
795 snprintf(buf, 256,
"%04d-%02d-%02d", year, month, day);
796 timestamp = std::string(buf) + justTime;
800 strftime(buf, 256,
"%Y_%m_%d", tstruct);
802 strftime(buf, 256,
"%FT%H:%M:%S", tstruct);
808 std::string fullFile;
810 if(rank(*comm) == 0) {
811 std::string nameNoSpaces = name;
812 for(
char& c : nameNoSpaces)
817 if(buildName.length())
820 std::string buildNameNoSpaces = buildName;
821 for(
char& c : buildNameNoSpaces)
826 fullFile = watchrDir +
'/' + buildNameNoSpaces +
"-" + nameNoSpaces +
'_' + datestamp +
".xml";
829 fullFile = watchrDir +
'/' + nameNoSpaces +
'_' + datestamp +
".xml";
830 std::ofstream os(fullFile);
832 os <<
"<?xml version=\"1.0\"?>\n";
833 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
836 std::string gitSHA(rawGitSHA);
838 if(gitSHA.length() > 10)
839 gitSHA = gitSHA.substr(0, 10);
840 os <<
" <metadata key=\"Trilinos Version\" value=\"" << gitSHA <<
"\"/>\n";
842 printLevelXML(
"", 0, os, printed, 0.0, buildName +
": " + name);
843 os <<
"</performance-report>\n";
880 return static_cast<double>(
count_[i]) / static_cast<double>(
active_[i]);
886 "ERROR: StackedTimer::getAverageMpiTime() - must call aggregateMpiData() first!");
891 "ERROR: StackedTimer::getAverageMpiTime() - the timer named \""
892 << flat_timer_name <<
"\" does not exist!");
895 return static_cast<int>(i);
901 "ERROR: StackedTimer::isTimer() - must call aggregateMpiData() before using this query!");
bool isTimer(const std::string &flat_timer_name)
void setVerboseOstream(const Teuchos::RCP< std::ostream > &os)
Set the ostream for verbose mode(defaults to std::cout).
std::string::size_type timer_names_
std::string::size_type histogram_
std::string::size_type average_time_
std::string::size_type total_updates_
std::string::size_type procmax_
void addTimerNames(Array< std::string > &names, unsigned &pos)
void enableVerboseTimestamps(const unsigned levels)
Enable timestamps in verbose mode for the number of levels specified.
void enableVerbose(const bool enable_verbose)
If set to true, print timer start/stop to verbose ostream.
void merge(Teuchos::RCP< const Teuchos::Comm< int > > comm)
std::string::size_type max_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
void reduce< int, double >(const double sendBuf[], double recvBuf[], const int count, const EReductionType reductType, const int root, const Comm< int > &comm)
std::string::size_type procmin_
bool enable_verbose_
If set to true, prints to the debug ostream. At construction, default value is set from environment v...
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
double printLevelXML(std::string prefix, int level, std::ostream &os, std::vector< bool > &printed, double parent_time, const std::string &rootName="")
double getMpiAverageCount(const std::string &flat_timer_name)
bool enable_timers_
Used to disable timers for asynchronous work.
std::string reportWatchrXML(const std::string &name, Teuchos::RCP< const Teuchos::Comm< int > > comm)
unsigned verbose_timestamp_levels_
If set to a value greater than 0, verbose mode will print that many levels of timers with timestamps...
BaseTimer::TimeInfo findTimer(const std::string &name, bool &found)
double printLevel(std::string prefix, int level, std::ostream &os, std::vector< bool > &printed, double parent_time, const OutputOptions &options)
double accumulatedTime(const std::string &name="")
std::string::size_type fraction_
std::string::size_type count_
void report(std::ostream &os)
void error_out(const std::string &msg, const bool)
Error reporting function for stacked timer.
The basic timer used internally, uses std::chrono::high_resolution_clock.
static void printXMLEscapedString(std::ostream &os, const std::string &str)
double computeColumnWidthsForAligment(std::string prefix, int print_level, std::vector< bool > &printed, double parent_time, const OutputOptions &options)
void reportXML(std::ostream &os, const std::string &datestamp, const std::string ×tamp, Teuchos::RCP< const Teuchos::Comm< int > > comm)
Array< Array< int > > hist_
void collectRemoteData(Teuchos::RCP< const Teuchos::Comm< int > > comm, const OutputOptions &options)
bool print_names_before_values
Array< unsigned long long > updates_
void mergeCounterNames(const Comm< int > &comm, const Array< std::string > &localNames, Array< std::string > &globalNames, const ECounterSetOp setOp)
Merge counter names over all processors.
std::string::size_type min_
void resize(size_type new_size, const value_type &x=value_type())
Teuchos::RCP< std::ostream > verbose_ostream_
For debugging, this is the ostream used for printing.
LevelTimer timer_
Base timer.
double getMpiAverageTime(const std::string &flat_timer_name)
Array< std::string > flat_names_
int getFlatNameIndex(const std::string &flat_timer_name)
bool global_mpi_aggregation_called_
void report(std::ostream &os)
LevelTimer()
Default constructor, shouldn't be used but needed for std::vector.
const BaseTimer * findBaseTimer(const std::string &name) const
void aggregateMpiData(Teuchos::RCP< const Teuchos::Comm< int > > comm, OutputOptions options=OutputOptions())
Smart reference counting pointer class for automatic garbage collection.
Array< unsigned long > count_
std::string::size_type stddev_
bool output_total_updates
std::pair< std::string, std::string > getPrefix(const std::string &name)
struct Teuchos::StackedTimer::AlignmentWidths alignments_