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.");
294 if (counters_ ==
nullptr) {
295 counters_ =
new std::map<std::string, RCP<T> > ();
300 static_cast<void>( atexit(freeCounters) );
303 counters_ ==
nullptr, std::logic_error,
"Teuchos::PerformanceMonitorBase::"
304 "counters: Should never get here! counters_ is nullptr.");
314 static std::map<std::string, RCP<T> >* counters_;
320 bool isRecursiveCall_;
325 PerformanceMonitorBase<T>::format_ =
nullptr;
328 std::map<std::string, RCP<T> >*
329 PerformanceMonitorBase<T>::counters_ =
nullptr;
335 typedef std::map<std::string, RCP<T> > map_type;
336 typedef typename map_type::iterator iter_type;
338 map_type& ctrs = counters ();
339 iter_type it = ctrs.find (name);
341 if (it == ctrs.end ()) {
342 newCounter =
rcp (
new T (name));
343 #ifdef HAVE_TEUCHOS_DEBUG
344 const bool wasNotThere = ctrs.insert (std::make_pair (name, newCounter)).second;
346 ! wasNotThere, std::logic_error,
347 "getNewCounter: insert() claims that timer \"" << name <<
"\" was "
348 "already there in the map, even though find() claims that it was not. "
349 "Please report this bug to the Teuchos developers.");
352 ctrs.insert (it, std::make_pair (name, newCounter));
353 #endif // HAVE_TEUCHOS_DEBUG
355 newCounter = it->second;
356 #ifdef HAVE_TEUCHOS_DEBUG
358 it->second.is_null (), std::logic_error,
359 "getNewCounter: Timer \"" << name <<
"\" was already there in the map, "
360 "but looking it up by name resulted in a null timer. "
361 "Please report this bug to the Teuchos developers.");
363 name != it->second->name (), std::logic_error,
364 "getNewCounter: Timer \"" << name <<
"\" was already there in the map, "
365 "but looking it up by name resulted in a timer with a different name \""
366 << it->second->name () <<
"\". Please report this bug to the Teuchos "
368 #endif // HAVE_TEUCHOS_DEBUG
371 #ifdef HAVE_TEUCHOS_DEBUG
373 newCounter.
is_null (), std::logic_error,
374 "getNewCounter: At end of method, when creating timer \"" << name
375 <<
"\", newCounter is null. Please report this bug to the Teuchos "
377 #endif // HAVE_TEUCHOS_DEBUG
385 typedef std::map<std::string, RCP<T> > map_type;
386 typedef typename map_type::iterator iter_type;
388 map_type& ctrs = counters ();
389 iter_type it = ctrs.find (name);
390 if (it == ctrs.end ()) {
401 counters ().erase (name);
408 counters ().clear ();
413 #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.