LCOV - code coverage report
Current view: top level - src/base - reference_counter.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 14 21 66.7 %
Date: 2025-08-19 19:27:09 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 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
      25             : #include "libmesh/reference_counter.h"
      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             : 
      36             : ReferenceCounter::Counts ReferenceCounter::_counts;
      37             : 
      38             : #endif
      39             : 
      40             : bool ReferenceCounter::_enable_print_counter = true;
      41             : Threads::atomic<unsigned int> ReferenceCounter::_n_objects;
      42             : Threads::spin_mutex  ReferenceCounter::_mutex;
      43             : 
      44             : 
      45             : // ------------------------------------------------------------
      46             : // ReferenceCounter class members
      47         462 : std::string ReferenceCounter::get_info ()
      48             : {
      49             : #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
      50             : 
      51         924 :   std::ostringstream oss;
      52             : 
      53             :   oss << '\n'
      54             :       << " ---------------------------------------------------------------------------- \n"
      55             :       << "| Reference count information                                                |\n"
      56         462 :       << " ---------------------------------------------------------------------------- \n";
      57             : 
      58        6296 :   for (const auto & [name, cd] : _counts)
      59             :     oss << "| " << name << " reference count information:\n"
      60        5834 :         << "|  Creations:    " << cd.first    << '\n'
      61        5834 :         << "|  Destructions: " << cd.second << '\n';
      62             : 
      63         462 :   oss << " ---------------------------------------------------------------------------- \n";
      64             : 
      65         924 :   return oss.str();
      66             : 
      67             : #else
      68             : 
      69           0 :   return "";
      70             : 
      71             : #endif
      72             : }
      73             : 
      74             : 
      75             : 
      76             : 
      77             : 
      78             : // avoid unused variable warnings
      79             : #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
      80             : 
      81         462 : void ReferenceCounter::print_info (std::ostream & out_stream)
      82             : {
      83         462 :   if (_enable_print_counter)
      84         462 :     out_stream << ReferenceCounter::get_info();
      85         462 : }
      86             : 
      87             : #else
      88             : 
      89       15919 : void ReferenceCounter::print_info (std::ostream & /* out_stream */)
      90       15919 : {}
      91             : 
      92             : #endif
      93             : 
      94           0 : void ReferenceCounter::enable_print_counter_info()
      95             : {
      96           0 :   _enable_print_counter = true;
      97           0 :   return;
      98             : }
      99             : 
     100           0 : void ReferenceCounter::disable_print_counter_info()
     101             : {
     102           0 :   _enable_print_counter = false;
     103           0 :   return;
     104             : }
     105             : 
     106             : } // namespace libMesh

Generated by: LCOV version 1.14