40#include "Teuchos_StackedTimer.hpp"
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);
97 BaseTimer::TimeInfo t;
103 if (get_full_name() == name) {
104 t = BaseTimer::TimeInfo(
this);
108 for (
unsigned i=0;
i<sub_timers_.size(); ++
i){
109 t = sub_timers_[
i].findTimer(name,
found);
148 if (
options.output_proc_minmax) {
154 if (
options.output_histogram ) {
155 hist_.resize(
options.num_histogram);
164 if (
options.output_total_updates)
178 used[
i] = t.count==0? 0:1;
179 if (
options.output_total_updates)
180 updates[
i] = t.updates;
197 if (procmin_.
size()) {
202 if (
used[
i] && (min_[
i]==time[
i]))
206 if (
used[
i] && (max_[
i]==time[
i]))
216 if (
options.output_histogram) {
219 double dh = (max_[
i]-min_[
i])/
options.num_histogram;
240 if (sum_sq_.
size()) {
248std::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);
267 for (
int i=0;
i<flat_names_.
size(); ++
i ) {
268 if (sum_[
i]/active_[
i] <=
options.drop_time)
272 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
281 std::ostringstream os;
282 for (
int l=0;
l<level; ++
l)
286 alignments_.timer_names_= std::max(alignments_.timer_names_,os.str().size());
291 std::ostringstream os;
292 os << sum_[
i]/active_[
i];
293 alignments_.average_time_ = std::max(alignments_.average_time_,os.str().size());
298 std::ostringstream os;
300 alignments_.fraction_ = std::max(alignments_.fraction_,os.str().size());
305 std::ostringstream os;
306 os <<
" ["<<count_[
i]/active_[
i]<<
"]";
307 alignments_.count_ = std::max(alignments_.count_,os.str().size());
311 if (
options.output_total_updates) {
312 std::ostringstream os;
313 os <<
" ("<<updates_[
i]/active_[
i]<<
")";
314 alignments_.total_updates_ = std::max(alignments_.total_updates_,os.str().size());
318 if (
options.output_minmax && active_[
i]>1) {
320 std::ostringstream os;
321 os <<
" {min=" << min_[
i];
322 alignments_.min_ = std::max(alignments_.min_,os.str().size());
325 std::ostringstream os;
326 os <<
", max=" << max_[
i];
329 alignments_.max_ = std::max(alignments_.max_,os.str().size());
331 if (procmin_.
size()) {
332 std::ostringstream os;
333 os <<
", proc min=" << procmin_[
i];
336 alignments_.procmin_ = std::min(alignments_.procmin_,os.str().size());
338 if (procmax_.
size()) {
339 std::ostringstream os;
340 os <<
", proc max=" << procmax_[
i];
343 alignments_.procmax_ = std::max(alignments_.procmax_,os.str().size());
346 std::ostringstream os;
347 os <<
", std dev=" <<
sqrt(std::max<double>(sum_sq_[
i]-sum_[
i]*sum_[
i]/active_[
i],0.0)/(active_[
i]-1));
349 alignments_.stddev_ = std::max(alignments_.stddev_,os.str().size());
353 if (
options.output_histogram && active_[
i] >1 ) {
354 std::ostringstream os;
358 os <<
", "<<hist_[
h][
i];
363 alignments_.histogram_ = std::max(alignments_.histogram_,os.str().size());
371 if (
options.print_names_before_values) {
372 std::ostringstream
tmp;
373 for (
int l=0;
l<=level; ++
l)
375 tmp <<
"Remainder: ";
376 alignments_.timer_names_ = std::max(alignments_.timer_names_,
tmp.str().size());
379 std::ostringstream
tmp;
381 alignments_.average_time_ = std::max(alignments_.average_time_,
tmp.str().size());
383 if (
options.output_fraction && (sum_[
i]/active_[
i] > 0.) ) {
384 std::ostringstream
tmp;
385 tmp <<
" - "<< (sum_[
i]/active_[
i]-
sub_time)/(sum_[
i]/active_[
i])*100 <<
"%";
386 alignments_.fraction_ = std::max(alignments_.fraction_,
tmp.str().size());
405 for (
int i=0;
i<flat_names_.
size(); ++
i ) {
406 if (sum_[
i]/active_[
i] <=
options.drop_time) {
411 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
419 if (
options.print_names_before_values) {
420 std::ostringstream
tmp;
421 for (
int l=0;
l<level; ++
l) {
427 os << std::left << std::setw(alignments_.timer_names_);
432 std::ostringstream
tmp;
433 tmp << sum_[
i]/active_[
i];
435 os << std::left << std::setw(alignments_.average_time_);
440 std::ostringstream
tmp;
443 os << std::left << std::setw(alignments_.fraction_);
447 else if (
options.output_fraction) {
449 os << std::setw(alignments_.fraction_) <<
" ";
453 std::ostringstream
tmp;
454 tmp <<
" ["<<count_[
i]/active_[
i]<<
"]";
456 os << std::left << std::setw(alignments_.count_);
460 if (
options.output_total_updates ) {
461 std::ostringstream
tmp;
462 tmp <<
" ("<<updates_[
i]/active_[
i]<<
")";
464 os << std::left << std::setw(alignments_.total_updates_);
468 if (
options.output_minmax && active_[
i]>1) {
470 std::ostringstream
tmp;
471 tmp <<
" {min="<<min_[
i];
473 os << std::left << std::setw(alignments_.min_);
477 std::ostringstream
tmp;
478 tmp <<
", max="<<max_[
i];
482 os << std::left << std::setw(alignments_.max_);
485 if (procmin_.
size()) {
486 std::ostringstream
tmp;
487 tmp <<
", proc min="<<procmin_[
i];
491 os << std::left << std::setw(alignments_.procmin_);
494 if (procmax_.
size()) {
495 std::ostringstream
tmp;
496 tmp <<
", proc max="<<procmax_[
i];
500 os << std::left << std::setw(alignments_.procmax_);
504 std::ostringstream
tmp;
505 tmp <<
", std dev="<<
sqrt(std::max<double>(sum_sq_[
i]-sum_[
i]*sum_[
i]/active_[
i],0.0)/(active_[
i]-1));
508 os << std::left << std::setw(alignments_.stddev_);
512 else if (
options.output_minmax) {
514 size_t offset = alignments_.min_ + alignments_.max_ + alignments_.stddev_;
520 if (
options.output_histogram && active_[
i] >1 ) {
521 std::ostringstream
tmp;
525 tmp <<
", "<<hist_[
h][
i];
531 os << std::left << std::setw(alignments_.histogram_);
534 else if (
options.output_histogram) {
536 for (
size_t j=0;
j < alignments_.histogram_; ++
j)
540 if (!
options.print_names_before_values) {
541 std::ostringstream
tmp;
543 for (
int l=0;
l<level; ++
l) {
557 if (
options.print_names_before_values) {
558 std::ostringstream
tmp;
559 for (
int l=0;
l<=level; ++
l)
561 tmp <<
"Remainder: ";
563 os << std::left << std::setw(alignments_.timer_names_);
567 std::ostringstream
tmp;
570 os << std::left << std::setw(alignments_.average_time_);
573 if (
options.output_fraction && (sum_[
i]/active_[
i] > 0.) ) {
575 os << std::left << std::setw(alignments_.fraction_);
576 std::ostringstream
tmp;
577 tmp <<
" - "<< (sum_[
i]/active_[
i]-
sub_time)/(sum_[
i]/active_[
i])*100 <<
"%";
580 if (!
options.print_names_before_values) {
583 offset += alignments_.count_;
584 if (
options.output_total_updates)
585 offset += alignments_.total_updates_;
587 offset += alignments_.min_ + alignments_.max_ + alignments_.stddev_;
589 offset += alignments_.histogram_;
593 std::ostringstream
tmp;
595 for (
int l=0;
l<=level; ++
l)
597 tmp <<
"Remainder: ";
599 os << std::left << std::setw(alignments_.timer_names_);
609static void printXMLEscapedString(std::ostream& os,
const std::string&
str)
644 for (
int i=0;
i<flat_names_.
size(); ++
i) {
647 int level = std::count(flat_names_[
i].begin(), flat_names_[
i].end(),
'@');
654 for (
int j = 0;
j < indent;
j++)
656 os <<
"<timing name=\"";
658 printXMLEscapedString(os,
rootName);
661 os <<
"\" value=\"" << sum_[
i]/active_[
i] <<
"\"";
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;
709 if ( (!
options.print_names_before_values) && (!
options.align_columns)) {
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."
718 std::vector<bool>
printed(flat_names_.
size(),
false);
722 std::vector<bool>
printed(flat_names_.
size(),
false);
734 if (rank(*
comm) == 0 ) {
735 std::vector<bool>
printed(flat_names_.
size(),
false);
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";
778 if(rank(*
comm) == 0) {
799 std::vector<bool>
printed(flat_names_.
size(),
false);
800 os <<
"<?xml version=\"1.0\"?>\n";
801 os <<
"<performance-report date=\"" <<
timestamp <<
"\" name=\"nightly_run_" <<
datestamp <<
"\" time-units=\"seconds\">\n";
808 os <<
" <metadata key=\"Trilinos Version\" value=\"" <<
gitSHA <<
"\"/>\n";
811 os <<
"</performance-report>\n";
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
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)
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.
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 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.
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.