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);
141 if (
options.output_total_updates)
155 used[
i] = t.count==0? 0:1;
156 if (
options.output_total_updates)
157 updates[
i] = t.updates;
174 if (procmin_.
size()) {
179 if (
used[
i] && (min_[
i]==time[
i]))
183 if (
used[
i] && (max_[
i]==time[
i]))
193 if (
options.output_histogram) {
196 double dh = (max_[
i]-min_[
i])/
options.num_histogram;
217 if (sum_sq_.
size()) {
225std::pair<std::string, std::string> getPrefix(
const std::string &name) {
226 for (std::size_t
i=name.size()-1;
i>0; --
i)
227 if (name[
i] ==
'@') {
228 return std::pair<std::string, std::string>(name.substr(0,
i), name.substr(
i+1));
230 return std::pair<std::string, std::string>(std::string(
""), name);
244 for (
int i=0;
i<flat_names_.
size(); ++
i ) {
245 if (sum_[
i]/active_[
i] <=
options.drop_time)
249 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
258 std::ostringstream os;
259 for (
int l=0;
l<level; ++
l)
263 alignments_.timer_names_= std::max(alignments_.timer_names_,os.str().size());
268 std::ostringstream os;
269 os << sum_[
i]/active_[
i];
270 alignments_.average_time_ = std::max(alignments_.average_time_,os.str().size());
275 std::ostringstream os;
277 alignments_.fraction_ = std::max(alignments_.fraction_,os.str().size());
282 std::ostringstream os;
283 os <<
" ["<<count_[
i]/active_[
i]<<
"]";
284 alignments_.count_ = std::max(alignments_.count_,os.str().size());
288 if (
options.output_total_updates) {
289 std::ostringstream os;
290 os <<
" ("<<updates_[
i]/active_[
i]<<
")";
291 alignments_.total_updates_ = std::max(alignments_.total_updates_,os.str().size());
295 if (
options.output_minmax && active_[
i]>1) {
297 std::ostringstream os;
298 os <<
" {min=" << min_[
i];
299 alignments_.min_ = std::max(alignments_.min_,os.str().size());
302 std::ostringstream os;
303 os <<
", max=" << max_[
i];
306 alignments_.max_ = std::max(alignments_.max_,os.str().size());
308 if (procmin_.
size()) {
309 std::ostringstream os;
310 os <<
", proc min=" << procmin_[
i];
313 alignments_.procmin_ = std::min(alignments_.procmin_,os.str().size());
315 if (procmax_.
size()) {
316 std::ostringstream os;
317 os <<
", proc max=" << procmax_[
i];
320 alignments_.procmax_ = std::max(alignments_.procmax_,os.str().size());
323 std::ostringstream os;
324 os <<
", std dev=" <<
sqrt(std::max<double>(sum_sq_[
i]-sum_[
i]*sum_[
i]/active_[
i],0.0)/(active_[
i]-1));
326 alignments_.stddev_ = std::max(alignments_.stddev_,os.str().size());
330 if (
options.output_histogram && active_[
i] >1 ) {
331 std::ostringstream os;
335 os <<
", "<<hist_[
h][
i];
340 alignments_.histogram_ = std::max(alignments_.histogram_,os.str().size());
348 if (
options.print_names_before_values) {
349 std::ostringstream
tmp;
350 for (
int l=0;
l<=level; ++
l)
352 tmp <<
"Remainder: ";
353 alignments_.timer_names_ = std::max(alignments_.timer_names_,
tmp.str().size());
356 std::ostringstream
tmp;
358 alignments_.average_time_ = std::max(alignments_.average_time_,
tmp.str().size());
360 if (
options.output_fraction && (sum_[
i]/active_[
i] > 0.) ) {
361 std::ostringstream
tmp;
362 tmp <<
" - "<< (sum_[
i]/active_[
i]-
sub_time)/(sum_[
i]/active_[
i])*100 <<
"%";
363 alignments_.fraction_ = std::max(alignments_.fraction_,
tmp.str().size());
382 for (
int i=0;
i<flat_names_.
size(); ++
i ) {
383 if (sum_[
i]/active_[
i] <=
options.drop_time) {
388 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
396 if (
options.print_names_before_values) {
397 std::ostringstream
tmp;
398 for (
int l=0;
l<level; ++
l) {
404 os << std::left << std::setw(alignments_.timer_names_);
409 std::ostringstream
tmp;
410 tmp << sum_[
i]/active_[
i];
412 os << std::left << std::setw(alignments_.average_time_);
417 std::ostringstream
tmp;
420 os << std::left << std::setw(alignments_.fraction_);
424 else if (
options.output_fraction) {
426 os << std::setw(alignments_.fraction_) <<
" ";
430 std::ostringstream
tmp;
431 tmp <<
" ["<<count_[
i]/active_[
i]<<
"]";
433 os << std::left << std::setw(alignments_.count_);
437 if (
options.output_total_updates ) {
438 std::ostringstream
tmp;
439 tmp <<
" ("<<updates_[
i]/active_[
i]<<
")";
441 os << std::left << std::setw(alignments_.total_updates_);
445 if (
options.output_minmax && active_[
i]>1) {
447 std::ostringstream
tmp;
448 tmp <<
" {min="<<min_[
i];
450 os << std::left << std::setw(alignments_.min_);
454 std::ostringstream
tmp;
455 tmp <<
", max="<<max_[
i];
459 os << std::left << std::setw(alignments_.max_);
462 if (procmin_.
size()) {
463 std::ostringstream
tmp;
464 tmp <<
", proc min="<<procmin_[
i];
468 os << std::left << std::setw(alignments_.procmin_);
471 if (procmax_.
size()) {
472 std::ostringstream
tmp;
473 tmp <<
", proc max="<<procmax_[
i];
477 os << std::left << std::setw(alignments_.procmax_);
481 std::ostringstream
tmp;
482 tmp <<
", std dev="<<
sqrt(std::max<double>(sum_sq_[
i]-sum_[
i]*sum_[
i]/active_[
i],0.0)/(active_[
i]-1));
485 os << std::left << std::setw(alignments_.stddev_);
489 else if (
options.output_minmax) {
491 size_t offset = alignments_.min_ + alignments_.max_ + alignments_.stddev_;
497 if (
options.output_histogram && active_[
i] >1 ) {
498 std::ostringstream
tmp;
502 tmp <<
", "<<hist_[
h][
i];
508 os << std::left << std::setw(alignments_.histogram_);
511 else if (
options.output_histogram) {
513 for (
size_t j=0;
j < alignments_.histogram_; ++
j)
517 if (!
options.print_names_before_values) {
518 std::ostringstream
tmp;
520 for (
int l=0;
l<level; ++
l) {
534 if (
options.print_names_before_values) {
535 std::ostringstream
tmp;
536 for (
int l=0;
l<=level; ++
l)
538 tmp <<
"Remainder: ";
540 os << std::left << std::setw(alignments_.timer_names_);
544 std::ostringstream
tmp;
547 os << std::left << std::setw(alignments_.average_time_);
550 if (
options.output_fraction && (sum_[
i]/active_[
i] > 0.) ) {
552 os << std::left << std::setw(alignments_.fraction_);
553 std::ostringstream
tmp;
554 tmp <<
" - "<< (sum_[
i]/active_[
i]-
sub_time)/(sum_[
i]/active_[
i])*100 <<
"%";
557 if (!
options.print_names_before_values) {
560 offset += alignments_.count_;
561 if (
options.output_total_updates)
562 offset += alignments_.total_updates_;
564 offset += alignments_.min_ + alignments_.max_ + alignments_.stddev_;
566 offset += alignments_.histogram_;
570 std::ostringstream
tmp;
572 for (
int l=0;
l<=level; ++
l)
574 tmp <<
"Remainder: ";
576 os << std::left << std::setw(alignments_.timer_names_);
586static void printXMLEscapedString(std::ostream& os,
const std::string&
str)
629 for (
int i=0;
i<flat_names_.
size(); ++
i) {
632 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
639 for (
int j = 0;
j < indent;
j++)
641 os <<
"<timing name=\"";
643 printXMLEscapedString(os,
rootName);
646 os <<
"\" value=\"" << sum_[
i]/active_[
i] <<
"\"";
661 os <<
"<timing name=\"Remainder\" value=\"" << (sum_[
i]/active_[
i] -
sub_time) <<
"\"/>\n";
664 for (
int j = 0;
j < indent;
j++)
681 if (rank(*
comm) == 0 ) {
683 os <<
"*** Teuchos::StackedTimer::report() - Remainder for a level will be ***"
684 <<
"\n*** incorrect if a timer in the level does not exist on every rank ***"
685 <<
"\n*** of the MPI Communicator. ***"
689 os <<
"Teuchos::StackedTimer::report() - max_levels manually set to " <<
options.max_levels
690 <<
". \nTo print more levels, increase value of OutputOptions::max_levels." << std::endl;
692 if ( (!
options.print_names_before_values) && (!
options.align_columns)) {
695 os <<
"Teuchos::StackedTimer::report() - option print_names_before_values=false "
696 <<
"\nrequires that the option align_columns=true too. Setting the value for "
697 <<
"\nalign_column to true."
701 std::vector<bool>
printed(flat_names_.
size(),
false);
705 std::vector<bool>
printed(flat_names_.
size(),
false);
715 if (rank(*
comm) == 0 ) {
716 std::vector<bool>
printed(flat_names_.
size(),
false);
717 os <<
"<?xml version=\"1.0\"?>\n";
718 os <<
"<performance-report date=\"" <<
timestamp <<
"\" name=\"nightly_run_" <<
datestamp <<
"\" time-units=\"seconds\">\n";
720 os <<
"</performance-report>\n";
756 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid year or is not in YYYY_MM_DD format.");
758 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid month or is not in YYYY_MM_DD format.");
760 throw std::invalid_argument(
"$WATCHR_BUILD_DATE has invalid day or is not in YYYY_MM_DD format.");
780 if(rank(*
comm) == 0) {
801 std::vector<bool>
printed(flat_names_.
size(),
false);
802 os <<
"<?xml version=\"1.0\"?>\n";
803 os <<
"<performance-report date=\"" <<
timestamp <<
"\" name=\"nightly_run_" <<
datestamp <<
"\" time-units=\"seconds\">\n";
810 os <<
" <metadata key=\"Trilinos Version\" value=\"" <<
gitSHA <<
"\"/>\n";
813 os <<
"</performance-report>\n";
838 global_mpi_aggregation_called_ =
true;
844 return sum_[
i] / active_[
i];
850 return static_cast<double>(count_[
i]) /
static_cast<double>(active_[
i]);
856 "ERROR: StackedTimer::getAverageMpiTime() - must call aggregateMpiData() first!");
861 "ERROR: StackedTimer::getAverageMpiTime() - the timer named \""
865 return static_cast<int>(
i);
871 "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.