Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
Teuchos_TimeMonitor.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_TIMEMONITOR_HPP
43 #define TEUCHOS_TIMEMONITOR_HPP
44 
45 
69 #include "Teuchos_Comm.hpp"
70 #include "Teuchos_Time.hpp"
71 
73 
75 #define TEUCHOS_TIMER(funcName, strName) \
76  static Teuchos::Time& funcName() \
77  {static Teuchos::RCP<Time> rtn = \
78  Teuchos::TimeMonitor::getNewCounter(strName); return *rtn;}
79 
80 
86 #define TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, DIFF ) \
87  static Teuchos::RCP<Teuchos::Time> DIFF ## blabla_localTimer; \
88  if(!DIFF ## blabla_localTimer.get()) { \
89  std::ostringstream oss; \
90  oss << FUNCNAME; \
91  DIFF ## blabla_localTimer = Teuchos::TimeMonitor::getNewCounter(oss.str()); \
92  } \
93  Teuchos::TimeMonitor DIFF ## blabla_localTimeMonitor(*DIFF ## blabla_localTimer)
94 
95 
118 #define TEUCHOS_FUNC_TIME_MONITOR( FUNCNAME ) \
119  TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, main )
120 
121 
122 namespace Teuchos {
123 
135 typedef std::map<std::string, std::vector<std::pair<double, double> > > stat_map_type;
136 
164  public PerformanceMonitorBase<Time> {
165 public:
166 
169 
178  TimeMonitor (Time& timer, bool reset=false);
179 
181  ~TimeMonitor();
183 
192  static RCP<Time> getNewTimer (const std::string& name) {
193  return getNewCounter (name);
194  }
195 
211  static void disableTimer (const std::string& name);
212 
221  static void enableTimer (const std::string& name);
222 
229  static void zeroOutTimers();
230 
344  static void
345  computeGlobalTimerStatistics (stat_map_type& statData,
346  std::vector<std::string>& statNames,
347  Ptr<const Comm<int> > comm,
348  const ECounterSetOp setOp=Intersection,
349  const std::string& filter="");
350 
379  static void
380  computeGlobalTimerStatistics (stat_map_type& statData,
381  std::vector<std::string>& statNames,
382  const ECounterSetOp setOp=Intersection,
383  const std::string& filter="");
384 
446  static void
447  summarize (Ptr<const Comm<int> > comm,
448  std::ostream &out=std::cout,
449  const bool alwaysWriteLocal=false,
450  const bool writeGlobalStats=true,
451  const bool writeZeroTimers=true,
452  const ECounterSetOp setOp=Intersection,
453  const std::string& filter="");
454 
471  static void
472  summarize (std::ostream& out=std::cout,
473  const bool alwaysWriteLocal=false,
474  const bool writeGlobalStats=true,
475  const bool writeZeroTimers=true,
476  const ECounterSetOp setOp=Intersection,
477  const std::string& filter="");
478 
557  static void
558  report (Ptr<const Comm<int> > comm,
559  std::ostream& out,
560  const std::string& filter,
561  const RCP<ParameterList>& params=null);
562 
567  static void
568  report (Ptr<const Comm<int> > comm,
569  std::ostream& out,
570  const RCP<ParameterList>& params=null);
571 
576  static void
577  report (std::ostream& out,
578  const std::string& filter,
579  const RCP<ParameterList>& params=null);
580 
585  static void
586  report (std::ostream& out,
587  const RCP<ParameterList>& params=null);
588 
590  static RCP<const ParameterList> getValidReportParameters ();
591 
592  private:
599  REPORT_FORMAT_TABLE
600  };
601 
608  YAML_FORMAT_SPACIOUS
609  };
610 
625  static void
626  summarizeToYaml (Ptr<const Comm<int> > comm,
627  std::ostream& out,
628  const ETimeMonitorYamlFormat yamlStyle,
629  const std::string& filter="");
630 
635  static void
636  summarizeToYaml (std::ostream& out,
637  const ETimeMonitorYamlFormat yamlStyle,
638  const std::string& filter="");
639 
644  static void setReportFormatParameter (ParameterList& plist);
645 
650  static void setYamlFormatParameter (ParameterList& plist);
651 
656  static void setSetOpParameter (ParameterList& plist);
657 
672  static void setReportParameters (const RCP<ParameterList>& params);
673 
675 
676 
679 
683 
686 
688  static bool alwaysWriteLocal_;
689 
692  static bool writeGlobalStats_;
693 
695  static bool writeZeroTimers_;
697 
702  static bool setParams_;
703 };
704 
705 
706 } // namespace Teuchos
707 
708 
709 namespace Teuchos {
710 
720 {
721  virtual void summarize (std::ostream& out) {
723  }
724 };
725 
768 public:
773  }
774  }
775 };
776 
777 } // end namespace Teuchos
778 
779 
780 namespace {
781 
782 // Inject the implementation in every translation unit.
783 Teuchos::TimeMonitorSurrogateImplInserter timeMonitorSurrogateImplInserter;
784 
785 } // namespace (anonymous)
786 
787 #endif // TEUCHOS_TIMEMONITOR_H
static bool alwaysWriteLocal_
Whether report() should always report Proc 0&#39;s local timer results.
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
static ETimeMonitorYamlFormat yamlStyle_
std::map< std::string, std::vector< std::pair< double, double > > > stat_map_type
Global statistics collected from timer data.
virtual void summarize(std::ostream &out)
Summarize timings over all process(es) to the given output stream.
static ECounterSetOp setOp_
Whether report() should use the intersection or union of timers over processes.
Basic wall-clock timer class.
static bool writeZeroTimers_
Whether report() should report timers with zero call counts.
Implementation of TimeMonitorSurrogate that invokes TimeMonitor.
static RCP< Time > getNewTimer(const std::string &name)
Return a new timer with the given name (class method).
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="")
Print summary statistics for all timers on the given communicator.
static void setTimeMonitorSurrogate(const RCP< TimeMonitorSurrogate > &timeMonitorSurrogate)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
Wall-clock timer.
Interface by which CommandLineProcessor may use TimeMonitor.
static ETimeMonitorReportFormat reportFormat_
Parameters for the report() class method.
static RCP< TimeMonitorSurrogate > getTimeMonitorSurrogate()
A list of parameters of arbitrary type.
TimeMonitorSurrogateImplInserter()
Constructor: inject dependency on TimeMonitor into CommandLineProcessor.
ETimeMonitorReportFormat
Valid output formats for report().
Abstract interface for distributed-memory communication.
ETimeMonitorYamlFormat
Valid YAML output formats for report().
Basic command line parser for input from (argc,argv[])
#define TEUCHOSCOMM_LIB_DLL_EXPORT
Smart reference counting pointer class for automatic garbage collection.
Provides common capabilities for collecting and reporting performance data across processors...
static bool setParams_
Whether setReportParameters() completed successfully.
ECounterSetOp
Set operation type for mergeCounterNames() to perform.
Common capabilities for collecting and reporting performance data across processors.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
A scope-safe timer wrapper class, that can compute global timer statistics.
Injects run-time dependency of a class on TimeMonitor.