<commit_before>
/**
 * debug.c
 *
 * Debugging reports for Turbine
 * */

#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "src/util/debug.h"

static bool  initialized = false;
static bool  enabled = true;
static char* buffer = NULL;
static const int buffer_size = 2*1024;

void
turbine_debug_init()
{
  if (initialized)
  {
    printf("turbine_debug: already initialized\n");
    return;
  }
  initialized = true;
  char* s = getenv("DEBUG");
  if (s != NULL)
    if (strcmp(s, "0") == 0)
    {
      enabled = false;
      return;
    }
  buffer = malloc(buffer_size);
}

/**
   All turbine_debug messages may be disabled by setting
   DEBUG=0 (number 0) in the environment.
   We have to put everything into one string before we print it,
   otherwise mpiexec -l does not print the rank things [0]
   correctly.
*/
void
turbine_debug(const char* token, const char* format, ...)
{
  if (!enabled)
    return;
  assert(initialized);

  va_list va;
  va_start(va, format);
  int count = 0;
  count += sprintf(buffer, "%s: ", token);
  count += vsnprintf(buffer+count, buffer_size-count, format, va);
  if (count >= buffer_size)
    printf("turbine_debug: message exceeded buffer_size (%i)\n",
           buffer_size);
  printf("%s", buffer);<commit_msg>Add GCC attribute to implementation as well<commit_after>
/**
 * debug.c
 *
 * Debugging reports for Turbine
 * */

#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "src/util/debug.h"

static bool  initialized = false;
static bool  enabled = true;
static char* buffer = NULL;
static const int buffer_size = 2*1024;

void
turbine_debug_init()
{
  if (initialized)
  {
    printf("turbine_debug: already initialized\n");
    return;
  }
  initialized = true;
  char* s = getenv("DEBUG");
  if (s != NULL)
    if (strcmp(s, "0") == 0)
    {
      enabled = false;
      return;
    }
  buffer = malloc(buffer_size);
}

/**
   All turbine_debug messages may be disabled by setting
   DEBUG=0 (number 0) in the environment.
   We have to put everything into one string before we print it,
   otherwise mpiexec -l does not print the rank things [0]
   correctly.
*/
__attribute__ ((format (printf, 2, 3)))
void
turbine_debug(const char* token, const char* format, ...)
{
  if (!enabled)
    return;
  assert(initialized);

  va_list va;
  va_start(va, format);
  int count = 0;
  count += sprintf(buffer, "%s: ", token);
  count += vsnprintf(buffer+count, buffer_size-count, format, va);
  if (count >= buffer_size)
    printf("turbine_debug: message exceeded buffer_size (%i)\n",
           buffer_size);
  printf("%s", buffer);
{'fraction_non_alphanumeric': 0.13513513513513514, 'fraction_numerical': 0.008765522279035792, 'mean_word_length': 3.4754901960784315, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6398220', 'n_tokens_mistral': 955, 'n_tokens_neox': 937, 'n_words': 284}