LCOV - code coverage report
Current view: top level - ugbase/common - debug_id.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 55.6 % 27 15
Test Date: 2025-09-21 23:31:46 Functions: 80.0 % 5 4

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2012-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Martin Rupp
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #include "debug_id.h"
      34              : #include "common/log.h"
      35              : #include "common/error.h"
      36              : #include "common/assert.h"
      37              : #include <iostream>
      38              : #include <string.h>
      39              : #include "util/string_util.h"
      40              : 
      41              : namespace ug{
      42              : 
      43              : /**
      44              :  * register the debug id.
      45              :  * NOTE: this function is called in the initialization of variables
      46              :  * of type DebugID, which are mostly global variables.
      47              :  * Be absolutely sure we are safe here, i.e.
      48              :  * we are not using other things which might not be initialized (like Log).
      49              :  */
      50           30 : DebugID::DebugID(const char *str)
      51              : {
      52           30 :         m_hash = crc32(str);
      53           30 :         GetDebugIDManager().register_debug_id(str);
      54           30 : }
      55              : 
      56           31 : DebugIDManager& DebugIDManager::instance()
      57              : {
      58           31 :         static DebugIDManager m;
      59           31 :         return m;
      60              : }
      61              : 
      62              : 
      63            1 : bool DebugIDManager::
      64              : set_debug_levels(int lev)
      65              : {
      66           31 :         for(std::map<uint32, int>::iterator it=m_dbgLevels.begin(); it != m_dbgLevels.end(); ++it)
      67           30 :                 (*it).second = lev;
      68            1 :         return true;
      69              : }
      70              : 
      71            0 : bool DebugIDManager::
      72              : set_debug_level(const char *debugID, int level)
      73              : {
      74            0 :         int slen = strlen(debugID);
      75            0 :         if(slen<=0) return false;
      76            0 :         if(debugID[slen-1] == '*')
      77              :         {
      78            0 :                 for(size_t i=0; i<m_dbgLevelIdentifiers.size(); i++)
      79              :                 {
      80              :                         const char *name = m_dbgLevelIdentifiers[i].c_str();
      81            0 :                         if(WildcardMatch(name, debugID))
      82              :                         {
      83            0 :                                 set_debug_level(crc32(name), level);
      84              :                                 //UG_LOGN(name);
      85              :                         }
      86              :                 }
      87              :         }
      88            0 :         else if(set_debug_level(crc32(debugID), level) == false)
      89              :         {
      90            0 :                 UG_LOG("DebugID " << debugID << " not registered.\n");
      91            0 :                 return false;
      92              :         }
      93              :         return true;
      94              : }
      95              : 
      96              : /**
      97              :  * register the debug id.
      98              :  * NOTE: this function is called in the initialization of global variables
      99              :  * of type DebugID. Be absolutely sure we are safe here, i.e.
     100              :  * we are not using other things which might not be initialized (like Log).
     101              :  */
     102           30 : bool DebugIDManager::
     103              : register_debug_id(const char *debugID)
     104              : {
     105           30 :         if(debug_id_registered(debugID) == false)
     106              :         {
     107           30 :                 m_dbgLevelIdentifiers.push_back(std::string(debugID));
     108           30 :                 m_dbgLevels[crc32(debugID)] = -1;
     109              :                 return true;
     110              :         }
     111              :         else
     112              :         {
     113              :                 // not quite clear if cout is defined yet.
     114              :                 // --> it should be, if we define it in this header!
     115            0 :                 std::cout << "FATAL ERROR: DebugID "<<debugID<<" already registered." << std::endl;
     116              :                 // note that this could be caused by double-registering libraries.
     117            0 :                 UG_THROW("FATAL ERROR: DebugID "<<debugID<<" already registered.");
     118              :                 return false;
     119              :         }
     120              : }
     121              : 
     122              : }
        

Generated by: LCOV version 2.0-1