LCOV - code coverage report
Current view: top level - lib/util - talloc_report_printf.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 0 19 0.0 %
Date: 2024-04-21 15:09:00 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  * talloc_report into a FILE
       3             :  *
       4             :  * Copyright Volker Lendecke <vl@samba.org> 2015
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include "replace.h"
      21             : #include "talloc_report_printf.h"
      22             : 
      23           0 : static void talloc_report_printf_helper(
      24             :         const void *ptr,
      25             :         int depth,
      26             :         int max_depth,
      27             :         int is_ref,
      28             :         void *private_data)
      29             : {
      30           0 :         FILE *f = private_data;
      31           0 :         const char *name = talloc_get_name(ptr);
      32             : 
      33           0 :         if (is_ref) {
      34           0 :                 fprintf(f,
      35             :                         "%*sreference to: %s\n",
      36             :                         depth*4,
      37             :                         "",
      38             :                         name);
      39           0 :                 return;
      40             :         }
      41             : 
      42           0 :         if (depth == 0) {
      43           0 :                 fprintf(f,
      44             :                         "%stalloc report on '%s' "
      45             :                         "(total %6zu bytes in %3zu blocks)\n",
      46             :                         (max_depth < 0 ? "full " :""), name,
      47             :                         talloc_total_size(ptr),
      48             :                         talloc_total_blocks(ptr));
      49           0 :                 return;
      50             :         }
      51             : 
      52           0 :         if (strcmp(name, "char") == 0) {
      53             :                 /*
      54             :                  * Print out the first 50 bytes of the string
      55             :                  */
      56           0 :                 fprintf(f,
      57             :                         "%*s%-30s contains %6zu bytes in %3zu blocks "
      58             :                         "(ref %zu): %*s\n", depth*4, "", name,
      59             :                         talloc_total_size(ptr),
      60             :                         talloc_total_blocks(ptr),
      61             :                         talloc_reference_count(ptr),
      62           0 :                         (int)MIN(50, talloc_get_size(ptr)),
      63             :                         (const char *)ptr);
      64           0 :                 return;
      65             :         }
      66             : 
      67           0 :         fprintf(f,
      68             :                 "%*s%-30s contains %6zu bytes in %3zu blocks (ref %zu) %p\n",
      69             :                 depth*4, "", name,
      70             :                 talloc_total_size(ptr),
      71             :                 talloc_total_blocks(ptr),
      72             :                 talloc_reference_count(ptr),
      73             :                 ptr);
      74             : }
      75             : 
      76           0 : void talloc_full_report_printf(TALLOC_CTX *root, FILE *f)
      77             : {
      78           0 :         talloc_report_depth_cb(root, 0, -1, talloc_report_printf_helper, f);
      79             : #if defined(HAVE_MALLINFO2)
      80             :         {
      81           0 :                 struct mallinfo2 mi2 = mallinfo2();
      82             : 
      83           0 :                 fprintf(f,
      84             :                         "mallinfo:\n"
      85             :                         "    arena: %zu\n"
      86             :                         "    ordblks: %zu\n"
      87             :                         "    smblks: %zu\n"
      88             :                         "    hblks: %zu\n"
      89             :                         "    hblkhd: %zu\n"
      90             :                         "    usmblks: %zu\n"
      91             :                         "    fsmblks: %zu\n"
      92             :                         "    uordblks: %zu\n"
      93             :                         "    fordblks: %zu\n"
      94             :                         "    keepcost: %zu\n",
      95             :                         mi2.arena,
      96             :                         mi2.ordblks,
      97             :                         mi2.smblks,
      98             :                         mi2.hblks,
      99             :                         mi2.hblkhd,
     100             :                         mi2.usmblks,
     101             :                         mi2.fsmblks,
     102             :                         mi2.uordblks,
     103             :                         mi2.fordblks,
     104             :                         mi2.keepcost);
     105             :         }
     106             : #elif defined(HAVE_MALLINFO)
     107             :         {
     108             :                 struct mallinfo mi = mallinfo();
     109             : 
     110             :                 fprintf(f,
     111             :                         "mallinfo:\n"
     112             :                         "    arena: %d\n"
     113             :                         "    ordblks: %d\n"
     114             :                         "    smblks: %d\n"
     115             :                         "    hblks: %d\n"
     116             :                         "    hblkhd: %d\n"
     117             :                         "    usmblks: %d\n"
     118             :                         "    fsmblks: %d\n"
     119             :                         "    uordblks: %d\n"
     120             :                         "    fordblks: %d\n"
     121             :                         "    keepcost: %d\n",
     122             :                         mi.arena,
     123             :                         mi.ordblks,
     124             :                         mi.smblks,
     125             :                         mi.hblks,
     126             :                         mi.hblkhd,
     127             :                         mi.usmblks,
     128             :                         mi.fsmblks,
     129             :                         mi.uordblks,
     130             :                         mi.fordblks,
     131             :                         mi.keepcost);
     132             :         }
     133             : #endif /* HAVE_MALLINFO2 or HAVE_MALLINFO */
     134           0 : }

Generated by: LCOV version 1.14