LCOV - code coverage report
Current view: top level - libs/mem/src - mem_telemetry_summary.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 69.9 % 249 174
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 10 10
Branches: 38.0 % 100 38

             Branch data     Line data    Source code
       1                 :             : #include "mem.h"
       2                 :             : #include <stdio.h>
       3                 :             : 
       4                 :             : /**
       5                 :             :  * @brief Print live-memory balance counters
       6                 :             :  *
       7                 :             :  * @param buf Numeric formatting buffer
       8                 :             :  * @param byte_size_buffer Byte-size formatting buffer
       9                 :             :  */
      10                 :           1 : static void telemetry_summary_print_memory_balance(
      11                 :             :         char *buf,
      12                 :             :         char *byte_size_buffer)
      13                 :             : {
      14                 :           1 :         printf(BOLD "Memory balance" RESET "\n");
      15                 :           1 :         printf(GRAY "Shows what is still alive at shutdown. In a clean run, reserved memory, useful payload, and active descriptors should all return to zero.\n" RESET WHITE);
      16                 :             : 
      17                 :           1 :         printf("Current heap reserved bytes (expected 0B), now is: ");
      18                 :             : 
      19         [ +  - ]:           1 :         if(telemetry.current_heap_reserved_bytes == 0)
      20                 :             :         {
      21                 :           1 :                 printf(BOLDGREEN);
      22                 :             :         } else {
      23                 :           0 :                 printf(BOLDRED);
      24                 :             :         }
      25                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.current_heap_reserved_bytes,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
      26                 :             : 
      27                 :           1 :         printf("Current payload bytes (expected 0B), now is: ");
      28                 :             : 
      29         [ +  - ]:           1 :         if(telemetry.current_payload_bytes == 0)
      30                 :             :         {
      31                 :           1 :                 printf(BOLDGREEN);
      32                 :             :         } else {
      33                 :           0 :                 printf(BOLDRED);
      34                 :             :         }
      35                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.current_payload_bytes,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
      36                 :             : 
      37                 :           1 :         printf("Current active descriptors (expected 0), now is: ");
      38                 :             : 
      39         [ +  - ]:           1 :         if(telemetry.current_active_descriptors == 0)
      40                 :             :         {
      41                 :           1 :                 printf(BOLDGREEN);
      42                 :             :         } else {
      43                 :           0 :                 printf(BOLDRED);
      44                 :             :         }
      45                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.current_active_descriptors,buf,FORM_OUTPUT_BUFFER_SIZE));
      46                 :           1 : }
      47                 :             : 
      48                 :             : /**
      49                 :             :  * @brief Print heap reserve and release counters
      50                 :             :  *
      51                 :             :  * @param buf Numeric formatting buffer
      52                 :             :  * @param byte_size_buffer Byte-size formatting buffer
      53                 :             :  * @param expected_buf Byte-size formatting buffer for expected values
      54                 :             :  * @param now_buf Byte-size formatting buffer for current values
      55                 :             :  */
      56                 :           1 : static void telemetry_summary_print_heap_reserve(
      57                 :             :         char *buf,
      58                 :             :         char *byte_size_buffer,
      59                 :             :         char *expected_buf,
      60                 :             :         char *now_buf)
      61                 :             : {
      62                 :           1 :         printf("\n" BOLD "Heap reserve" RESET "\n");
      63                 :           1 :         printf(GRAY "Shows how much memory was reserved from the system allocator and how much was returned. Reserved memory can be larger than useful data because memory is kept in chunks.\n" RESET WHITE);
      64                 :             : 
      65                 :           1 :         printf("Peak heap reserved bytes");
      66                 :             : 
      67         [ -  + ]:           1 :         if(telemetry.total_heap_reserved_bytes_acquired == 0)
      68                 :             :         {
      69                 :           0 :                 printf(" (expected 0B), now is: ");
      70                 :             : 
      71         [ #  # ]:           0 :                 if(telemetry.peak_heap_reserved_bytes == 0)
      72                 :             :                 {
      73                 :           0 :                         printf(BOLDGREEN);
      74                 :             :                 } else {
      75                 :           0 :                         printf(BOLDRED);
      76                 :             :                 }
      77                 :             :         } else {
      78                 :           1 :                 printf(" (expected > 0), now is: ");
      79                 :             : 
      80         [ +  - ]:           1 :                 if(telemetry.peak_heap_reserved_bytes > 0)
      81                 :             :                 {
      82                 :           1 :                         printf(BOLDGREEN);
      83                 :             :                 } else {
      84                 :           0 :                         printf(BOLDRED);
      85                 :             :                 }
      86                 :             :         }
      87                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.peak_heap_reserved_bytes,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
      88                 :             : 
      89                 :           1 :         printf("Total heap reserved bytes acquired");
      90                 :             : 
      91         [ -  + ]:           1 :         if(telemetry.fresh_heap_allocations == 0)
      92                 :             :         {
      93                 :           0 :                 printf(" (expected 0B), now is: ");
      94                 :             : 
      95         [ #  # ]:           0 :                 if(telemetry.total_heap_reserved_bytes_acquired == 0)
      96                 :             :                 {
      97                 :           0 :                         printf(BOLDGREEN);
      98                 :             :                 } else {
      99                 :           0 :                         printf(BOLDRED);
     100                 :             :                 }
     101                 :             :         } else {
     102                 :           1 :                 printf(" (expected > 0), now is: ");
     103                 :             : 
     104         [ +  - ]:           1 :                 if(telemetry.total_heap_reserved_bytes_acquired > 0)
     105                 :             :                 {
     106                 :           1 :                         printf(BOLDGREEN);
     107                 :             :                 } else {
     108                 :           0 :                         printf(BOLDRED);
     109                 :             :                 }
     110                 :             :         }
     111                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.total_heap_reserved_bytes_acquired,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
     112                 :             : 
     113                 :           1 :         printf("Total heap reserved bytes released (expected %s), now is: ",bkbmbgbtbpbeb_r(telemetry.total_heap_reserved_bytes_acquired,FULL_VIEW,expected_buf,MAX_CHARACTERS));
     114                 :             : 
     115         [ +  - ]:           1 :         if(telemetry.total_heap_reserved_bytes_released == telemetry.total_heap_reserved_bytes_acquired)
     116                 :             :         {
     117                 :           1 :                 printf(BOLDGREEN);
     118                 :             :         } else {
     119                 :           0 :                 printf(BOLDRED);
     120                 :             :         }
     121                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.total_heap_reserved_bytes_released,FULL_VIEW,now_buf,MAX_CHARACTERS));
     122                 :             : 
     123                 :           1 :         printf("Fresh heap allocations");
     124                 :             : 
     125         [ -  + ]:           1 :         if(telemetry.total_heap_reserved_bytes_acquired == 0)
     126                 :             :         {
     127                 :           0 :                 printf(" (expected 0), now is: ");
     128                 :             : 
     129         [ #  # ]:           0 :                 if(telemetry.fresh_heap_allocations == 0)
     130                 :             :                 {
     131                 :           0 :                         printf(BOLDGREEN);
     132                 :             :                 } else {
     133                 :           0 :                         printf(BOLDRED);
     134                 :             :                 }
     135                 :             :         } else {
     136                 :           1 :                 printf(" (expected > 0), now is: ");
     137                 :             : 
     138         [ +  - ]:           1 :                 if(telemetry.fresh_heap_allocations > 0)
     139                 :             :                 {
     140                 :           1 :                         printf(BOLDGREEN);
     141                 :             :                 } else {
     142                 :           0 :                         printf(BOLDRED);
     143                 :             :                 }
     144                 :             :         }
     145                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.fresh_heap_allocations,buf,FORM_OUTPUT_BUFFER_SIZE));
     146                 :             : 
     147                 :           1 :         printf("Heap reallocations: %s\n",form(telemetry.heap_reallocations,buf,FORM_OUTPUT_BUFFER_SIZE));
     148                 :             : 
     149                 :           1 :         printf("Heap buffer releases (expected %zu), now is: ",telemetry.fresh_heap_allocations);
     150                 :             : 
     151         [ +  - ]:           1 :         if(telemetry.heap_buffer_releases == telemetry.fresh_heap_allocations)
     152                 :             :         {
     153                 :           1 :                 printf(BOLDGREEN);
     154                 :             :         } else {
     155                 :           0 :                 printf(BOLDRED);
     156                 :             :         }
     157                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.heap_buffer_releases,buf,FORM_OUTPUT_BUFFER_SIZE));
     158                 :             : 
     159                 :           1 :         printf("Heap allocation failures");
     160                 :             : 
     161         [ -  + ]:           1 :         if(telemetry.expected_heap_allocation_failures == 0)
     162                 :             :         {
     163                 :           0 :                 printf(" (expected 0), now is: ");
     164                 :             :         } else {
     165                 :           1 :                 printf(" (normal 0, expected here %s), now is: ",form(telemetry.expected_heap_allocation_failures,buf,FORM_OUTPUT_BUFFER_SIZE));
     166                 :             :         }
     167                 :             : 
     168         [ +  - ]:           1 :         if(telemetry.heap_allocation_failures == telemetry.expected_heap_allocation_failures)
     169                 :             :         {
     170                 :           1 :                 printf(BOLDGREEN);
     171                 :             :         } else {
     172                 :           0 :                 printf(BOLDRED);
     173                 :             :         }
     174                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.heap_allocation_failures,buf,FORM_OUTPUT_BUFFER_SIZE));
     175                 :             : 
     176                 :           1 :         printf("Heap reallocation failures");
     177                 :             : 
     178         [ -  + ]:           1 :         if(telemetry.expected_heap_reallocation_failures == 0)
     179                 :             :         {
     180                 :           0 :                 printf(" (expected 0), now is: ");
     181                 :             :         } else {
     182                 :           1 :                 printf(" (normal 0, expected here %s), now is: ",form(telemetry.expected_heap_reallocation_failures,buf,FORM_OUTPUT_BUFFER_SIZE));
     183                 :             :         }
     184                 :             : 
     185         [ +  - ]:           1 :         if(telemetry.heap_reallocation_failures == telemetry.expected_heap_reallocation_failures)
     186                 :             :         {
     187                 :           1 :                 printf(BOLDGREEN);
     188                 :             :         } else {
     189                 :           0 :                 printf(BOLDRED);
     190                 :             :         }
     191                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.heap_reallocation_failures,buf,FORM_OUTPUT_BUFFER_SIZE));
     192                 :           1 : }
     193                 :             : 
     194                 :             : /**
     195                 :             :  * @brief Print logical payload counters
     196                 :             :  *
     197                 :             :  * @param buf Numeric formatting buffer
     198                 :             :  * @param byte_size_buffer Byte-size formatting buffer
     199                 :             :  */
     200                 :           1 : static void telemetry_summary_print_payload(
     201                 :             :         char *buf,
     202                 :             :         char *byte_size_buffer)
     203                 :             : {
     204                 :           1 :         printf("\n" BOLD "Payload" RESET "\n");
     205                 :           1 :         printf(GRAY "Shows the useful data area requested by the program. Spare room kept for future growth is counted separately.\n" RESET WHITE);
     206                 :             : 
     207                 :           1 :         printf("Total payload bytes added");
     208                 :             : 
     209         [ -  + ]:           1 :         if(telemetry.fresh_heap_allocations == 0)
     210                 :             :         {
     211                 :           0 :                 printf(" (expected 0B), now is: ");
     212                 :             : 
     213         [ #  # ]:           0 :                 if(telemetry.total_payload_bytes_added == 0)
     214                 :             :                 {
     215                 :           0 :                         printf(BOLDGREEN);
     216                 :             :                 } else {
     217                 :           0 :                         printf(BOLDRED);
     218                 :             :                 }
     219                 :             :         } else {
     220                 :           1 :                 printf(" (expected > 0), now is: ");
     221                 :             : 
     222         [ +  - ]:           1 :                 if(telemetry.total_payload_bytes_added > 0)
     223                 :             :                 {
     224                 :           1 :                         printf(BOLDGREEN);
     225                 :             :                 } else {
     226                 :           0 :                         printf(BOLDRED);
     227                 :             :                 }
     228                 :             :         }
     229                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.total_payload_bytes_added,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
     230                 :             : 
     231                 :           1 :         printf("Zero-initialized payload growths: %s\n",form(telemetry.zero_initialized_payload_growths,buf,FORM_OUTPUT_BUFFER_SIZE));
     232                 :           1 : }
     233                 :             : 
     234                 :             : /**
     235                 :             :  * @brief Print release-unused counters
     236                 :             :  *
     237                 :             :  * @param buf Numeric formatting buffer
     238                 :             :  * @param byte_size_buffer Byte-size formatting buffer
     239                 :             :  */
     240                 :           1 : static void telemetry_summary_print_release_unused(
     241                 :             :         char *buf,
     242                 :             :         char *byte_size_buffer)
     243                 :             : {
     244                 :           1 :         printf("\n" BOLD "Release-unused" RESET "\n");
     245                 :           1 :         printf(GRAY "Shows how often spare memory was intentionally trimmed, and how much reserved memory was returned instead of being kept for reuse.\n" RESET WHITE);
     246                 :             : 
     247                 :           1 :         printf("Release-unused shrink operations");
     248                 :             : 
     249         [ -  + ]:           1 :         if(telemetry.total_release_unused_heap_reserved_bytes_released == 0)
     250                 :             :         {
     251                 :           0 :                 printf(" (expected 0), now is: ");
     252                 :             : 
     253         [ #  # ]:           0 :                 if(telemetry.release_unused_shrinks == 0)
     254                 :             :                 {
     255                 :           0 :                         printf(BOLDGREEN);
     256                 :             :                 } else {
     257                 :           0 :                         printf(BOLDRED);
     258                 :             :                 }
     259                 :             :         } else {
     260                 :           1 :                 printf(" (expected > 0), now is: ");
     261                 :             : 
     262         [ +  - ]:           1 :                 if(telemetry.release_unused_shrinks > 0)
     263                 :             :                 {
     264                 :           1 :                         printf(BOLDGREEN);
     265                 :             :                 } else {
     266                 :           0 :                         printf(BOLDRED);
     267                 :             :                 }
     268                 :             :         }
     269                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.release_unused_shrinks,buf,FORM_OUTPUT_BUFFER_SIZE));
     270                 :             : 
     271                 :           1 :         printf("Total release-unused heap reserved bytes released");
     272                 :             : 
     273         [ -  + ]:           1 :         if(telemetry.release_unused_shrinks == 0)
     274                 :             :         {
     275                 :           0 :                 printf(" (expected 0B), now is: ");
     276                 :             : 
     277         [ #  # ]:           0 :                 if(telemetry.total_release_unused_heap_reserved_bytes_released == 0)
     278                 :             :                 {
     279                 :           0 :                         printf(BOLDGREEN);
     280                 :             :                 } else {
     281                 :           0 :                         printf(BOLDRED);
     282                 :             :                 }
     283                 :             :         } else {
     284                 :           1 :                 printf(" (expected > 0), now is: ");
     285                 :             : 
     286         [ +  - ]:           1 :                 if(telemetry.total_release_unused_heap_reserved_bytes_released > 0)
     287                 :             :                 {
     288                 :           1 :                         printf(BOLDGREEN);
     289                 :             :                 } else {
     290                 :           0 :                         printf(BOLDRED);
     291                 :             :                 }
     292                 :             :         }
     293                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.total_release_unused_heap_reserved_bytes_released,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
     294                 :           1 : }
     295                 :             : 
     296                 :             : /**
     297                 :             :  * @brief Print block-overhead counters
     298                 :             :  *
     299                 :             :  * @param byte_size_buffer Byte-size formatting buffer
     300                 :             :  */
     301                 :           1 : static void telemetry_summary_print_block_overhead(char *byte_size_buffer)
     302                 :             : {
     303                 :           1 :         printf("\n" BOLD "Block overhead" RESET "\n");
     304                 :           1 :         printf(GRAY "Shows spare bytes inside reserved blocks. This is not leaked memory: it is unused capacity kept so nearby growth can often avoid another allocation.\n" RESET WHITE);
     305                 :             : 
     306                 :           1 :         printf("Current block overhead bytes (expected 0B), now is: ");
     307                 :             : 
     308         [ +  - ]:           1 :         if(telemetry.current_block_overhead_bytes == 0)
     309                 :             :         {
     310                 :           1 :                 printf(BOLDGREEN);
     311                 :             :         } else {
     312                 :           0 :                 printf(BOLDRED);
     313                 :             :         }
     314                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.current_block_overhead_bytes,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
     315                 :             : 
     316                 :           1 :         printf("Peak block overhead bytes");
     317                 :             : 
     318         [ -  + ]:           1 :         if(telemetry.total_block_overhead_bytes_added == 0)
     319                 :             :         {
     320                 :           0 :                 printf(" (expected 0B), now is: ");
     321                 :             : 
     322         [ #  # ]:           0 :                 if(telemetry.peak_block_overhead_bytes == 0)
     323                 :             :                 {
     324                 :           0 :                         printf(BOLDGREEN);
     325                 :             :                 } else {
     326                 :           0 :                         printf(BOLDRED);
     327                 :             :                 }
     328                 :             :         } else {
     329                 :           1 :                 printf(" (expected > 0), now is: ");
     330                 :             : 
     331         [ +  - ]:           1 :                 if(telemetry.peak_block_overhead_bytes > 0)
     332                 :             :                 {
     333                 :           1 :                         printf(BOLDGREEN);
     334                 :             :                 } else {
     335                 :           0 :                         printf(BOLDRED);
     336                 :             :                 }
     337                 :             :         }
     338                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.peak_block_overhead_bytes,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
     339                 :             : 
     340                 :           1 :         printf("Total block overhead bytes added");
     341                 :             : 
     342         [ -  + ]:           1 :         if(telemetry.peak_block_overhead_bytes == 0)
     343                 :             :         {
     344                 :           0 :                 printf(" (expected 0B), now is: ");
     345                 :             : 
     346         [ #  # ]:           0 :                 if(telemetry.total_block_overhead_bytes_added == 0)
     347                 :             :                 {
     348                 :           0 :                         printf(BOLDGREEN);
     349                 :             :                 } else {
     350                 :           0 :                         printf(BOLDRED);
     351                 :             :                 }
     352                 :             :         } else {
     353                 :           1 :                 printf(" (expected > 0), now is: ");
     354                 :             : 
     355         [ +  - ]:           1 :                 if(telemetry.total_block_overhead_bytes_added > 0)
     356                 :             :                 {
     357                 :           1 :                         printf(BOLDGREEN);
     358                 :             :                 } else {
     359                 :           0 :                         printf(BOLDRED);
     360                 :             :                 }
     361                 :             :         }
     362                 :           1 :         printf("%s" RESET WHITE "\n",bkbmbgbtbpbeb_r(telemetry.total_block_overhead_bytes_added,FULL_VIEW,byte_size_buffer,MAX_CHARACTERS));
     363                 :           1 : }
     364                 :             : 
     365                 :             : /**
     366                 :             :  * @brief Print resize-behavior counters
     367                 :             :  *
     368                 :             :  * @param buf Numeric formatting buffer
     369                 :             :  */
     370                 :           1 : static void telemetry_summary_print_resize_behavior(char *buf)
     371                 :             : {
     372                 :           1 :         printf("\n" BOLD "Resize behavior" RESET "\n");
     373                 :           1 :         printf(GRAY "Shows how resize requests were handled: by reusing existing storage, changing the allocation, or noticing that the requested size was already current.\n" RESET WHITE);
     374                 :             : 
     375                 :           1 :         printf("In-place resizes: %s\n",form(telemetry.in_place_resizes,buf,FORM_OUTPUT_BUFFER_SIZE));
     376                 :             : 
     377                 :           1 :         printf("No-op resizes");
     378                 :             : 
     379         [ -  + ]:           1 :         if(telemetry.peak_consecutive_noop_resizes == 0)
     380                 :             :         {
     381                 :           0 :                 printf(" (expected 0), now is: ");
     382                 :             : 
     383         [ #  # ]:           0 :                 if(telemetry.noop_resizes == 0)
     384                 :             :                 {
     385                 :           0 :                         printf(BOLDGREEN);
     386                 :             :                 } else {
     387                 :           0 :                         printf(BOLDRED);
     388                 :             :                 }
     389                 :             :         } else {
     390                 :           1 :                 printf(" (expected > 0), now is: ");
     391                 :             : 
     392         [ +  - ]:           1 :                 if(telemetry.noop_resizes > 0)
     393                 :             :                 {
     394                 :           1 :                         printf(BOLDGREEN);
     395                 :             :                 } else {
     396                 :           0 :                         printf(BOLDRED);
     397                 :             :                 }
     398                 :             :         }
     399                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.noop_resizes,buf,FORM_OUTPUT_BUFFER_SIZE));
     400                 :             : 
     401                 :           1 :         printf("Current consecutive no-op resizes (expected 0), now is: ");
     402                 :             : 
     403         [ +  - ]:           1 :         if(telemetry.current_consecutive_noop_resizes == 0)
     404                 :             :         {
     405                 :           1 :                 printf(BOLDGREEN);
     406                 :             :         } else {
     407                 :           0 :                 printf(BOLDRED);
     408                 :             :         }
     409                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.current_consecutive_noop_resizes,buf,FORM_OUTPUT_BUFFER_SIZE));
     410                 :             : 
     411                 :           1 :         printf("Peak consecutive no-op resizes");
     412                 :             : 
     413         [ -  + ]:           1 :         if(telemetry.noop_resizes == 0)
     414                 :             :         {
     415                 :           0 :                 printf(" (expected 0), now is: ");
     416                 :             : 
     417         [ #  # ]:           0 :                 if(telemetry.peak_consecutive_noop_resizes == 0)
     418                 :             :                 {
     419                 :           0 :                         printf(BOLDGREEN);
     420                 :             :                 } else {
     421                 :           0 :                         printf(BOLDRED);
     422                 :             :                 }
     423                 :             :         } else {
     424                 :           1 :                 printf(" (expected > 0), now is: ");
     425                 :             : 
     426         [ +  - ]:           1 :                 if(telemetry.peak_consecutive_noop_resizes > 0)
     427                 :             :                 {
     428                 :           1 :                         printf(BOLDGREEN);
     429                 :             :                 } else {
     430                 :           0 :                         printf(BOLDRED);
     431                 :             :                 }
     432                 :             :         }
     433                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.peak_consecutive_noop_resizes,buf,FORM_OUTPUT_BUFFER_SIZE));
     434                 :           1 : }
     435                 :             : 
     436                 :             : /**
     437                 :             :  * @brief Print string and mode conversion counters
     438                 :             :  *
     439                 :             :  * @param buf Numeric formatting buffer
     440                 :             :  */
     441                 :           1 : static void telemetry_summary_print_string_and_mode_conversions(char *buf)
     442                 :             : {
     443                 :           1 :         printf("\n" BOLD "String and mode conversions" RESET "\n");
     444                 :           1 :         printf(GRAY "Shows string maintenance work, such as writing terminators, finalizing manually written strings, and switching storage between raw data and text.\n" RESET WHITE);
     445                 :             : 
     446                 :           1 :         printf("Data-to-string conversions: %s\n",form(telemetry.data_to_string_conversions,buf,FORM_OUTPUT_BUFFER_SIZE));
     447                 :             : 
     448                 :           1 :         printf("String-to-data conversions: %s\n",form(telemetry.string_to_data_conversions,buf,FORM_OUTPUT_BUFFER_SIZE));
     449                 :             : 
     450                 :           1 :         printf("Finalize string terminator already present: %s\n",form(telemetry.finalize_string_terminator_already_present,buf,FORM_OUTPUT_BUFFER_SIZE));
     451                 :             : 
     452                 :           1 :         printf("Finalize string terminator written when missing");
     453                 :             : 
     454         [ -  + ]:           1 :         if(telemetry.string_terminator_writes == 0)
     455                 :             :         {
     456                 :           0 :                 printf(" (expected 0), now is: ");
     457                 :             : 
     458         [ #  # ]:           0 :                 if(telemetry.finalize_string_terminator_written_when_missing == 0)
     459                 :             :                 {
     460                 :           0 :                         printf(BOLDGREEN);
     461                 :             :                 } else {
     462                 :           0 :                         printf(BOLDRED);
     463                 :             :                 }
     464                 :           0 :                 printf("%s" RESET WHITE "\n",form(telemetry.finalize_string_terminator_written_when_missing,buf,FORM_OUTPUT_BUFFER_SIZE));
     465                 :             :         } else {
     466                 :           1 :                 printf(": %s\n",form(telemetry.finalize_string_terminator_written_when_missing,buf,FORM_OUTPUT_BUFFER_SIZE));
     467                 :             :         }
     468                 :             : 
     469                 :           1 :         printf("String terminator writes");
     470                 :             : 
     471         [ +  - ]:           1 :         if(telemetry.finalize_string_terminator_written_when_missing > 0)
     472                 :             :         {
     473                 :           1 :                 printf(" (expected > 0), now is: ");
     474                 :             : 
     475         [ +  - ]:           1 :                 if(telemetry.string_terminator_writes > 0)
     476                 :             :                 {
     477                 :           1 :                         printf(BOLDGREEN);
     478                 :             :                 } else {
     479                 :           0 :                         printf(BOLDRED);
     480                 :             :                 }
     481                 :           1 :                 printf("%s" RESET WHITE "\n",form(telemetry.string_terminator_writes,buf,FORM_OUTPUT_BUFFER_SIZE));
     482                 :             :         } else {
     483                 :           0 :                 printf(": %s\n",form(telemetry.string_terminator_writes,buf,FORM_OUTPUT_BUFFER_SIZE));
     484                 :             :         }
     485                 :           1 : }
     486                 :             : 
     487                 :             : /**
     488                 :             :  * @brief Print active-descriptor counters
     489                 :             :  *
     490                 :             :  * @param buf Numeric formatting buffer
     491                 :             :  */
     492                 :           1 : static void telemetry_summary_print_descriptor_activity(char *buf)
     493                 :             : {
     494                 :           1 :         printf("\n" BOLD "Descriptor activity" RESET "\n");
     495                 :           1 :         printf(GRAY "Shows the highest number of heap-owning descriptors alive at the same time.\n" RESET WHITE);
     496                 :             : 
     497                 :           1 :         printf("Peak active descriptors");
     498                 :             : 
     499         [ -  + ]:           1 :         if(telemetry.fresh_heap_allocations == 0)
     500                 :             :         {
     501                 :           0 :                 printf(" (expected 0), now is: ");
     502                 :             : 
     503         [ #  # ]:           0 :                 if(telemetry.peak_active_descriptors == 0)
     504                 :             :                 {
     505                 :           0 :                         printf(BOLDGREEN);
     506                 :             :                 } else {
     507                 :           0 :                         printf(BOLDRED);
     508                 :             :                 }
     509                 :             :         } else {
     510                 :           1 :                 printf(" (expected > 0), now is: ");
     511                 :             : 
     512         [ +  - ]:           1 :                 if(telemetry.peak_active_descriptors > 0)
     513                 :             :                 {
     514                 :           1 :                         printf(BOLDGREEN);
     515                 :             :                 } else {
     516                 :           0 :                         printf(BOLDRED);
     517                 :             :                 }
     518                 :             :         }
     519                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.peak_active_descriptors,buf,FORM_OUTPUT_BUFFER_SIZE));
     520                 :           1 : }
     521                 :             : 
     522                 :             : /**
     523                 :             :  * @brief Print safety counters
     524                 :             :  *
     525                 :             :  * @param buf Numeric formatting buffer
     526                 :             :  */
     527                 :           1 : static void telemetry_summary_print_safety(char *buf)
     528                 :             : {
     529                 :           1 :         printf("\n" BOLD "Safety" RESET "\n");
     530                 :           1 :         printf(GRAY "Shows size-calculation problems caught before they could lead to unsafe memory work.\n" RESET WHITE);
     531                 :             : 
     532                 :           1 :         printf("Arithmetic guard failures");
     533                 :             : 
     534         [ -  + ]:           1 :         if(telemetry.expected_arithmetic_guard_failures == 0)
     535                 :             :         {
     536                 :           0 :                 printf(" (expected 0), now is: ");
     537                 :             :         } else {
     538                 :           1 :                 printf(" (normal 0, expected here %s), now is: ",form(telemetry.expected_arithmetic_guard_failures,buf,FORM_OUTPUT_BUFFER_SIZE));
     539                 :             :         }
     540                 :             : 
     541         [ +  - ]:           1 :         if(telemetry.arithmetic_guard_failures == telemetry.expected_arithmetic_guard_failures)
     542                 :             :         {
     543                 :           1 :                 printf(BOLDGREEN);
     544                 :             :         } else {
     545                 :           0 :                 printf(BOLDRED);
     546                 :             :         }
     547                 :           1 :         printf("%s" RESET WHITE "\n",form(telemetry.arithmetic_guard_failures,buf,FORM_OUTPUT_BUFFER_SIZE));
     548                 :           1 : }
     549                 :             : 
     550                 :           1 : void telemetry_summary(void)
     551                 :             : {
     552                 :             :         char buf[FORM_OUTPUT_BUFFER_SIZE];
     553                 :             :         char byte_size_buffer[MAX_CHARACTERS];
     554                 :             :         char expected_buf[MAX_CHARACTERS];
     555                 :             :         char now_buf[MAX_CHARACTERS];
     556                 :             : 
     557                 :           1 :         telemetry_summary_print_memory_balance(buf,byte_size_buffer);
     558                 :           1 :         telemetry_summary_print_heap_reserve(buf,byte_size_buffer,expected_buf,now_buf);
     559                 :           1 :         telemetry_summary_print_payload(buf,byte_size_buffer);
     560                 :           1 :         telemetry_summary_print_release_unused(buf,byte_size_buffer);
     561                 :           1 :         telemetry_summary_print_block_overhead(byte_size_buffer);
     562                 :           1 :         telemetry_summary_print_resize_behavior(buf);
     563                 :           1 :         telemetry_summary_print_string_and_mode_conversions(buf);
     564                 :           1 :         telemetry_summary_print_descriptor_activity(buf);
     565                 :           1 :         telemetry_summary_print_safety(buf);
     566                 :           1 : }
        

Generated by: LCOV version 2.0-1