LCOV - code coverage report
Current view: top level - gjs - mem.cpp (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 87.5 % 16 14
Test Date: 2024-04-16 04:37:39 Functions: 100.0 % 1 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 80.0 % 10 8

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2008 litl, LLC
       4                 :             : 
       5                 :             : #include <config.h>
       6                 :             : 
       7                 :             : #include <stdint.h>
       8                 :             : 
       9                 :             : #include <glib.h>
      10                 :             : 
      11                 :             : #include "gjs/mem-private.h"
      12                 :             : #include "gjs/mem.h"
      13                 :             : #include "util/log.h"
      14                 :             : 
      15                 :             : namespace Gjs {
      16                 :             : namespace Memory {
      17                 :             : namespace Counters {
      18                 :             : #define GJS_DEFINE_COUNTER(name, ix) Counter name(#name);
      19                 :             : 
      20                 :             : GJS_DEFINE_COUNTER(everything, -1)
      21                 :             : GJS_FOR_EACH_COUNTER(GJS_DEFINE_COUNTER)
      22                 :             : }  // namespace Counters
      23                 :             : }  // namespace Memory
      24                 :             : }  // namespace Gjs
      25                 :             : 
      26                 :             : #define GJS_LIST_COUNTER(name, ix) &Gjs::Memory::Counters::name,
      27                 :             : 
      28                 :             : static Gjs::Memory::Counter* counters[] = {
      29                 :             :     GJS_FOR_EACH_COUNTER(GJS_LIST_COUNTER)};
      30                 :             : 
      31                 :             : void
      32                 :          96 : gjs_memory_report(const char *where,
      33                 :             :                   bool        die_if_leaks)
      34                 :             : {
      35                 :             :     int i;
      36                 :             :     int n_counters;
      37                 :             :     int64_t total_objects;
      38                 :             : 
      39                 :          96 :     gjs_debug(GJS_DEBUG_MEMORY,
      40                 :             :               "Memory report: %s",
      41                 :             :               where);
      42                 :             : 
      43                 :          96 :     n_counters = G_N_ELEMENTS(counters);
      44                 :             : 
      45                 :          96 :     total_objects = 0;
      46         [ +  + ]:        1632 :     for (i = 0; i < n_counters; ++i) {
      47                 :        1536 :         total_objects += counters[i]->value;
      48                 :             :     }
      49                 :             : 
      50         [ -  + ]:          96 :     if (total_objects != GJS_GET_COUNTER(everything)) {
      51                 :           0 :         gjs_debug(GJS_DEBUG_MEMORY,
      52                 :             :                   "Object counts don't add up!");
      53                 :             :     }
      54                 :             : 
      55                 :          96 :     gjs_debug(GJS_DEBUG_MEMORY,
      56                 :             :               "  %" G_GINT64_FORMAT " objects currently alive",
      57                 :             :               GJS_GET_COUNTER(everything));
      58                 :             : 
      59         [ +  + ]:          96 :     if (GJS_GET_COUNTER(everything) != 0) {
      60         [ +  + ]:         816 :         for (i = 0; i < n_counters; ++i) {
      61                 :        1536 :             gjs_debug(GJS_DEBUG_MEMORY, "    %24s = %" G_GINT64_FORMAT,
      62                 :        1536 :                       counters[i]->name, counters[i]->value.load());
      63                 :             :         }
      64                 :             : 
      65         [ -  + ]:          48 :         if (die_if_leaks)
      66                 :           0 :             g_error("%s: JavaScript objects were leaked.", where);
      67                 :             :     }
      68                 :          96 : }
        

Generated by: LCOV version 2.0-1