<commit_before>/* 
 * gen_gpl.c
 */

#include <errno.h>
#include <string.h>
#include "dag_recorder_impl.h"

/* 
   this file calculates a time series
   of the number of running and ready
   tasks and generates a gnuplot file.
 */

/* the state of a node.
   a node is either 
   (i) not ready,
   (ii) ready but not running, 
   (iii) running, or 
   (iv) finished
   we do not explicitly count (i) or (iv).
   ready tasks (category (ii)) are further
   classified by the event that made them
   ready.

   create : a task created a task and the
   node is the first node the create task
   create_cont : a task created a task and the
   node is the first in the parent task after 
   create_task
   end : a task issued a wait_task at one
   point, when one of the waited children
   has not yet finished. later the last
   child finished and the task is now ready.
   the node is the first node after wait_tasks
   wait_cont : a task issued a wait_task,
   when all waited children have finished.
   the node is the first node after wait_tasks
 */
typedef enum {
  dr_node_state_running,
  dr_node_state_end,
  dr_node_state_create,
  dr_node_state_create_cont,
  dr_node_state_wait_cont,
  dr_node_state_end_cont,
  dr_node_state_max,
} dr_node_state_t;

/* an entry in the parallelism profile. */
typedef struct {
  dr_clock_t t;			/* time */
  int a[dr_node_state_max];	/* count of nodes in each state */
} dr_para_prof_history_entry;

typedef struct {
  /* this must be the first element */
  void (*process_event)(chronological_traverser * ct, dr_event evt);
  int counts[dr_node_state_max];
  dr_clock_t last_time;
  dr_para_prof_history_entry * history;
  long hist_sz;
  long n_hists;
} dr_para_prof;

static void 
dr_para_prof_process_event(chronological_traverser * pp, dr_event evt);

static void 
dr_para_prof_init(dr_para_prof * pp, long hist_sz, dr_clock_t last_time) {
  int i;
  for (i = 0; i < dr_node_state_max; i++) {
    pp->counts[i] = 0;
  }
  pp->process_event = dr_para_prof_process_event;
  pp->last_time = last_time;
  pp->hist_sz = hist_sz;
  pp->n_hists = 0;
  pp->history = (dr_para_prof_history_entry *)
    dr_malloc(sizeof(dr_para_prof_history_entry) * hist_sz);
}

static void 
dr_para_prof_add_hist(dr_para_prof * pp, dr_clock_t t) {
  long sz = pp->hist_sz;
  long n = pp->n_hists;
  dr_para_prof_history_entry * hist = pp->history;
  long last_t = (n ? hist[n-1].t : 0);
  // (last_t + (t - last_t) * (sz - n) >= pp->last_time)

  if (t / (double)pp->last_time >= n / (double)sz) {
    int i;
    dr_para_prof_history_entry * h = &hist[n];
    assert(n < sz);
    h->t = t;
    for (i = 0; i < dr_node_state_max; i++) {
      h->a[i] = pp->counts[i];<commit_msg>bug fix in gnuplot generation<commit_after>/* 
 * gen_gpl.c
 */

#include <errno.h>
#include <string.h>
#include "dag_recorder_impl.h"

/* 
   this file calculates a time series
   of the number of running and ready
   tasks and generates a gnuplot file.
 */

/* the state of a node.
   a node is either 
   (i) not ready,
   (ii) ready but not running, 
   (iii) running, or 
   (iv) finished
   we do not explicitly count (i) or (iv).
   ready tasks (category (ii)) are further
   classified by the event that made them
   ready.

   create : a task created a task and the
   node is the first node the create task
   create_cont : a task created a task and the
   node is the first in the parent task after 
   create_task
   end : a task issued a wait_task at one
   point, when one of the waited children
   has not yet finished. later the last
   child finished and the task is now ready.
   the node is the first node after wait_tasks
   wait_cont : a task issued a wait_task,
   when all waited children have finished.
   the node is the first node after wait_tasks
 */
typedef enum {
  dr_node_state_running,
  dr_node_state_end,
  dr_node_state_create,
  dr_node_state_create_cont,
  dr_node_state_wait_cont,
  dr_node_state_end_cont,
  dr_node_state_max,
} dr_node_state_t;

/* an entry in the parallelism profile. */
typedef struct {
  dr_clock_t t;			/* time */
  int a[dr_node_state_max];	/* count of nodes in each state */
} dr_para_prof_history_entry;

typedef struct {
  /* this must be the first element */
  void (*process_event)(chronological_traverser * ct, dr_event evt);
  int counts[dr_node_state_max];
  dr_clock_t last_time;
  dr_para_prof_history_entry * history;
  long hist_sz;
  long n_hists;
} dr_para_prof;

static void 
dr_para_prof_process_event(chronological_traverser * pp, dr_event evt);

static void 
dr_para_prof_init(dr_para_prof * pp, long hist_sz, dr_clock_t last_time) {
  int i;
  for (i = 0; i < dr_node_state_max; i++) {
    pp->counts[i] = 0;
  }
  pp->process_event = dr_para_prof_process_event;
  pp->last_time = last_time;
  pp->hist_sz = hist_sz;
  pp->n_hists = 0;
  pp->history = (dr_para_prof_history_entry *)
    dr_malloc(sizeof(dr_para_prof_history_entry) * hist_sz);
}

static void 
dr_para_prof_add_hist(dr_para_prof * pp, dr_clock_t t) {
  long sz = pp->hist_sz;
  long n = pp->n_hists;
  dr_para_prof_history_entry * hist = pp->history;
  long last_t = (n ? hist[n-1].t : 0);
  // (last_t + (t - last_t) * (sz - n) >= pp->last_time)

  if (t / (double)pp->last_time > n / (double)sz) {
    int i;
    dr_para_prof_history_entry * h = &hist[n];
    assert(n < sz);
    h->t = t;
    for (i = 0; i < dr_node_state_max; i++) {
      h->a[i] = pp->counts[i];
{'fraction_non_alphanumeric': 0.09658356417359187, 'fraction_numerical': 0.00221606648199446, 'mean_word_length': 3.4140179299103504, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 39, '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': '5856805', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1982, 'n_words': 605}