4 #include "Teuchos_StackedTimer.hpp"
12 level_(std::numeric_limits<unsigned>::max()),name_(
"INVALID"),parent_(NULL)
23 for (
unsigned i=0; i<level_; ++i)
25 os << name_<<
":"<<
accumulatedTime()<<
" [" << count_started_<<
"] ("<< count_updates_ <<
")"<<std::endl;
27 for (
size_t i=0; i<sub_timers_.size(); ++i) {
28 t_total += sub_timers_[i].accumulatedTime();
29 sub_timers_[i].report(os);
31 if ( sub_timers_.size() == 0 )
33 for (
unsigned i=0; i<=level_; ++i)
41 BaseTimer::TimeInfo t;
42 if (get_full_name() == name) {
43 t = BaseTimer::TimeInfo(
this);
47 for (
unsigned i=0;i<sub_timers_.size(); ++i){
48 t = sub_timers_[i].findTimer(name,found);
59 flat_names_.
resize(num_timers);
61 timer_.addTimerNames(flat_names_, pos);
68 flat_names_ = all_names;
74 int num_names = flat_names_.
size();
79 if (options.output_minmax || options.output_histogram) {
82 if ( options.output_minmax )
87 if (options.output_histogram ) {
88 hist_.resize(options.num_histogram);
89 for (
int i=0;i<options.num_histogram ; ++i)
90 hist_[i].resize(num_names);
97 if (options.output_total_updates)
102 if (options.output_histogram)
106 for (
int i=0;i<num_names; ++i) {
111 used[i] = t.count==0? 0:1;
112 if (options.output_total_updates)
113 updates[i] = t.updates;
126 if (options.output_histogram) {
127 for (
int i=0;i<num_names; ++i) {
129 double dh = (max_[i]-min_[i])/options.num_histogram;
133 int bin=(time[i]- min_[i])/dh;
134 bins[i] = std::max(std::min(bin,options.num_histogram-1) , 0);
138 for (
int j=0; j<options.num_histogram; ++j){
139 for (
int i=0;i<num_names; ++i) {
149 if (sum_sq_.
size()) {
150 for (
int i=0;i<num_names; ++i)
157 std::pair<std::string, std::string> getPrefix(
const std::string &name) {
158 for (std::size_t i=name.size()-1; i>0; --i)
159 if (name[i] ==
'@') {
160 return std::pair<std::string, std::string>(name.substr(0,i), name.substr(i+1, name.size()));
162 return std::pair<std::string, std::string>(std::string(
""), name);
168 double total_time = 0.0;
170 for (
int i=0; i<flat_names_.
size(); ++i ) {
173 int level = std::count(flat_names_[i].begin(), flat_names_[i].end(),
'@');
174 if ( (level != print_level) || (level >= options.max_levels) )
176 auto split_names = getPrefix(flat_names_[i]);
177 if ( prefix != split_names.first)
181 for (
int l=0; l<level; ++l)
183 os << split_names.second <<
": ";
185 os << sum_[i]/active_[i];
187 if ( options.output_fraction && parent_time>0)
188 os <<
" - "<<sum_[i]/active_[i]/parent_time*100<<
"%";
190 os <<
" ["<<count_[i]/active_[i]<<
"]";
192 if ( options.output_total_updates )
193 os <<
" ("<<updates_[i]/active_[i]<<
")";
195 if ( options.output_minmax && active_[i]>1) {
196 os <<
" {min="<<min_[i]<<
", max="<<max_[i];
198 os<<
", std dev="<<sqrt((sum_sq_[i]-sum_[i]*sum_[i]/active_[i])/(active_[i]-1));
202 if ( options.output_histogram && active_[i] >1 ) {
205 for (
int h=0;h<options.num_histogram; ++h) {
207 os <<
", "<<hist_[h][i];
215 double sub_time =
printLevel(flat_names_[i], level+1, os, printed, sum_[i]/active_[i], options);
217 for (
int l=0; l<=level; ++l)
219 os <<
"Remainder: " << sum_[i]/active_[i]- sub_time;
220 if ( options.output_fraction && (sum_[i]/active_[i] > 0.) )
221 os <<
" - "<< (sum_[i]/active_[i]- sub_time)/(sum_[i]/active_[i])*100 <<
"%";
224 total_time += sum_[i]/active_[i];
234 if (rank(*comm) == 0 ) {
235 if (options.print_warnings) {
236 os <<
"*** Teuchos::StackedTimer::report() - Remainder for a block will be ***"
237 <<
"\n*** incorrect if a timer in the block does not exist on every rank ***"
238 <<
"\n*** of the MPI Communicator. ***"
241 if ( (options.max_levels != INT_MAX) && options.print_warnings) {
242 os <<
"Teuchos::StackedTimer::report() - max_levels set to " << options.max_levels
243 <<
", to print more levels, increase value of OutputOptions::max_levels." << std::endl;
245 std::vector<bool> printed(flat_names_.
size(),
false);