<commit_before>/*
 * dag recorder 2.0
 */

#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* 
     task ::= section* end
     section ::= task_group (section|create)* wait 

 */

#ifdef __cplusplus
extern "C" {
#endif

  /* they must be provided by the underlying
     system (or by the user) */
  int dr_get_worker();
  int dr_get_num_workers();
  int dr_get_cpu();

  /* a kind of nodes */
  typedef enum {
    dr_dag_node_kind_task_group,
    dr_dag_node_kind_create_task,
    dr_dag_node_kind_wait_tasks,
    dr_dag_node_kind_end_task,
    dr_dag_node_kind_section,
    dr_dag_node_kind_task
  } dr_dag_node_kind_t;
  
  typedef struct dr_dag_node_list dr_dag_node_list;

  typedef unsigned long long dr_clock_t;

  /* a node of the dag */
  struct dr_dag_node {
    dr_dag_node_kind_t kind;
    dr_clock_t start; 
    dr_clock_t est;
    dr_clock_t end; 
    dr_clock_t t_1;
    dr_clock_t t_inf;
    long n_nodes; 
    long n_edges; 
    int worker;
    int cpu;
    union {
      dr_dag_node * child;		/* kind == create_task */
      struct {
	dr_dag_node_list * subgraphs;	/* kind == section/task */
	int done;
	int collapsed;
      };
    };
  };

  enum { dr_dag_node_chunk_sz = 5 };
  typedef struct dr_dag_node_chunk {
    struct dr_dag_node_chunk * next;
    dr_dag_node a[dr_dag_node_chunk_sz];
    int n;
  } dr_dag_node_chunk;

  struct dr_dag_node_list {
    dr_dag_node_chunk * tail;
    dr_dag_node_chunk head[1];
  };

  typedef struct dr_thread_specific_state {
    union {
      struct {
	dr_dag_node * task;		/* current task */
      };
      char minimum_size[64];
    };
  } dr_thread_specific_state;

  typedef struct dr_global_state {
    /* root of the task graph. 
       used (only) by print_task_graph */
    dr_dag_node * root;
    /* the clock when dr_start() was called */
    dr_clock_t start_clock;
    dr_options opts;
  } dr_global_state;

#define dr_check(x) if (!(x)) { fprintf(stderr, "%s:%d:%s: dag recorder check failed : %s\n", __FILE__, __LINE__, __func__, #x); exit(1); }

  extern dr_thread_specific_state * TS;
  extern dr_global_state GS;

  /* malloc and free */

  static void * 
  dr_malloc(size_t sz) {
    void * a = malloc(sz);
    if (!a) { perror("malloc"); exit(1); }
    return a;
  }

  static void
  dr_free(void * a, size_t sz) {
    if (a) {
      if (GS.opts.dbg_level>=1) memset(a, 222, sz);
      free(a);
    } else {
      dr_check(sz == 0);
    }
  }

  /* chunk */

  static inline void
  dr_dag_node_chunk_init(dr_dag_node_chunk * ch) {
    ch->next = 0;
    ch->n = 0;
  }

  static inline dr_dag_node * 
  dr_dag_node_chunk_last(dr_dag_node_chunk * ch) {
    dr_check(ch->n > 0);
    return &ch->a[ch->n - 1];
  }

  static inline dr_dag_node * 
  dr_dag_node_chunk_first(dr_dag_node_chunk * ch) {
    dr_check(ch->n > 0);
    return &ch->a[0];
  }

  static inline dr_dag_node * 
  dr_dag_node_chunk_push_back(dr_dag_node_chunk * ch) {
    int n = ch->n;
    dr_check(n < dr_dag_node_chunk_sz);
    ch->n = n + 1;
    return &ch->a[n];
  }

  /* list */

  static inline void 
  dr_dag_node_list_init(dr_dag_node_list * l) {
    dr_dag_node_chunk_init(l->head);
    l->tail = l->head;
  }

  dr_dag_node_list * 
  dr_mk_dag_node_list() {
    dr_dag_node_list * l 
      = (dr_dag_node_list *)dr_malloc(sizeof(dr_dag_node_list));
    dr_dag_node_list_init(l);
    return l;
  }

  static inline int
  dr_dag_node_list_empty(dr_dag_node_list * l) {
    if (l->head != l->tail) return 0;
    if (l->head->n) return 0;
    return 1;
  }

  static inline dr_dag_node *
  dr_dag_node_list_first(dr_dag_node_list * l) {
    return dr_dag_node_chunk_first(l->head);
  }

  static inline dr_dag_node *
  dr_dag_node_list_last(dr_dag_node_list * l) {
    return dr_dag_node_chunk_last(l->tail);
  }
<commit_msg>bug fix<commit_after>/*
 * dag recorder 2.0
 */

#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* 
     task ::= section* end
     section ::= task_group (section|create)* wait 

 */

#ifdef __cplusplus
extern "C" {
#endif

  /* they must be provided by the underlying
     system (or by the user) */
  int dr_get_worker();
  int dr_get_num_workers();
  int dr_get_cpu();

  /* a kind of nodes */
  typedef enum {
    dr_dag_node_kind_task_group,
    dr_dag_node_kind_create_task,
    dr_dag_node_kind_wait_tasks,
    dr_dag_node_kind_end_task,
    dr_dag_node_kind_section,
    dr_dag_node_kind_task
  } dr_dag_node_kind_t;
  
  typedef struct dr_dag_node_list dr_dag_node_list;

  typedef unsigned long long dr_clock_t;

  /* a node of the dag */
  struct dr_dag_node {
    dr_dag_node_kind_t kind;
    dr_clock_t start; 
    dr_clock_t est;
    dr_clock_t end; 
    dr_clock_t t_1;
    dr_clock_t t_inf;
    long n_nodes; 
    long n_edges; 
    int worker;
    int cpu;
    union {
      dr_dag_node * child;		/* kind == create_task */
      struct {
	dr_dag_node_list * subgraphs;	/* kind == section/task */
	int done;
	int collapsed;
      };
    };
  };

  enum { dr_dag_node_chunk_sz = 5 };
  typedef struct dr_dag_node_chunk {
    struct dr_dag_node_chunk * next;
    dr_dag_node a[dr_dag_node_chunk_sz];
    int n;
  } dr_dag_node_chunk;

  struct dr_dag_node_list {
    dr_dag_node_chunk * tail;
    dr_dag_node_chunk head[1];
  };

  typedef struct dr_thread_specific_state {
    union {
      struct {
	dr_dag_node * task;		/* current task */
      };
      char minimum_size[64];
    };
  } dr_thread_specific_state;

  typedef struct dr_global_state {
    /* root of the task graph. 
       used (only) by print_task_graph */
    dr_dag_node * root;
    /* the clock when dr_start() was called */
    dr_clock_t start_clock;
    dr_options opts;
  } dr_global_state;

#define dr_check(x) if (!(x)) { fprintf(stderr, "%s:%d:%s: dag recorder check failed : %s\n", __FILE__, __LINE__, __func__, #x); exit(1); }

  extern dr_thread_specific_state * TS;
  extern dr_global_state GS;

  /* malloc and free */

  static void * 
  dr_malloc(size_t sz) {
    void * a = malloc(sz);
    if (!a) { perror("malloc"); exit(1); }
    return a;
  }

  static void
  dr_free(void * a, size_t sz) {
    if (a) {
      if (GS.opts.dbg_level>=1) memset(a, 222, sz);
      free(a);
    } else {
      dr_check(sz == 0);
    }
  }

  /* chunk */

  static inline void
  dr_dag_node_chunk_init(dr_dag_node_chunk * ch) {
    ch->next = 0;
    ch->n = 0;
  }

  static inline dr_dag_node * 
  dr_dag_node_chunk_last(dr_dag_node_chunk * ch) {
    dr_check(ch->n > 0);
    return &ch->a[ch->n - 1];
  }

  static inline dr_dag_node * 
  dr_dag_node_chunk_first(dr_dag_node_chunk * ch) {
    dr_check(ch->n > 0);
    return &ch->a[0];
  }

  static inline dr_dag_node * 
  dr_dag_node_chunk_push_back(dr_dag_node_chunk * ch) {
    int n = ch->n;
    dr_check(n < dr_dag_node_chunk_sz);
    ch->n = n + 1;
    return &ch->a[n];
  }

  /* list */

  static inline void 
  dr_dag_node_list_init(dr_dag_node_list * l) {
    dr_dag_node_chunk_init(l->head);
    l->tail = l->head;
  }

  static inline dr_dag_node_list * 
  dr_mk_dag_node_list() {
    dr_dag_node_list * l 
      = (dr_dag_node_list *)dr_malloc(sizeof(dr_dag_node_list));
    dr_dag_node_list_init(l);
    return l;
  }

  static inline int
  dr_dag_node_list_empty(dr_dag_node_list * l) {
    if (l->head != l->tail) return 0;
    if (l->head->n) return 0;
    return 1;
  }

  static inline dr_dag_node *
  dr_dag_node_list_first(dr_dag_node_list * l) {
    return dr_dag_node_chunk_first(l->head);
  }

  static inline dr_dag_node *
  dr_dag_node_list_last(dr_dag_node_list * l) {
    return dr_dag_node_chunk_last(l->tail);
  }

{'fraction_non_alphanumeric': 0.11324224908039937, 'fraction_numerical': 0.006305832895428271, 'mean_word_length': 2.92827657378741, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, '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': '1178835', 'n_tokens_mistral': 3118, 'n_tokens_neox': 2989, 'n_words': 621}