reference_counter.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // C++ includes
21 #include <iostream>
22 #include <sstream>
23 
24 // Local includes
26 
27 namespace libMesh
28 {
29 
30 
31 
32 // ------------------------------------------------------------
33 // ReferenceCounter class static member initializations
34 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
35 
37 
38 #endif
39 
41 Threads::atomic<unsigned int> ReferenceCounter::_n_objects;
43 
44 
45 // ------------------------------------------------------------
46 // ReferenceCounter class members
48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (const auto & pr : _counts)
59  {
60  const std::string name(pr.first);
61  const unsigned int creations = pr.second.first;
62  const unsigned int destructions = pr.second.second;
63 
64  oss << "| " << name << " reference count information:\n"
65  << "| Creations: " << creations << '\n'
66  << "| Destructions: " << destructions << '\n';
67  }
68 
69  oss << " ---------------------------------------------------------------------------- \n";
70 
71  return oss.str();
72 
73 #else
74 
75  return "";
76 
77 #endif
78 }
79 
80 
81 
82 
83 
84 // avoid unused variable warnings
85 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
86 
87 void ReferenceCounter::print_info (std::ostream & out_stream)
88 {
90  out_stream << ReferenceCounter::get_info();
91 }
92 
93 #else
94 
95 void ReferenceCounter::print_info (std::ostream & /* out_stream */)
96 {}
97 
98 #endif
99 
101 {
102  _enable_print_counter = true;
103  return;
104 }
105 
107 {
108  _enable_print_counter = false;
109  return;
110 }
111 
112 } // namespace libMesh
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
static Threads::atomic< unsigned int > _n_objects
std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
static std::string get_info()
static Threads::spin_mutex _mutex
static void enable_print_counter_info()
static void print_info(std::ostream &out=libMesh::out)
tbb::spin_mutex spin_mutex
Definition: threads_tbb.h:209
static void disable_print_counter_info()