LCOV - code coverage report
Current view: top level - include/base - libmesh_logging.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4343 (6ea38c) with base 8c3130 Lines: 11 11 100.0 %
Date: 2026-10-13 21:47:33 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2026 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             : #ifndef LIBMESH_LIBMESH_LOGGING_H
      21             : #define LIBMESH_LIBMESH_LOGGING_H
      22             : 
      23             : 
      24             : // The library configuration options
      25             : #include "libmesh/libmesh_common.h"
      26             : 
      27             : #include "libmesh/perf_log.h"
      28             : 
      29             : // Two-level macro substitution trick, used to construct a unique
      30             : // variable name for a given line.
      31             : #define TOKENPASTE(x, y) x ## y
      32             : #define TOKENPASTE2(x, y) TOKENPASTE(x, y)
      33             : 
      34             : namespace libMesh
      35             : {
      36             : 
      37             : 
      38             : // Forward declaration, required when included
      39             : // in perf_log.{C,h} because the preceding
      40             : // #include "libmesh/perf_log.h" is ineffective.
      41             : // Multiple inclusion avoidance problem...
      42             : // LIBMESH_PERF_LOG_H already #define'd, but the
      43             : // class has not been declared yet!.
      44             : class PerfLog;
      45             : 
      46             : /**
      47             :  * A \p PerfLog object to log performance.  If the library is configured
      48             :  * with \p --enable-perflog then it will log key functions.
      49             :  */
      50             : extern PerfLog perflog;
      51             : 
      52             : 
      53             : /**
      54             :  * Used for logging something that naturally lasts as long as some
      55             :  * enclosing scope, such as the current function.  Makes it very easy
      56             :  * to handle multiple return scenarios, since the event is popped in
      57             :  * the destructor.  Should not be used directly, instead use the
      58             :  * LOG_SCOPE macro, which resolves to nothing at compile time if
      59             :  * logging is disabled.
      60             :  *
      61             :  * \author John Peterson
      62             :  * \date 2016
      63             :  */
      64             : struct PerfItem
      65             : {
      66    66425906 :   PerfItem(const char * label,
      67             :            const char * header,
      68             :            bool enabled=true,
      69             :            PerfLog * my_perflog=&perflog,
      70   134811360 :            bool per_entity=false) :
      71             :     _label(label),
      72             :     _header(header),
      73             :     _enabled(enabled),
      74             :     _perflog(*my_perflog),
      75   134811364 :     _per_entity(per_entity)
      76             :   {
      77    73652254 :     if (_enabled)
      78   134193368 :       _perflog.fast_push(label, header, _per_entity);
      79    66425906 :   }
      80             : 
      81   132394466 :   ~PerfItem()
      82   132394466 :   {
      83   132394466 :     if (_enabled)
      84   131786650 :       _perflog.fast_pop(_label, _header, _per_entity);
      85   132394466 :   }
      86             : 
      87             : private:
      88             :   const char * _label;
      89             :   const char * _header;
      90             :   bool _enabled;
      91             :   PerfLog & _perflog;
      92             : 
      93             :   /**
      94             :    * Whether the event fires once per mesh entity or more often; see
      95             :    * PerfLog::fast_push().
      96             :    */
      97             :   bool _per_entity;
      98             : };
      99             : 
     100             : 
     101             : 
     102             : } // namespace libMesh
     103             : 
     104             : 
     105             : 
     106             : // Macros for performance logging.  This allows us
     107             : // to add performance monitors to the code without
     108             : // impacting performance when performance logging
     109             : // is disabled.
     110             : #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
     111             : 
     112             : #  define START_LOG(a,b)   { libMesh::perflog.push(a,b); }
     113             : #  define STOP_LOG(a,b)    { libMesh::perflog.pop(a,b); }
     114             : #  define LOG_SCOPE(a,b)   libMesh::PerfItem TOKENPASTE2(perf_item_, __LINE__)(a,b);
     115             : #  define LOG_SCOPE_IF(a,b,enabled)   libMesh::PerfItem TOKENPASTE2(perf_item_, __LINE__)(a,b,enabled);
     116             : #  define LOG_SCOPE_WITH(a,b,logger)   libMesh::PerfItem TOKENPASTE2(perf_item_, __LINE__)(a,b,true,&logger);
     117             : // For events that fire once per mesh entity or more often; see
     118             : // PerfLog::fast_push().
     119             : #  define LOG_ONE_ENTITY_SCOPE(a,b)   libMesh::PerfItem TOKENPASTE2(perf_item_, __LINE__)(a,b,true,&libMesh::perflog,true);
     120             : 
     121             : #else
     122             : 
     123             : #  define START_LOG(a,b)   {}
     124             : #  define STOP_LOG(a,b)    {}
     125             : #  define PALIBMESH_USE_LOG(a,b)   {}
     126             : #  define RESTART_LOG(a,b) {}
     127             : #  define LOG_SCOPE(a,b)   {}
     128             : #  define LOG_SCOPE_IF(a,b,enabled) {}
     129             : #  define LOG_SCOPE_WITH(a,b,logger) {}
     130             : #  define LOG_ONE_ENTITY_SCOPE(a,b) {}
     131             : 
     132             : #endif
     133             : 
     134             : // If performance logging is disabled, the LOG_SCOPE(a,b) will be a no-op.
     135             : #define LOG_CALL(a,b,X)   \
     136             :   do {                    \
     137             :     LOG_SCOPE(a,b);       \
     138             :     X;                    \
     139             :   } while (0)
     140             : 
     141             : 
     142             : 
     143             : 
     144             : #endif // LIBMESH_LIBMESH_LOGGING_H

Generated by: LCOV version 1.14