LCOV - differential code coverage report
Current view: top level - src/backend/utils/misc - pg_rusage.c (source / functions) Coverage Total Hit UBC CBC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 91.7 % 24 22 2 22
Current Date: 2025-09-06 07:49:51 +0900 Functions: 100.0 % 2 2 2
Baseline: lcov-20250906-005545-baseline Branches: 83.3 % 6 5 1 5
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 91.7 % 24 22 2 22
Function coverage date bins:
(360..) days: 100.0 % 2 2 2
Branch coverage date bins:
(360..) days: 83.3 % 6 5 1 5

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * pg_rusage.c
                                  4                 :                :  *    Resource usage measurement support routines.
                                  5                 :                :  *
                                  6                 :                :  *
                                  7                 :                :  * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
                                  8                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  9                 :                :  *
                                 10                 :                :  *
                                 11                 :                :  * IDENTIFICATION
                                 12                 :                :  *    src/backend/utils/misc/pg_rusage.c
                                 13                 :                :  *
                                 14                 :                :  *-------------------------------------------------------------------------
                                 15                 :                :  */
                                 16                 :                : #include "postgres.h"
                                 17                 :                : 
                                 18                 :                : #include <unistd.h>
                                 19                 :                : 
                                 20                 :                : #include "utils/pg_rusage.h"
                                 21                 :                : 
                                 22                 :                : 
                                 23                 :                : /*
                                 24                 :                :  * Initialize usage snapshot.
                                 25                 :                :  */
                                 26                 :                : void
 7278 tgl@sss.pgh.pa.us          27                 :CBC        5057 : pg_rusage_init(PGRUsage *ru0)
                                 28                 :                : {
                                 29                 :           5057 :     getrusage(RUSAGE_SELF, &ru0->ru);
 7259 andrew@dunslane.net        30                 :           5057 :     gettimeofday(&ru0->tv, NULL);
 7278 tgl@sss.pgh.pa.us          31                 :           5057 : }
                                 32                 :                : 
                                 33                 :                : /*
                                 34                 :                :  * Compute elapsed time since ru0 usage snapshot, and format into
                                 35                 :                :  * a displayable string.  Result is in a static string, which is
                                 36                 :                :  * tacky, but no one ever claimed that the Postgres backend is
                                 37                 :                :  * threadable...
                                 38                 :                :  */
                                 39                 :                : const char *
                                 40                 :            311 : pg_rusage_show(const PGRUsage *ru0)
                                 41                 :                : {
                                 42                 :                :     static char result[100];
                                 43                 :                :     PGRUsage    ru1;
                                 44                 :                : 
                                 45                 :            311 :     pg_rusage_init(&ru1);
                                 46                 :                : 
                                 47         [ +  + ]:            311 :     if (ru1.tv.tv_usec < ru0->tv.tv_usec)
                                 48                 :                :     {
                                 49                 :             23 :         ru1.tv.tv_sec--;
                                 50                 :             23 :         ru1.tv.tv_usec += 1000000;
                                 51                 :                :     }
                                 52         [ -  + ]:            311 :     if (ru1.ru.ru_stime.tv_usec < ru0->ru.ru_stime.tv_usec)
                                 53                 :                :     {
 7278 tgl@sss.pgh.pa.us          54                 :UBC           0 :         ru1.ru.ru_stime.tv_sec--;
                                 55                 :              0 :         ru1.ru.ru_stime.tv_usec += 1000000;
                                 56                 :                :     }
 7278 tgl@sss.pgh.pa.us          57         [ +  + ]:CBC         311 :     if (ru1.ru.ru_utime.tv_usec < ru0->ru.ru_utime.tv_usec)
                                 58                 :                :     {
                                 59                 :              1 :         ru1.ru.ru_utime.tv_sec--;
                                 60                 :              1 :         ru1.ru.ru_utime.tv_usec += 1000000;
                                 61                 :                :     }
                                 62                 :                : 
                                 63                 :            311 :     snprintf(result, sizeof(result),
 3016 alvherre@alvh.no-ip.       64                 :            311 :              _("CPU: user: %d.%02d s, system: %d.%02d s, elapsed: %d.%02d s"),
 7278 tgl@sss.pgh.pa.us          65                 :            311 :              (int) (ru1.ru.ru_utime.tv_sec - ru0->ru.ru_utime.tv_sec),
 2999                            66                 :            311 :              (int) (ru1.ru.ru_utime.tv_usec - ru0->ru.ru_utime.tv_usec) / 10000,
 3244 peter_e@gmx.net            67                 :            311 :              (int) (ru1.ru.ru_stime.tv_sec - ru0->ru.ru_stime.tv_sec),
 2999 tgl@sss.pgh.pa.us          68                 :            311 :              (int) (ru1.ru.ru_stime.tv_usec - ru0->ru.ru_stime.tv_usec) / 10000,
 7278                            69                 :            311 :              (int) (ru1.tv.tv_sec - ru0->tv.tv_sec),
                                 70                 :            311 :              (int) (ru1.tv.tv_usec - ru0->tv.tv_usec) / 10000);
                                 71                 :                : 
                                 72                 :            311 :     return result;
                                 73                 :                : }
        

Generated by: LCOV version 2.4-beta