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);
163 hist_[i].resize(num_names);
171 updates.
resize(num_names);
179 for (
int i=0;i<num_names; ++i) {
184 used[i] = t.count==0? 0:1;
186 updates[i] = t.updates;
196 for (
int i=0;i<num_names;++i)
200 for (
int i=0;i<num_names;++i)
206 int commRank = comm->getRank();
207 for (
int i=0;i<num_names; ++i) {
208 if (used[i] && (
min_[i]==time[i]))
209 procmin[i] = commRank;
212 if (used[i] && (
max_[i]==time[i]))
213 procmax[i] = commRank;
223 for (
int i=0;i<num_names; ++i) {
229 int bin=(time[i]-
min_[i])/dh;
230 bins[i] = std::max(std::min(bin,options.
num_histogram-1) , 0);
236 for (
int i=0;i<num_names; ++i) {
247 for (
int i=0;i<num_names; ++i)
254std::pair<std::string, std::string>
getPrefix(
const std::string &name) {
255 for (std::size_t i=name.size()-1; i>0; --i)
256 if (name[i] ==
'@') {
257 return std::pair<std::string, std::string>(name.substr(0,i), name.substr(i+1));
259 return std::pair<std::string, std::string>(std::string(
""), name);
265 std::vector<bool> &printed,
271 double total_time = 0.0;
279 if ( (level != print_level) || (level >= options.
max_levels) )
282 if ( prefix != split_names.first)
287 std::ostringstream os;
288 for (
int l=0; l<level; ++l)
291 os << split_names.second <<
": ";
297 std::ostringstream os;
304 std::ostringstream os;
305 os <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
311 std::ostringstream os;
318 std::ostringstream os;
326 std::ostringstream os;
327 os <<
" {min=" <<
min_[i];
331 std::ostringstream os;
332 os <<
", max=" <<
max_[i];
338 std::ostringstream os;
345 std::ostringstream os;
352 std::ostringstream os;
360 std::ostringstream os;
364 os <<
", "<<
hist_[h][i];
378 std::ostringstream tmp;
379 for (
int l=0; l<=level; ++l)
381 tmp <<
"Remainder: ";
385 std::ostringstream tmp;
390 std::ostringstream tmp;
409 double total_time = 0.0;
418 if ( (level != print_level) || (level >= options.
max_levels) )
421 if ( prefix != split_names.first)
426 std::ostringstream tmp;
427 for (
int l=0; l<level; ++l) {
431 tmp << split_names.second <<
": ";
438 std::ostringstream tmp;
446 std::ostringstream tmp;
447 tmp <<
" - "<<
sum_[i]/
active_[i]/parent_time*100<<
"%";
459 std::ostringstream tmp;
467 std::ostringstream tmp;
476 std::ostringstream tmp;
477 tmp <<
" {min="<<
min_[i];
483 std::ostringstream tmp;
484 tmp <<
", max="<<
max_[i];
492 std::ostringstream tmp;
501 std::ostringstream tmp;
510 std::ostringstream tmp;
521 for (
size_t j=0; j < offset; ++j)
527 std::ostringstream tmp;
531 tmp <<
", "<<
hist_[h][i];
547 std::ostringstream tmp;
549 for (
int l=0; l<level; ++l) {
553 tmp << split_names.second <<
": ";
564 std::ostringstream tmp;
565 for (
int l=0; l<=level; ++l)
567 tmp <<
"Remainder: ";
573 std::ostringstream tmp;
582 std::ostringstream tmp;
596 for (
size_t j=0; j < offset; ++j)
599 std::ostringstream tmp;
601 for (
int l=0; l<=level; ++l)
603 tmp <<
"Remainder: ";
651StackedTimer::printLevelXML (std::string prefix,
int print_level, std::ostream& os, std::vector<bool> &printed,
double parent_time,
const std::string& rootName)
653 constexpr int indSpaces = 2;
654 int indent = indSpaces * print_level;
656 double total_time = 0.0;
662 if ( level != print_level)
665 if ( prefix != split_names.first)
668 for (
int j = 0; j < indent; j++)
670 os <<
"<timing name=\"";
671 if(level == 0 && rootName.length())
679 std::ostringstream osInner;
681 std::string innerContents = osInner.str();
682 if(innerContents.length())
688 for (
int j = 0; j < indent + indSpaces; j++)
690 os <<
"<timing name=\"Remainder\" value=\"" << (
sum_[i]/
active_[i] - sub_time) <<
"\"/>\n";
693 for (
int j = 0; j < indent; j++)
712 if (rank(*comm) == 0 ) {
714 os <<
"*** Teuchos::StackedTimer::report() - Remainder for a level will be ***"
715 <<
"\n*** incorrect if a timer in the level does not exist on every rank ***"
716 <<
"\n*** of the MPI Communicator. ***"
720 os <<
"Teuchos::StackedTimer::report() - max_levels manually set to " << options.
max_levels
721 <<
". \nTo print more levels, increase value of OutputOptions::max_levels." << std::endl;
726 os <<
"Teuchos::StackedTimer::report() - option print_names_before_values=false "
727 <<
"\nrequires that the option align_columns=true too. Setting the value for "
728 <<
"\nalign_column to true."
748 if (rank(*comm) == 0 ) {
750 os <<
"<?xml version=\"1.0\"?>\n";
751 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
753 os <<
"</performance-report>\n";
759 const char* rawWatchrDir = getenv(
"WATCHR_PERF_DIR");
760 const char* rawBuildName = getenv(
"WATCHR_BUILD_NAME");
761 const char* rawGitSHA = getenv(
"TRILINOS_GIT_SHA");
762 const char* rawBuildDateOverride = getenv(
"WATCHR_BUILD_DATE");
766 std::string watchrDir = rawWatchrDir;
767 if(!watchrDir.length())
773 std::string buildName = rawBuildName ? rawBuildName :
"";
774 std::string datestamp;
775 std::string timestamp;
781 tstruct = gmtime(&t);
782 if(rawBuildDateOverride)
785 int year = 0, month = 0, day = 0;
786 sscanf(rawBuildDateOverride,
"%d_%d_%d", &year, &month, &day);
788 if(year <= 2000 || year > 2100)
789 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid year or is not in YYYY_MM_DD format.");
790 if(month < 1 || month > 12)
791 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid month or is not in YYYY_MM_DD format.");
792 if(day < 1 || day > 31)
793 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid day or is not in YYYY_MM_DD format.");
794 snprintf(buf, 256,
"%04d_%02d_%02d", year, month, day);
796 strftime(buf, 256,
"T%H:%M:%S", tstruct);
797 std::string justTime = buf;
798 snprintf(buf, 256,
"%04d-%02d-%02d", year, month, day);
799 timestamp = std::string(buf) + justTime;
803 strftime(buf, 256,
"%Y_%m_%d", tstruct);
805 strftime(buf, 256,
"%FT%H:%M:%S", tstruct);
813 std::string fullFile;
815 if(rank(*comm) == 0) {
816 std::string nameNoSpaces = name;
817 for(
char& c : nameNoSpaces)
822 if(buildName.length())
825 std::string buildNameNoSpaces = buildName;
826 for(
char& c : buildNameNoSpaces)
831 fullFile = watchrDir +
'/' + buildNameNoSpaces +
"-" + nameNoSpaces +
'_' + datestamp +
".xml";
834 fullFile = watchrDir +
'/' + nameNoSpaces +
'_' + datestamp +
".xml";
835 std::ofstream os(fullFile);
837 os <<
"<?xml version=\"1.0\"?>\n";
838 os <<
"<performance-report date=\"" << timestamp <<
"\" name=\"nightly_run_" << datestamp <<
"\" time-units=\"seconds\">\n";
841 std::string gitSHA(rawGitSHA);
843 if(gitSHA.length() > 10)
844 gitSHA = gitSHA.substr(0, 10);
845 os <<
" <metadata key=\"Trilinos Version\" value=\"" << gitSHA <<
"\"/>\n";
847 printLevelXML(
"", 0, os, printed, 0.0, buildName +
": " + name);
848 os <<
"</performance-report>\n";
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
T * getRawPtr()
Return a raw pointer to beginning of array or NULL if unsized.
void resize(size_type new_size, const value_type &x=value_type())
the basic timer used elsewhere, uses MPI_Wtime for time
Abstract interface for distributed-memory communication.
Smart reference counting pointer class for automatic garbage collection.
void report(std::ostream &os)
void addTimerNames(Array< std::string > &names, unsigned &pos)
BaseTimer::TimeInfo findTimer(const std::string &name, bool &found)
const BaseTimer * findBaseTimer(const std::string &name) const
LevelTimer()
Default constructor, shouldn't be used but needed for std::vector.
struct Teuchos::StackedTimer::AlignmentWidths alignments_
double computeColumnWidthsForAligment(std::string prefix, int print_level, std::vector< bool > &printed, double parent_time, const OutputOptions &options)
void collectRemoteData(Teuchos::RCP< const Teuchos::Comm< int > > comm, const OutputOptions &options)
Array< Array< int > > hist_
Teuchos::RCP< std::ostream > verbose_ostream_
For debugging, this is the ostream used for printing.
double printLevelXML(std::string prefix, int level, std::ostream &os, std::vector< bool > &printed, double parent_time, const std::string &rootName="")
Array< unsigned long long > updates_
void report(std::ostream &os)
void enableVerboseTimestamps(const unsigned levels)
Enable timestamps in verbose mode for the number of levels specified.
Array< std::string > flat_names_
void setVerboseOstream(const Teuchos::RCP< std::ostream > &os)
Set the ostream for verbose mode(defaults to std::cout).
bool enable_timers_
Used to disable timers for asynchronous work.
Array< unsigned long > count_
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...
void merge(Teuchos::RCP< const Teuchos::Comm< int > > comm)
double printLevel(std::string prefix, int level, std::ostream &os, std::vector< bool > &printed, double parent_time, const OutputOptions &options)
void enableVerbose(const bool enable_verbose)
If set to true, print timer start/stop to verbose ostream.
std::string reportWatchrXML(const std::string &name, Teuchos::RCP< const Teuchos::Comm< int > > comm)
void reportXML(std::ostream &os, const std::string &datestamp, const std::string ×tamp, Teuchos::RCP< const Teuchos::Comm< int > > comm)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static void printXMLEscapedString(std::ostream &os, const std::string &str)
std::pair< std::string, std::string > getPrefix(const std::string &name)
void mergeCounterNames(const Comm< int > &comm, const Array< std::string > &localNames, Array< std::string > &globalNames, const ECounterSetOp setOp)
Merge counter names over all processors.
void reduce< int, double >(const double sendBuf[], double recvBuf[], const int count, const EReductionType reductType, const int root, const Comm< int > &comm)
void error_out(const std::string &msg, const bool)
Error reporting function for stacked timer.
std::string::size_type max_
std::string::size_type procmax_
std::string::size_type fraction_
std::string::size_type procmin_
std::string::size_type histogram_
std::string::size_type stddev_
std::string::size_type count_
std::string::size_type total_updates_
std::string::size_type timer_names_
std::string::size_type average_time_
std::string::size_type min_
bool print_names_before_values
bool output_total_updates