23 level_(std::numeric_limits<unsigned>::max()),name_(
"INVALID"),parent_(nullptr)
34 for (
unsigned i=0; i<level_; ++i)
36 os << name_<<
":"<<
accumulatedTime()<<
" [" << count_started_<<
"] ("<< count_updates_ <<
")"<<std::endl;
38 for (
size_t i=0; i<sub_timers_.size(); ++i) {
39 t_total += sub_timers_[i].accumulatedTime();
40 sub_timers_[i].report(os);
42 if ( sub_timers_.size() == 0 )
44 for (
unsigned i=0; i<=level_; ++i)
53 if (get_full_name() == name) {
57 for (
unsigned i=0;i<sub_timers_.size(); ++i){
58 t = sub_timers_[i].findBaseTimer(name);
69 auto full_name = get_full_name();
70 if (full_name.size() > name.size())
72 if ( strncmp(full_name.c_str(), name.c_str(), full_name.size()))
74 if (get_full_name() == name) {
79 for (
unsigned i=0;i<sub_timers_.size(); ++i){
80 t = sub_timers_[i].findTimer(name,found);
134 hist_[i].resize(num_names);
147 updates.
resize(num_names);
152 per_proc_stddev.
resize(num_names);
158 for (
int i=0;i<num_names; ++i) {
163 used[i] = t.count==0? 0:1;
165 updates[i] = t.updates;
167 per_proc_stddev[i] = t.stdDev;
177 for (
int i=0;i<num_names;++i)
181 for (
int i=0;i<num_names;++i)
187 int commRank = comm->getRank();
188 for (
int i=0;i<num_names; ++i) {
189 if (used[i] && (
min_[i]==time[i]))
190 procmin[i] = commRank;
193 if (used[i] && (
max_[i]==time[i]))
194 procmax[i] = commRank;
204 for (
int i=0;i<num_names; ++i) {
210 int bin=(time[i]-
min_[i])/dh;
211 bins[i] = std::max(std::min(bin,options.
num_histogram-1) , 0);
217 for (
int i=0;i<num_names; ++i) {
228 for (
int i=0;i<num_names; ++i)
240 std::pair<std::string, std::string>
getPrefix(
const std::string &name) {
241 for (std::size_t i=name.size()-1; i>0; --i)
242 if (name[i] ==
'@') {
243 return std::pair<std::string, std::string>(name.substr(0,i), name.substr(i+1));
245 return std::pair<std::string, std::string>(std::string(
""), name);
251 std::vector<bool> &printed,
257 double total_time = 0.0;
265 if ( (level != print_level) || (level >= options.
max_levels) )
268 if ( prefix != split_names.first)
273 std::ostringstream os;
274 for (
int l=0; l<level; ++l)
277 os << split_names.second <<
": ";
283 std::ostringstream os;
290 std::ostringstream os;
291 os <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
297 std::ostringstream os;
304 std::ostringstream os;
312 std::ostringstream os;
313 os <<
" {min=" <<
min_[i];
317 std::ostringstream os;
318 os <<
", max=" <<
max_[i];
324 std::ostringstream os;
331 std::ostringstream os;
338 std::ostringstream os;
346 std::ostringstream os;
350 os <<
", "<<
hist_[h][i];
364 std::ostringstream tmp;
365 for (
int l=0; l<=level; ++l)
367 tmp <<
"Remainder: ";
371 std::ostringstream tmp;
376 std::ostringstream tmp;
395 double total_time = 0.0;
404 if ( (level != print_level) || (level >= options.
max_levels) )
407 if ( prefix != split_names.first)
412 std::ostringstream tmp;
413 for (
int l=0; l<level; ++l) {
417 tmp << split_names.second <<
": ";
424 std::ostringstream tmp;
432 std::ostringstream tmp;
433 tmp <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
445 std::ostringstream tmp;
453 std::ostringstream tmp;
462 std::ostringstream tmp;
463 tmp <<
" {min="<<
min_[i];
469 std::ostringstream tmp;
470 tmp <<
", max="<<
max_[i];
478 std::ostringstream tmp;
487 std::ostringstream tmp;
496 std::ostringstream tmp;
507 for (
size_t j=0; j < offset; ++j)
513 std::ostringstream tmp;
517 tmp <<
", "<<
hist_[h][i];
533 std::ostringstream tmp;
534 tmp <<
", std dev per proc min/max=";
542 std::ostringstream tmp;
544 for (
int l=0; l<level; ++l) {
548 tmp << split_names.second <<
": ";
559 std::ostringstream tmp;
560 for (
int l=0; l<=level; ++l)
562 tmp <<
"Remainder: ";
568 std::ostringstream tmp;
577 std::ostringstream tmp;
591 for (
size_t j=0; j < offset; ++j)
594 std::ostringstream tmp;
596 for (
int l=0; l<=level; ++l)
598 tmp <<
"Remainder: ";
646 StackedTimer::printLevelXML (std::string prefix,
int print_level, std::ostream& os, std::vector<bool> &printed,
double parent_time,
const std::string& rootName)
648 constexpr
int indSpaces = 2;
649 int indent = indSpaces * print_level;
651 double total_time = 0.0;
657 if ( level != print_level)
660 if ( prefix != split_names.first)
663 for (
int j = 0; j < indent; j++)
665 os <<
"<timing name=\"";
666 if(level == 0 && rootName.length())
674 std::ostringstream osInner;
676 std::string innerContents = osInner.str();
677 if(innerContents.length())
683 for (
int j = 0; j < indent + indSpaces; j++)
685 os <<
"<timing name=\"Remainder\" value=\"" << (
sum_[i]/
active_[i] - sub_time) <<
"\"/>\n";
688 for (
int j = 0; j < indent; j++)
705 if (rank(*comm) == 0 ) {
707 os <<
"*** Teuchos::StackedTimer::report() - Remainder for a level will be ***"
708 <<
"\n*** incorrect if a timer in the level does not exist on every rank ***"
709 <<
"\n*** of the MPI Communicator. ***"
713 os <<
"Teuchos::StackedTimer::report() - max_levels manually set to " << options.
max_levels
714 <<
". \nTo print more levels, increase value of OutputOptions::max_levels." << std::endl;
719 os <<
"Teuchos::StackedTimer::report() - option print_names_before_values=false "
720 <<
"\nrequires that the option align_columns=true too. Setting the value for "
721 <<
"\nalign_column to true."
739 if (rank(*comm) == 0 ) {
741 os <<
"<?xml version=\"1.0\"?>\n";
742 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
744 os <<
"</performance-report>\n";
750 const char* rawWatchrDir = getenv(
"WATCHR_PERF_DIR");
751 const char* rawBuildName = getenv(
"WATCHR_BUILD_NAME");
752 const char* rawGitSHA = getenv(
"TRILINOS_GIT_SHA");
753 const char* rawBuildDateOverride = getenv(
"WATCHR_BUILD_DATE");
757 std::string watchrDir = rawWatchrDir;
758 if(!watchrDir.length())
764 std::string buildName = rawBuildName ? rawBuildName :
"";
765 std::string datestamp;
766 std::string timestamp;
772 tstruct = gmtime(&t);
773 if(rawBuildDateOverride)
776 int year = 0, month = 0, day = 0;
777 sscanf(rawBuildDateOverride,
"%d_%d_%d", &year, &month, &day);
779 if(year <= 2000 || year > 2100)
780 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid year or is not in YYYY_MM_DD format.");
781 if(month < 1 || month > 12)
782 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid month or is not in YYYY_MM_DD format.");
783 if(day < 1 || day > 31)
784 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid day or is not in YYYY_MM_DD format.");
785 snprintf(buf, 256,
"%04d_%02d_%02d", year, month, day);
787 strftime(buf, 256,
"T%H:%M:%S", tstruct);
788 std::string justTime = buf;
789 snprintf(buf, 256,
"%04d-%02d-%02d", year, month, day);
790 timestamp = std::string(buf) + justTime;
794 strftime(buf, 256,
"%Y_%m_%d", tstruct);
796 strftime(buf, 256,
"%FT%H:%M:%S", tstruct);
802 std::string fullFile;
804 if(rank(*comm) == 0) {
805 std::string nameNoSpaces = name;
806 for(
char& c : nameNoSpaces)
811 if(buildName.length())
814 std::string buildNameNoSpaces = buildName;
815 for(
char& c : buildNameNoSpaces)
820 fullFile = watchrDir +
'/' + buildNameNoSpaces +
"-" + nameNoSpaces +
'_' + datestamp +
".xml";
823 fullFile = watchrDir +
'/' + nameNoSpaces +
'_' + datestamp +
".xml";
824 std::ofstream os(fullFile);
826 os <<
"<?xml version=\"1.0\"?>\n";
827 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
830 std::string gitSHA(rawGitSHA);
832 if(gitSHA.length() > 10)
833 gitSHA = gitSHA.substr(0, 10);
834 os <<
" <metadata key=\"Trilinos Version\" value=\"" << gitSHA <<
"\"/>\n";
836 printLevelXML(
"", 0, os, printed, 0.0, buildName +
": " + name);
837 os <<
"</performance-report>\n";
874 return static_cast<double>(
count_[i]) / static_cast<double>(
active_[i]);
880 "ERROR: StackedTimer::getAverageMpiTime() - must call aggregateMpiData() first!");
885 "ERROR: StackedTimer::getAverageMpiTime() - the timer named \""
886 << flat_timer_name <<
"\" does not exist!");
889 return static_cast<int>(i);
895 "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_
Array< double > per_proc_stddev_max_
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="")
Array< double > per_proc_stddev_min_
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_
bool output_per_proc_stddev
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_