LCOV - code coverage report
Current view: top level - core - console-log.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 21 21 100.0 %
Date: 2024-01-02 21:04:04 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Console Log routines
       4                 :            :  * Wraps libc and console lower level functions
       5                 :            :  * does fancy-schmancy things like timestamps and priorities
       6                 :            :  * Doesn't make waffles.
       7                 :            :  *
       8                 :            :  * Copyright 2013-2018 IBM Corp.
       9                 :            :  */
      10                 :            : 
      11                 :            : #include "skiboot.h"
      12                 :            : #include "unistd.h"
      13                 :            : #include "stdio.h"
      14                 :            : #include "console.h"
      15                 :            : #include "timebase.h"
      16                 :            : #include <debug_descriptor.h>
      17                 :            : 
      18                 :         13 : int vprlog(int log_level, const char *fmt, va_list ap)
      19                 :            : {
      20                 :            :         int count;
      21                 :            :         char buffer[320];
      22                 :         13 :         bool flush_to_drivers = true;
      23                 :         13 :         unsigned long tb = mftb();
      24                 :            : 
      25                 :            :         /* It's safe to return 0 when we "did" something here
      26                 :            :          * as only printf cares about how much we wrote, and
      27                 :            :          * if you change log_level to below PR_PRINTF then you
      28                 :            :          * get everything you deserve.
      29                 :            :          * By default, only PR_DEBUG and higher are stored in memory.
      30                 :            :          * PR_TRACE and PR_INSANE are for those having a bad day.
      31                 :            :          */
      32                 :         13 :         if (log_level > (debug_descriptor.console_log_levels >> 4))
      33                 :          2 :                 return 0;
      34                 :            : 
      35                 :         11 :         count = snprintf(buffer, sizeof(buffer), "[%5lu.%09lu,%d] ",
      36                 :            :                          tb_to_secs(tb), tb_remaining_nsecs(tb), log_level);
      37                 :         11 :         count+= vsnprintf(buffer+count, sizeof(buffer)-count, fmt, ap);
      38                 :            : 
      39                 :         11 :         if (log_level > (debug_descriptor.console_log_levels & 0x0f))
      40                 :          2 :                 flush_to_drivers = false;
      41                 :            : 
      42                 :         11 :         console_write(flush_to_drivers, buffer, count);
      43                 :            : 
      44                 :         11 :         return count;
      45                 :            : }
      46                 :            : 
      47                 :            : /* we don't return anything as what on earth are we going to do
      48                 :            :  * if we actually fail to print a log message? Print a log message about it?
      49                 :            :  * Callers shouldn't care, prlog and friends should do something generically
      50                 :            :  * sane in such crazy situations.
      51                 :            :  */
      52                 :         10 : void _prlog(int log_level, const char* fmt, ...)
      53                 :            : {
      54                 :            :         va_list ap;
      55                 :            : 
      56                 :         10 :         va_start(ap, fmt);
      57                 :         10 :         vprlog(log_level, fmt, ap);
      58                 :         10 :         va_end(ap);
      59                 :         10 : }
      60                 :            : 
      61                 :          2 : int _printf(const char* fmt, ...)
      62                 :            : {
      63                 :            :         int count;
      64                 :            :         va_list ap;
      65                 :            : 
      66                 :          3 :         va_start(ap, fmt);
      67                 :          3 :         count = vprlog(PR_PRINTF, fmt, ap);
      68                 :          3 :         va_end(ap);
      69                 :            : 
      70                 :          3 :         return count;
      71                 :            : }

Generated by: LCOV version 1.14