Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
78 #define TEUCHOS_TIMER(funcName, strName) \
79  static Teuchos::Time& funcName() \
80  {static Teuchos::RCP<Time> rtn = \
81  Teuchos::TimeMonitor::getNewCounter(strName); return *rtn;}
82 
83 
92 #define TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, DIFF ) \
93  static Teuchos::RCP<Teuchos::Time> DIFF ## blabla_localTimer; \
94  if(!DIFF ## blabla_localTimer.get()) { \
95  std::ostringstream oss; \
96  oss << FUNCNAME; \
97  DIFF ## blabla_localTimer = Teuchos::TimeMonitor::getNewCounter(oss.str()); \
98  } \
99  Teuchos::TimeMonitor DIFF ## blabla_localTimeMonitor(*DIFF ## blabla_localTimer)
100 
101 
124 #define TEUCHOS_FUNC_TIME_MONITOR( FUNCNAME ) \
125  TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, main )
126 
127 
128 namespace Teuchos {
129 
130 // Forward declaration
131 class StackedTimer;
132 
144 typedef std::map<std::string, std::vector<std::pair<double, double> > > stat_map_type;
145 
179  public PerformanceMonitorBase<Time> {
180 public:
181 
184 
193  TimeMonitor (Time& timer, bool reset=false);
194 
196  ~TimeMonitor();
198 
207  static RCP<Time> getNewTimer (const std::string& name) {
208  return getNewCounter (name);
209  }
210 
226  static void disableTimer (const std::string& name);
227 
236  static void enableTimer (const std::string& name);
237 
244  static void zeroOutTimers();
245 
359  static void
360  computeGlobalTimerStatistics (stat_map_type& statData,
361  std::vector<std::string>& statNames,
362  Ptr<const Comm<int> > comm,
363  const ECounterSetOp setOp=Intersection,
364  const std::string& filter="");
365 
394  static void
395  computeGlobalTimerStatistics (stat_map_type& statData,
396  std::vector<std::string>& statNames,
397  const ECounterSetOp setOp=Intersection,
398  const std::string& filter="");
399 
466  static void
467  summarize (Ptr<const Comm<int> > comm,
468  std::ostream &out=std::cout,
469  const bool alwaysWriteLocal=false,
470  const bool writeGlobalStats=true,
471  const bool writeZeroTimers=true,
472  const ECounterSetOp setOp=Intersection,
473  const std::string& filter="",
474  const bool ignoreZeroTimers=false);
475 
492  static void
493  summarize (std::ostream& out=std::cout,
494  const bool alwaysWriteLocal=false,
495  const bool writeGlobalStats=true,
496  const bool writeZeroTimers=true,
497  const ECounterSetOp setOp=Intersection,
498  const std::string& filter="",
499  const bool ignoreZeroTimers=false);
500 
579  static void
580  report (Ptr<const Comm<int> > comm,
581  std::ostream& out,
582  const std::string& filter,
583  const RCP<ParameterList>& params=null);
584 
589  static void
590  report (Ptr<const Comm<int> > comm,
591  std::ostream& out,
592  const RCP<ParameterList>& params=null);
593 
598  static void
599  report (std::ostream& out,
600  const std::string& filter,
601  const RCP<ParameterList>& params=null);
602 
607  static void
608  report (std::ostream& out,
609  const RCP<ParameterList>& params=null);
610 
612  static RCP<const ParameterList> getValidReportParameters ();
613 
617  static void setStackedTimer(const Teuchos::RCP<Teuchos::StackedTimer>& t);
618 
620  static const Teuchos::RCP<Teuchos::StackedTimer>& getStackedTimer();
621 
622  private:
629  REPORT_FORMAT_TABLE
630  };
631 
638  YAML_FORMAT_SPACIOUS
639  };
640 
655  static void
656  summarizeToYaml (Ptr<const Comm<int> > comm,
657  std::ostream& out,
658  const ETimeMonitorYamlFormat yamlStyle,
659  const std::string& filter="");
660 
665  static void
666  summarizeToYaml (std::ostream& out,
667  const ETimeMonitorYamlFormat yamlStyle,
668  const std::string& filter="");
669 
674  static void setReportFormatParameter (ParameterList& plist);
675 
680  static void setYamlFormatParameter (ParameterList& plist);
681 
686  static void setSetOpParameter (ParameterList& plist);
687 
702  static void setReportParameters (const RCP<ParameterList>& params);
703 
705 
706 
709 
713 
716 
718  static bool alwaysWriteLocal_;
719 
722  static bool writeGlobalStats_;
723 
725  static bool writeZeroTimers_;
727 
732  static bool setParams_;
733 
736 };
737 
738 
739 } // namespace Teuchos
740 
741 
742 namespace Teuchos {
743 
753 {
754  virtual void summarize (std::ostream& out) {
756  }
757 };
758 
801 public:
806  }
807  }
808 };
809 
810 } // end namespace Teuchos
811 
812 
813 namespace {
814 
815 // Inject the implementation in every translation unit.
816 Teuchos::TimeMonitorSurrogateImplInserter timeMonitorSurrogateImplInserter;
817 
818 } // namespace (anonymous)
819 
820 #endif // TEUCHOS_TIMEMONITOR_H
static bool alwaysWriteLocal_
Whether report() should always report Proc 0&#39;s local timer results.
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.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
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 Teuchos::RCP< Teuchos::StackedTimer > stackedTimer_
Stacked timer for optional injetion of timing from TimeMontior enabled objects.
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.
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="", const bool ignoreZeroTimers=false)
Print summary statistics for all timers on the given communicator.
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.