|
Teuchos - Trilinos Tools Package
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #ifndef TEUCHOS_TIMEMONITOR_HPP 00043 #define TEUCHOS_TIMEMONITOR_HPP 00044 00045 00067 #include "Teuchos_PerformanceMonitorBase.hpp" 00068 #include "Teuchos_ParameterList.hpp" 00069 #include "Teuchos_Comm.hpp" 00070 #include "Teuchos_Time.hpp" 00071 00072 #include "Teuchos_CommandLineProcessor.hpp" 00073 00075 #define TEUCHOS_TIMER(funcName, strName) \ 00076 static Teuchos::Time& funcName() \ 00077 {static Teuchos::RCP<Time> rtn = \ 00078 Teuchos::TimeMonitor::getNewCounter(strName); return *rtn;} 00079 00080 00086 #define TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, DIFF ) \ 00087 static Teuchos::RCP<Teuchos::Time> DIFF ## blabla_localTimer; \ 00088 if(!DIFF ## blabla_localTimer.get()) { \ 00089 std::ostringstream oss; \ 00090 oss << FUNCNAME; \ 00091 DIFF ## blabla_localTimer = Teuchos::TimeMonitor::getNewCounter(oss.str()); \ 00092 } \ 00093 Teuchos::TimeMonitor DIFF ## blabla_localTimeMonitor(*DIFF ## blabla_localTimer) 00094 00095 00118 #define TEUCHOS_FUNC_TIME_MONITOR( FUNCNAME ) \ 00119 TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, main ) 00120 00121 00122 namespace Teuchos { 00123 00135 typedef std::map<std::string, std::vector<std::pair<double, double> > > stat_map_type; 00136 00163 class TEUCHOSCOMM_LIB_DLL_EXPORT TimeMonitor : 00164 public PerformanceMonitorBase<Time> { 00165 public: 00166 00169 00178 TimeMonitor (Time& timer, bool reset=false); 00179 00181 ~TimeMonitor(); 00183 00192 static RCP<Time> getNewTimer (const std::string& name) { 00193 return getNewCounter (name); 00194 } 00195 00211 static void disableTimer (const std::string& name); 00212 00221 static void enableTimer (const std::string& name); 00222 00229 static void zeroOutTimers(); 00230 00344 static void 00345 computeGlobalTimerStatistics (stat_map_type& statData, 00346 std::vector<std::string>& statNames, 00347 Ptr<const Comm<int> > comm, 00348 const ECounterSetOp setOp=Intersection, 00349 const std::string& filter=""); 00350 00379 static void 00380 computeGlobalTimerStatistics (stat_map_type& statData, 00381 std::vector<std::string>& statNames, 00382 const ECounterSetOp setOp=Intersection, 00383 const std::string& filter=""); 00384 00451 static void 00452 summarize (Ptr<const Comm<int> > comm, 00453 std::ostream &out=std::cout, 00454 const bool alwaysWriteLocal=false, 00455 const bool writeGlobalStats=true, 00456 const bool writeZeroTimers=true, 00457 const ECounterSetOp setOp=Intersection, 00458 const std::string& filter="", 00459 const bool ignoreZeroTimers=false); 00460 00477 static void 00478 summarize (std::ostream& out=std::cout, 00479 const bool alwaysWriteLocal=false, 00480 const bool writeGlobalStats=true, 00481 const bool writeZeroTimers=true, 00482 const ECounterSetOp setOp=Intersection, 00483 const std::string& filter="", 00484 const bool ignoreZeroTimers=false); 00485 00564 static void 00565 report (Ptr<const Comm<int> > comm, 00566 std::ostream& out, 00567 const std::string& filter, 00568 const RCP<ParameterList>& params=null); 00569 00574 static void 00575 report (Ptr<const Comm<int> > comm, 00576 std::ostream& out, 00577 const RCP<ParameterList>& params=null); 00578 00583 static void 00584 report (std::ostream& out, 00585 const std::string& filter, 00586 const RCP<ParameterList>& params=null); 00587 00592 static void 00593 report (std::ostream& out, 00594 const RCP<ParameterList>& params=null); 00595 00597 static RCP<const ParameterList> getValidReportParameters (); 00598 00599 private: 00604 enum ETimeMonitorReportFormat { 00605 REPORT_FORMAT_YAML, 00606 REPORT_FORMAT_TABLE 00607 }; 00608 00613 enum ETimeMonitorYamlFormat { 00614 YAML_FORMAT_COMPACT, 00615 YAML_FORMAT_SPACIOUS 00616 }; 00617 00632 static void 00633 summarizeToYaml (Ptr<const Comm<int> > comm, 00634 std::ostream& out, 00635 const ETimeMonitorYamlFormat yamlStyle, 00636 const std::string& filter=""); 00637 00642 static void 00643 summarizeToYaml (std::ostream& out, 00644 const ETimeMonitorYamlFormat yamlStyle, 00645 const std::string& filter=""); 00646 00651 static void setReportFormatParameter (ParameterList& plist); 00652 00657 static void setYamlFormatParameter (ParameterList& plist); 00658 00663 static void setSetOpParameter (ParameterList& plist); 00664 00679 static void setReportParameters (const RCP<ParameterList>& params); 00680 00682 00683 00685 static ETimeMonitorReportFormat reportFormat_; 00686 00689 static ETimeMonitorYamlFormat yamlStyle_; 00690 00692 static ECounterSetOp setOp_; 00693 00695 static bool alwaysWriteLocal_; 00696 00699 static bool writeGlobalStats_; 00700 00702 static bool writeZeroTimers_; 00704 00709 static bool setParams_; 00710 }; 00711 00712 00713 } // namespace Teuchos 00714 00715 00716 namespace Teuchos { 00717 00726 class TimeMonitorSurrogateImpl : public CommandLineProcessor::TimeMonitorSurrogate 00727 { 00728 virtual void summarize (std::ostream& out) { 00729 TimeMonitor::summarize (out); 00730 } 00731 }; 00732 00774 class TimeMonitorSurrogateImplInserter { 00775 public: 00777 TimeMonitorSurrogateImplInserter () { 00778 if (is_null (CommandLineProcessor::getTimeMonitorSurrogate ())) { 00779 CommandLineProcessor::setTimeMonitorSurrogate (Teuchos::rcp (new TimeMonitorSurrogateImpl)); 00780 } 00781 } 00782 }; 00783 00784 } // end namespace Teuchos 00785 00786 00787 namespace { 00788 00789 // Inject the implementation in every translation unit. 00790 Teuchos::TimeMonitorSurrogateImplInserter timeMonitorSurrogateImplInserter; 00791 00792 } // namespace (anonymous) 00793 00794 #endif // TEUCHOS_TIMEMONITOR_H
1.7.6.1