40 #ifndef TEUCHOS_PERFORMANCEMONITORBASE_H
41 #define TEUCHOS_PERFORMANCEMONITORBASE_H
49 #include "Teuchos_Comm.hpp"
91 const Array<std::string>& localNames,
92 Array<std::string>& globalNames,
107 Array<std::string>& globalNames,
159 : counter_(counter_in), isRecursiveCall_(counter_.isRunning())
162 counter_.incrementNumCalls ();
200 static void freeTableFormat () {
201 if (format_ !=
nullptr) {
216 static void freeCounters () {
217 if (counters_ !=
nullptr) {
234 if (format_ ==
nullptr) {
240 static_cast<void>( atexit(freeTableFormat) );
243 format_ ==
nullptr, std::logic_error,
"Teuchos::PerformanceMonitorBase::"
244 "format: Should never get here! format_ is nullptr.");
293 static TEUCHOS_DEPRECATED
void clearTimer (
const std::string& name);
317 if (counters_ ==
nullptr) {
318 counters_ =
new std::map<std::string, RCP<T> > ();
323 static_cast<void>( atexit(freeCounters) );
326 counters_ ==
nullptr, std::logic_error,
"Teuchos::PerformanceMonitorBase::"
327 "counters: Should never get here! counters_ is nullptr.");
337 static std::map<std::string, RCP<T> >* counters_;
343 bool isRecursiveCall_;
348 PerformanceMonitorBase<T>::format_ =
nullptr;
351 std::map<std::string, RCP<T> >*
352 PerformanceMonitorBase<T>::counters_ =
nullptr;
358 typedef std::map<std::string, RCP<T> > map_type;
359 typedef typename map_type::iterator iter_type;
361 map_type& ctrs = counters ();
362 iter_type it = ctrs.find (name);
364 if (it == ctrs.end ()) {
365 newCounter =
rcp (
new T (name));
366 #ifdef HAVE_TEUCHOS_DEBUG
367 const bool wasNotThere = ctrs.insert (std::make_pair (name, newCounter)).second;
369 ! wasNotThere, std::logic_error,
370 "getNewCounter: insert() claims that timer \"" << name <<
"\" was "
371 "already there in the map, even though find() claims that it was not. "
372 "Please report this bug to the Teuchos developers.");
375 ctrs.insert (it, std::make_pair (name, newCounter));
376 #endif // HAVE_TEUCHOS_DEBUG
378 newCounter = it->second;
379 #ifdef HAVE_TEUCHOS_DEBUG
381 it->second.is_null (), std::logic_error,
382 "getNewCounter: Timer \"" << name <<
"\" was already there in the map, "
383 "but looking it up by name resulted in a null timer. "
384 "Please report this bug to the Teuchos developers.");
386 name != it->second->name (), std::logic_error,
387 "getNewCounter: Timer \"" << name <<
"\" was already there in the map, "
388 "but looking it up by name resulted in a timer with a different name \""
389 << it->second->name () <<
"\". Please report this bug to the Teuchos "
391 #endif // HAVE_TEUCHOS_DEBUG
394 #ifdef HAVE_TEUCHOS_DEBUG
396 newCounter.
is_null (), std::logic_error,
397 "getNewCounter: At end of method, when creating timer \"" << name
398 <<
"\", newCounter is null. Please report this bug to the Teuchos "
400 #endif // HAVE_TEUCHOS_DEBUG
408 typedef std::map<std::string, RCP<T> > map_type;
409 typedef typename map_type::iterator iter_type;
411 map_type& ctrs = counters ();
412 iter_type it = ctrs.find (name);
413 if (it == ctrs.end ()) {
424 counters ().erase (name);
445 counters ().clear ();
450 #endif // TEUCHOS_PERFORMANCEMONITORBASE_H
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
void mergeCounterNames(const Comm< int > &comm, const Array< std::string > &localNames, Array< std::string > &globalNames, const ECounterSetOp setOp)
Merge counter names over all processors.
void unsortedMergePair(const Array< std::string > &localNames, Array< std::string > &globalNames, const ECounterSetOp setOp)
Templated array class derived from the STL std::vector.
Smart reference counting pointer class for automatic garbage collection.
ECounterSetOp
Set operation type for mergeCounterNames() to perform.
Reference-counted pointer class and non-member templated function implementations.
bool is_null() const
Returns true if the underlying pointer is null.