52 level_(std::numeric_limits<unsigned>::max()),name_(
"INVALID"),parent_(nullptr)
63 for (
unsigned i=0; i<level_; ++i)
65 os << name_<<
":"<<
accumulatedTime()<<
" [" << count_started_<<
"] ("<< count_updates_ <<
")"<<std::endl;
67 for (
size_t i=0; i<sub_timers_.size(); ++i) {
68 t_total += sub_timers_[i].accumulatedTime();
69 sub_timers_[i].report(os);
71 if ( sub_timers_.size() == 0 )
73 for (
unsigned i=0; i<=level_; ++i)
82 if (get_full_name() == name) {
86 for (
unsigned i=0;i<sub_timers_.size(); ++i){
87 t = sub_timers_[i].findBaseTimer(name);
98 auto full_name = get_full_name();
99 if (full_name.size() > name.size())
101 if ( strncmp(full_name.c_str(), name.c_str(), full_name.size()))
103 if (get_full_name() == name) {
108 for (
unsigned i=0;i<sub_timers_.size(); ++i){
109 t = sub_timers_[i].findTimer(name,found);
157 hist_[i].resize(num_names);
165 updates.
resize(num_names);
173 for (
int i=0;i<num_names; ++i) {
178 used[i] = t.count==0? 0:1;
180 updates[i] = t.updates;
190 for (
int i=0;i<num_names;++i)
194 for (
int i=0;i<num_names;++i)
200 int commRank = comm->getRank();
201 for (
int i=0;i<num_names; ++i) {
202 if (used[i] && (
min_[i]==time[i]))
203 procmin[i] = commRank;
206 if (used[i] && (
max_[i]==time[i]))
207 procmax[i] = commRank;
217 for (
int i=0;i<num_names; ++i) {
223 int bin=(time[i]-
min_[i])/dh;
224 bins[i] = std::max(std::min(bin,options.
num_histogram-1) , 0);
230 for (
int i=0;i<num_names; ++i) {
241 for (
int i=0;i<num_names; ++i)
248 std::pair<std::string, std::string>
getPrefix(
const std::string &name) {
249 for (std::size_t i=name.size()-1; i>0; --i)
250 if (name[i] ==
'@') {
251 return std::pair<std::string, std::string>(name.substr(0,i), name.substr(i+1));
253 return std::pair<std::string, std::string>(std::string(
""), name);
259 std::vector<bool> &printed,
265 double total_time = 0.0;
273 if ( (level != print_level) || (level >= options.
max_levels) )
276 if ( prefix != split_names.first)
281 std::ostringstream os;
282 for (
int l=0; l<level; ++l)
285 os << split_names.second <<
": ";
291 std::ostringstream os;
298 std::ostringstream os;
299 os <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
305 std::ostringstream os;
312 std::ostringstream os;
320 std::ostringstream os;
321 os <<
" {min=" <<
min_[i];
325 std::ostringstream os;
326 os <<
", max=" <<
max_[i];
332 std::ostringstream os;
339 std::ostringstream os;
346 std::ostringstream os;
354 std::ostringstream os;
358 os <<
", "<<
hist_[h][i];
372 std::ostringstream tmp;
373 for (
int l=0; l<=level; ++l)
375 tmp <<
"Remainder: ";
379 std::ostringstream tmp;
384 std::ostringstream tmp;
403 double total_time = 0.0;
412 if ( (level != print_level) || (level >= options.
max_levels) )
415 if ( prefix != split_names.first)
420 std::ostringstream tmp;
421 for (
int l=0; l<level; ++l) {
425 tmp << split_names.second <<
": ";
432 std::ostringstream tmp;
440 std::ostringstream tmp;
441 tmp <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
453 std::ostringstream tmp;
461 std::ostringstream tmp;
470 std::ostringstream tmp;
471 tmp <<
" {min="<<
min_[i];
477 std::ostringstream tmp;
478 tmp <<
", max="<<
max_[i];
486 std::ostringstream tmp;
495 std::ostringstream tmp;
504 std::ostringstream tmp;
515 for (
size_t j=0; j < offset; ++j)
521 std::ostringstream tmp;
525 tmp <<
", "<<
hist_[h][i];
541 std::ostringstream tmp;
543 for (
int l=0; l<level; ++l) {
547 tmp << split_names.second <<
": ";
558 std::ostringstream tmp;
559 for (
int l=0; l<=level; ++l)
561 tmp <<
"Remainder: ";
567 std::ostringstream tmp;
576 std::ostringstream tmp;
590 for (
size_t j=0; j < offset; ++j)
593 std::ostringstream tmp;
595 for (
int l=0; l<=level; ++l)
597 tmp <<
"Remainder: ";
637 StackedTimer::printLevelXML (std::string prefix,
int print_level, std::ostream& os, std::vector<bool> &printed,
double parent_time,
const std::string& rootName)
639 constexpr
int indSpaces = 2;
640 int indent = indSpaces * print_level;
642 double total_time = 0.0;
648 if ( level != print_level)
651 if ( prefix != split_names.first)
654 for (
int j = 0; j < indent; j++)
656 os <<
"<timing name=\"";
657 if(level == 0 && rootName.length())
665 std::ostringstream osInner;
667 std::string innerContents = osInner.str();
668 if(innerContents.length())
674 for (
int j = 0; j < indent + indSpaces; j++)
676 os <<
"<timing name=\"Remainder\" value=\"" << (
sum_[i]/
active_[i] - sub_time) <<
"\"/>\n";
679 for (
int j = 0; j < indent; j++)
698 if (rank(*comm) == 0 ) {
700 os <<
"*** Teuchos::StackedTimer::report() - Remainder for a level will be ***"
701 <<
"\n*** incorrect if a timer in the level does not exist on every rank ***"
702 <<
"\n*** of the MPI Communicator. ***"
706 os <<
"Teuchos::StackedTimer::report() - max_levels manually set to " << options.
max_levels
707 <<
". \nTo print more levels, increase value of OutputOptions::max_levels." << std::endl;
712 os <<
"Teuchos::StackedTimer::report() - option print_names_before_values=false "
713 <<
"\nrequires that the option align_columns=true too. Setting the value for "
714 <<
"\nalign_column to true."
734 if (rank(*comm) == 0 ) {
736 os <<
"<?xml version=\"1.0\"?>\n";
737 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
739 os <<
"</performance-report>\n";
745 const char* rawWatchrDir = getenv(
"WATCHR_PERF_DIR");
746 const char* rawBuildName = getenv(
"WATCHR_BUILD_NAME");
750 std::string watchrDir = rawWatchrDir;
751 if(!watchrDir.length())
757 std::string buildName = rawBuildName ? rawBuildName :
"";
758 std::string datestamp;
759 std::string timestamp;
765 tstruct = gmtime(&t);
766 strftime(buf, 256,
"%Y_%m_%d", tstruct);
768 strftime(buf, 256,
"%FT%H:%M:%S", tstruct);
775 std::string fullFile;
777 if(rank(*comm) == 0) {
778 std::string nameNoSpaces = name;
779 for(
char& c : nameNoSpaces)
784 if(buildName.length())
787 std::string buildNameNoSpaces = buildName;
788 for(
char& c : buildNameNoSpaces)
793 fullFile = watchrDir +
'/' + buildNameNoSpaces +
"-" + nameNoSpaces +
'_' + datestamp +
".xml";
796 fullFile = watchrDir +
'/' + nameNoSpaces +
'_' + datestamp +
".xml";
797 std::ofstream os(fullFile);
799 os <<
"<?xml version=\"1.0\"?>\n";
800 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
801 printLevelXML(
"", 0, os, printed, 0.0, buildName +
": " + name);
802 os <<
"</performance-report>\n";
void setVerboseOstream(const Teuchos::RCP< std::ostream > &os)
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)
void enableVerbose(const bool enable_verbose)
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="")
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)
the basic timer used elsewhere, uses MPI_Wtime for time
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.
void error_out(const std::string &msg, const bool)
Error reporting function for stacked timer.
Array< std::string > flat_names_
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
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_