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 
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 
141 typedef std::map<std::string, std::vector<std::pair<double, double> > > stat_map_type;
142 
170  public PerformanceMonitorBase<Time> {
171 public:
172 
175 
184  TimeMonitor (Time& timer, bool reset=false);
185 
187  ~TimeMonitor();
189 
198  static RCP<Time> getNewTimer (const std::string& name) {
199  return getNewCounter (name);
200  }
201 
217  static void disableTimer (const std::string& name);
218 
227  static void enableTimer (const std::string& name);
228 
235  static void zeroOutTimers();
236 
350  static void
351  computeGlobalTimerStatistics (stat_map_type& statData,
352  std::vector<std::string>& statNames,
353  Ptr<const Comm<int> > comm,
354  const ECounterSetOp setOp=Intersection,
355  const std::string& filter="");
356 
385  static void
386  computeGlobalTimerStatistics (stat_map_type& statData,
387  std::vector<std::string>& statNames,
388  const ECounterSetOp setOp=Intersection,
389  const std::string& filter="");
390 
457  static void
458  summarize (Ptr<const Comm<int> > comm,
459  std::ostream &out=std::cout,
460  const bool alwaysWriteLocal=false,
461  const bool writeGlobalStats=true,
462  const bool writeZeroTimers=true,
463  const ECounterSetOp setOp=Intersection,
464  const std::string& filter="",
465  const bool ignoreZeroTimers=false);
466 
483  static void
484  summarize (std::ostream& out=std::cout,
485  const bool alwaysWriteLocal=false,
486  const bool writeGlobalStats=true,
487  const bool writeZeroTimers=true,
488  const ECounterSetOp setOp=Intersection,
489  const std::string& filter="",
490  const bool ignoreZeroTimers=false);
491 
570  static void
571  report (Ptr<const Comm<int> > comm,
572  std::ostream& out,
573  const std::string& filter,
574  const RCP<ParameterList>& params=null);
575 
580  static void
581  report (Ptr<const Comm<int> > comm,
582  std::ostream& out,
583  const RCP<ParameterList>& params=null);
584 
589  static void
590  report (std::ostream& out,
591  const std::string& filter,
592  const RCP<ParameterList>& params=null);
593 
598  static void
599  report (std::ostream& out,
600  const RCP<ParameterList>& params=null);
601 
603  static RCP<const ParameterList> getValidReportParameters ();
604 
605  private:
612  REPORT_FORMAT_TABLE
613  };
614 
621  YAML_FORMAT_SPACIOUS
622  };
623 
638  static void
639  summarizeToYaml (Ptr<const Comm<int> > comm,
640  std::ostream& out,
641  const ETimeMonitorYamlFormat yamlStyle,
642  const std::string& filter="");
643 
648  static void
649  summarizeToYaml (std::ostream& out,
650  const ETimeMonitorYamlFormat yamlStyle,
651  const std::string& filter="");
652 
657  static void setReportFormatParameter (ParameterList& plist);
658 
663  static void setYamlFormatParameter (ParameterList& plist);
664 
669  static void setSetOpParameter (ParameterList& plist);
670 
685  static void setReportParameters (const RCP<ParameterList>& params);
686 
688 
689 
692 
696 
699 
701  static bool alwaysWriteLocal_;
702 
705  static bool writeGlobalStats_;
706 
708  static bool writeZeroTimers_;
710 
715  static bool setParams_;
716 };
717 
718 
719 } // namespace Teuchos
720 
721 
722 namespace Teuchos {
723 
733 {
734  virtual void summarize (std::ostream& out) {
736  }
737 };
738 
781 public:
786  }
787  }
788 };
789 
790 } // end namespace Teuchos
791 
792 
793 namespace {
794 
795 // Inject the implementation in every translation unit.
796 Teuchos::TimeMonitorSurrogateImplInserter timeMonitorSurrogateImplInserter;
797 
798 } // namespace (anonymous)
799 
800 #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 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.