LCOV - code coverage report
Current view: top level - src - log.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 7 7 100.0 %
Date: 2025-03-29 09:04:10 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 26 32 81.2 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This file is part of libplacebo.
       3                 :            :  *
       4                 :            :  * libplacebo 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                 :            :  * libplacebo 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
      12                 :            :  * GNU 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 libplacebo. If not, see <http://www.gnu.org/licenses/>.
      16                 :            :  */
      17                 :            : 
      18                 :            : #pragma once
      19                 :            : 
      20                 :            : #include <stdarg.h>
      21                 :            : 
      22                 :            : #include "common.h"
      23                 :            : 
      24                 :            : #include <libplacebo/log.h>
      25                 :            : 
      26                 :            : // Internal logging-related functions
      27                 :            : 
      28                 :            : // Warning: Not entirely thread-safe. Exercise caution when using. May result
      29                 :            : // in either false positives or false negatives. Make sure to re-run this
      30                 :            : // function while `lock` is held, to ensure no race conditions on the check.
      31                 :            : static inline bool pl_msg_test(pl_log log, enum pl_log_level lev)
      32                 :            : {
      33   [ +  +  +  +  :     172013 :     return log && log->params.log_cb && log->params.log_level >= lev;
          +  +  +  -  +  
          -  +  +  +  +  
          +  -  +  +  +  
             -  +  -  +  
                      + ]
      34                 :            : }
      35                 :            : 
      36                 :            : void pl_msg(pl_log log, enum pl_log_level lev, const char *fmt, ...)
      37                 :            :     PL_PRINTF(3, 4);
      38                 :            : 
      39                 :            : // Convenience macros
      40                 :            : #define pl_fatal(log, ...)      pl_msg(log, PL_LOG_FATAL, __VA_ARGS__)
      41                 :            : #define pl_err(log, ...)        pl_msg(log, PL_LOG_ERR, __VA_ARGS__)
      42                 :            : #define pl_warn(log, ...)       pl_msg(log, PL_LOG_WARN, __VA_ARGS__)
      43                 :            : #define pl_info(log, ...)       pl_msg(log, PL_LOG_INFO, __VA_ARGS__)
      44                 :            : #define pl_debug(log, ...)      pl_msg(log, PL_LOG_DEBUG, __VA_ARGS__)
      45                 :            : #define pl_trace(log, ...)      pl_msg(log, PL_LOG_TRACE, __VA_ARGS__)
      46                 :            : 
      47                 :            : #define PL_MSG(obj, lev, ...)   pl_msg((obj)->log, lev, __VA_ARGS__)
      48                 :            : 
      49                 :            : #define PL_FATAL(obj, ...)      PL_MSG(obj, PL_LOG_FATAL, __VA_ARGS__)
      50                 :            : #define PL_ERR(obj, ...)        PL_MSG(obj, PL_LOG_ERR, __VA_ARGS__)
      51                 :            : #define PL_WARN(obj, ...)       PL_MSG(obj, PL_LOG_WARN, __VA_ARGS__)
      52                 :            : #define PL_INFO(obj, ...)       PL_MSG(obj, PL_LOG_INFO, __VA_ARGS__)
      53                 :            : #define PL_DEBUG(obj, ...)      PL_MSG(obj, PL_LOG_DEBUG, __VA_ARGS__)
      54                 :            : #define PL_TRACE(obj, ...)      PL_MSG(obj, PL_LOG_TRACE, __VA_ARGS__)
      55                 :            : 
      56                 :            : // Log something with line numbers included
      57                 :            : void pl_msg_source(pl_log log, enum pl_log_level lev, const char *src);
      58                 :            : 
      59                 :            : // Temporarily cap the log level to a certain verbosity. This is intended for
      60                 :            : // things like probing formats, attempting to create buffers that may fail, and
      61                 :            : // other types of operations in which we want to suppress errors. Call with
      62                 :            : // PL_LOG_NONE to disable this cap.
      63                 :            : //
      64                 :            : // Warning: This is generally not thread-safe, and only provided as a temporary
      65                 :            : // hack until a better solution can be thought of.
      66                 :            : void pl_log_level_cap(pl_log log, enum pl_log_level cap);
      67                 :            : 
      68                 :            : // CPU execution time reporting helper
      69         [ -  + ]:       1403 : static inline void pl_log_cpu_time(pl_log log, pl_clock_t start, pl_clock_t stop,
      70                 :            :                                    const char *operation)
      71                 :            : {
      72                 :       1403 :     double ms = pl_clock_diff(stop, start) * 1e3;
      73                 :            :     enum pl_log_level lev = PL_LOG_DEBUG;
      74         [ +  + ]:       1403 :     if (ms > 10)
      75                 :            :         lev = PL_LOG_INFO;
      76         [ +  + ]:        620 :     if (ms > 1000)
      77                 :            :         lev = PL_LOG_WARN;
      78                 :            : 
      79         [ +  + ]:       2693 :     pl_msg(log, lev, "Spent %.3f ms %s%s", ms, operation,
      80                 :            :            ms > 100 ? " (slow!)" : "");
      81                 :       1403 : }
      82                 :            : 
      83                 :            : // Log stack trace
      84                 :            : PL_NOINLINE void pl_log_stack_trace(pl_log log, enum pl_log_level lev);

Generated by: LCOV version 1.16