10#include "Teuchos_StackedTimer.hpp"
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);
68 BaseTimer::TimeInfo t;
74 if (get_full_name() == name) {
75 t = BaseTimer::TimeInfo(
this);
79 for (
unsigned i=0;
i<sub_timers_.size(); ++
i){
80 t = sub_timers_[
i].findTimer(name,
found);
125 if (
options.output_proc_minmax) {
131 if (
options.output_histogram ) {
132 hist_.resize(
options.num_histogram);
137 if (
options.output_per_proc_stddev) {
146 if (
options.output_total_updates)
151 if (
options.output_per_proc_stddev)
163 used[
i] = t.count==0? 0:1;
164 if (
options.output_total_updates)
165 updates[
i] = t.updates;
166 if (
options.output_per_proc_stddev)
184 if (procmin_.
size()) {
189 if (
used[
i] && (min_[
i]==time[
i]))
193 if (
used[
i] && (max_[
i]==time[
i]))
203 if (
options.output_histogram) {
206 double dh = (max_[
i]-min_[
i])/
options.num_histogram;
227 if (sum_sq_.
size()) {
233 if (
options.output_per_proc_stddev) {
240std::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);
259 for (
int i=0;
i<flat_names_.
size(); ++
i ) {
260 if (sum_[
i]/active_[
i] <=
options.drop_time)
264 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
273 std::ostringstream os;
274 for (
int l=0;
l<level; ++
l)
278 alignments_.timer_names_= std::max(alignments_.timer_names_,os.str().size());
283 std::ostringstream os;
284 os << sum_[
i]/active_[
i];
285 alignments_.average_time_ = std::max(alignments_.average_time_,os.str().size());
290 std::ostringstream os;
292 alignments_.fraction_ = std::max(alignments_.fraction_,os.str().size());
297 std::ostringstream os;
298 os <<
" ["<<count_[
i]/active_[
i]<<
"]";
299 alignments_.count_ = std::max(alignments_.count_,os.str().size());
303 if (
options.output_total_updates) {
304 std::ostringstream os;
305 os <<
" ("<<updates_[
i]/active_[
i]<<
")";
306 alignments_.total_updates_ = std::max(alignments_.total_updates_,os.str().size());
310 if (
options.output_minmax && active_[
i]>1) {
312 std::ostringstream os;
313 os <<
" {min=" << min_[
i];
314 alignments_.min_ = std::max(alignments_.min_,os.str().size());
317 std::ostringstream os;
318 os <<
", max=" << max_[
i];
321 alignments_.max_ = std::max(alignments_.max_,os.str().size());
323 if (procmin_.
size()) {
324 std::ostringstream os;
325 os <<
", proc min=" << procmin_[
i];
328 alignments_.procmin_ = std::min(alignments_.procmin_,os.str().size());
330 if (procmax_.
size()) {
331 std::ostringstream os;
332 os <<
", proc max=" << procmax_[
i];
335 alignments_.procmax_ = std::max(alignments_.procmax_,os.str().size());
338 std::ostringstream os;
339 os <<
", std dev=" <<
sqrt(std::max<double>(sum_sq_[
i]-sum_[
i]*sum_[
i]/active_[
i],0.0)/(active_[
i]-1));
341 alignments_.stddev_ = std::max(alignments_.stddev_,os.str().size());
345 if (
options.output_histogram && active_[
i] >1 ) {
346 std::ostringstream os;
350 os <<
", "<<hist_[
h][
i];
355 alignments_.histogram_ = std::max(alignments_.histogram_,os.str().size());
363 if (
options.print_names_before_values) {
364 std::ostringstream
tmp;
365 for (
int l=0;
l<=level; ++
l)
367 tmp <<
"Remainder: ";
368 alignments_.timer_names_ = std::max(alignments_.timer_names_,
tmp.str().size());
371 std::ostringstream
tmp;
373 alignments_.average_time_ = std::max(alignments_.average_time_,
tmp.str().size());
375 if (
options.output_fraction && (sum_[
i]/active_[
i] > 0.) ) {
376 std::ostringstream
tmp;
377 tmp <<
" - "<< (sum_[
i]/active_[
i]-
sub_time)/(sum_[
i]/active_[
i])*100 <<
"%";
378 alignments_.fraction_ = std::max(alignments_.fraction_,
tmp.str().size());
397 for (
int i=0;
i<flat_names_.
size(); ++
i ) {
398 if (sum_[
i]/active_[
i] <=
options.drop_time) {
403 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
411 if (
options.print_names_before_values) {
412 std::ostringstream
tmp;
413 for (
int l=0;
l<level; ++
l) {
419 os << std::left << std::setw(alignments_.timer_names_);
424 std::ostringstream
tmp;
425 tmp << sum_[
i]/active_[
i];
427 os << std::left << std::setw(alignments_.average_time_);
432 std::ostringstream
tmp;
435 os << std::left << std::setw(alignments_.fraction_);
439 else if (
options.output_fraction) {
441 os << std::setw(alignments_.fraction_) <<
" ";
445 std::ostringstream
tmp;
446 tmp <<
" ["<<count_[
i]/active_[
i]<<
"]";
448 os << std::left << std::setw(alignments_.count_);
452 if (
options.output_total_updates ) {
453 std::ostringstream
tmp;
454 tmp <<
" ("<<updates_[
i]/active_[
i]<<
")";
456 os << std::left << std::setw(alignments_.total_updates_);
460 if (
options.output_minmax && active_[
i]>1) {
462 std::ostringstream
tmp;
463 tmp <<
" {min="<<min_[
i];
465 os << std::left << std::setw(alignments_.min_);
469 std::ostringstream
tmp;
470 tmp <<
", max="<<max_[
i];
474 os << std::left << std::setw(alignments_.max_);
477 if (procmin_.
size()) {
478 std::ostringstream
tmp;
479 tmp <<
", proc min="<<procmin_[
i];
483 os << std::left << std::setw(alignments_.procmin_);
486 if (procmax_.
size()) {
487 std::ostringstream
tmp;
488 tmp <<
", proc max="<<procmax_[
i];
492 os << std::left << std::setw(alignments_.procmax_);
496 std::ostringstream
tmp;
497 tmp <<
", std dev="<<
sqrt(std::max<double>(sum_sq_[
i]-sum_[
i]*sum_[
i]/active_[
i],0.0)/(active_[
i]-1));
500 os << std::left << std::setw(alignments_.stddev_);
504 else if (
options.output_minmax) {
506 size_t offset = alignments_.min_ + alignments_.max_ + alignments_.stddev_;
512 if (
options.output_histogram && active_[
i] >1 ) {
513 std::ostringstream
tmp;
517 tmp <<
", "<<hist_[
h][
i];
523 os << std::left << std::setw(alignments_.histogram_);
526 else if (
options.output_histogram) {
528 for (
size_t j=0;
j < alignments_.histogram_; ++
j)
532 if (
options.output_per_proc_stddev) {
533 std::ostringstream
tmp;
534 tmp <<
", std dev per proc min/max=";
535 tmp << per_proc_stddev_min_[
i];
537 tmp << per_proc_stddev_max_[
i];
541 if (!
options.print_names_before_values) {
542 std::ostringstream
tmp;
544 for (
int l=0;
l<level; ++
l) {
558 if (
options.print_names_before_values) {
559 std::ostringstream
tmp;
560 for (
int l=0;
l<=level; ++
l)
562 tmp <<
"Remainder: ";
564 os << std::left << std::setw(alignments_.timer_names_);
568 std::ostringstream
tmp;
571 os << std::left << std::setw(alignments_.average_time_);
574 if (
options.output_fraction && (sum_[
i]/active_[
i] > 0.) ) {
576 os << std::left << std::setw(alignments_.fraction_);
577 std::ostringstream
tmp;
578 tmp <<
" - "<< (sum_[
i]/active_[
i]-
sub_time)/(sum_[
i]/active_[
i])*100 <<
"%";
581 if (!
options.print_names_before_values) {
584 offset += alignments_.count_;
585 if (
options.output_total_updates)
586 offset += alignments_.total_updates_;
588 offset += alignments_.min_ + alignments_.max_ + alignments_.stddev_;
590 offset += alignments_.histogram_;
594 std::ostringstream
tmp;
596 for (
int l=0;
l<=level; ++
l)
598 tmp <<
"Remainder: ";
600 os << std::left << std::setw(alignments_.timer_names_);
610static void printXMLEscapedString(std::ostream& os,
const std::string&
str)
653 for (
int i=0;
i<flat_names_.
size(); ++
i) {
656 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
663 for (
int j = 0;
j < indent;
j++)
665 os <<
"<timing name=\"";
667 printXMLEscapedString(os,
rootName);
670 os <<
"\" value=\"" << sum_[
i]/active_[
i] <<
"\"";
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;
716 if ( (!
options.print_names_before_values) && (!
options.align_columns)) {
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."
725 std::vector<bool>
printed(flat_names_.
size(),
false);
729 std::vector<bool>
printed(flat_names_.
size(),
false);
739 if (rank(*
comm) == 0 ) {
740 std::vector<bool>
printed(flat_names_.
size(),
false);
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";
780 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid year or is not in YYYY_MM_DD format.");
782 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid month or is not in YYYY_MM_DD format.");
784 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid day or is not in YYYY_MM_DD format.");
804 if(rank(*
comm) == 0) {
825 std::vector<bool>
printed(flat_names_.
size(),
false);
826 os <<
"<?xml version=\"1.0\"?>\n";
827 os <<
"<performance-report date=\"" <<
timestamp <<
"\" name=\"nightly_run_" <<
datestamp <<
"\" time-units=\"seconds\">\n";
834 os <<
" <metadata key=\"Trilinos Version\" value=\"" <<
gitSHA <<
"\"/>\n";
837 os <<
"</performance-report>\n";
862 global_mpi_aggregation_called_ =
true;
868 return sum_[
i] / active_[
i];
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 \""
889 return static_cast<int>(
i);
895 "ERROR: StackedTimer::isTimer() - must call aggregateMpiData() before using this query!");
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 internally, uses std::chrono::high_resolution_clock.
Smart reference counting pointer class for automatic garbage collection.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
void report(std::ostream &os)
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.
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)
double getMpiAverageTime(const std::string &flat_timer_name)
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="")
void enableVerboseTimestamps(const unsigned levels)
Enable timestamps in verbose mode for the number of levels specified.
int getFlatNameIndex(const std::string &flat_timer_name)
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.
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 aggregateMpiData(Teuchos::RCP< const Teuchos::Comm< int > > comm, OutputOptions options=OutputOptions())
void merge(Teuchos::RCP< const Teuchos::Comm< int > > comm)
bool isTimer(const std::string &flat_timer_name)
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)
double getMpiAverageCount(const std::string &flat_timer_name)
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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
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 error_out(const std::string &msg, const bool)
Error reporting function for stacked timer.