<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <sys/time.h>
#include "Signature.h"
#include "SignalRoutine.h"

#define POSIX_MUTEX

#include "Lock.h"

#define MAX_LOG_LEN 50000
#define MAX_THREAD_NUM 50

static bool start = false;
static pthread_t thread_idx_map[MAX_THREAD_NUM];
static int thread_idx = 1; //start from 1, make 0 be a terminal

static unsigned **GLOG = NULL;
static unsigned *GIDX = NULL;

static int num_shared_vars = 0;

//static struct timeval tpstart, tpend;

int static inline threadid(pthread_t tid) {
    for (int i = 1; i < thread_idx; i++) {
        if (thread_idx_map[i] == tid) {
            return i;
        }
    }

    return -1;
}

void static inline threadcreate(pthread_t tid) {
    thread_idx_map[thread_idx++] = tid;
    
    if (thread_idx > MAX_THREAD_NUM) {
        printf("Too many threads!\n");
        exit(0);
    }
}

void static inline store(int svId, int tid) {
    int currentIdx = GIDX[svId];
    if (currentIdx > 0 && (int) (GLOG[svId][currentIdx - 2]) == tid) {
        GLOG[svId][currentIdx - 1]++;
    } else {
        GLOG[svId][currentIdx] = tid;
        GLOG[svId][currentIdx + 1] = 1;
        GIDX[svId] += 2;
    }
}

extern "C" {

    void OnInit(int svsNum) {
        printf("OnInit-Record\n");
        initializeSigRoutine();

        //start = true;
        num_shared_vars = svsNum + 2; // one for fork, and the other is for synchronizations

        for (int i = 0; i < MAX_THREAD_NUM; i++) {
            thread_idx_map[i] = 0;
        }
<commit_msg>modify leaprecord<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <sys/time.h>
#include "Signature.h"
#include "SignalRoutine.h"

#define POSIX_MUTEX

#include "Lock.h"

#define MAX_LOG_LEN 50000
#define MAX_THREAD_NUM 50

static bool start = false;
static pthread_t thread_idx_map[MAX_THREAD_NUM];
static int thread_idx = 1; //start from 1, make 0 be a terminal

static unsigned **GLOG = NULL;
static unsigned *GIDX = NULL;

static int num_shared_vars = 0;

// set when log is too long
static bool stop_recording = false;

//static struct timeval tpstart, tpend;

int static inline threadid(pthread_t tid) {
    for (int i = 1; i < thread_idx; i++) {
        if (thread_idx_map[i] == tid) {
            return i;
        }
    }

    return -1;
}

void static inline threadcreate(pthread_t tid) {
    thread_idx_map[thread_idx++] = tid;
    
    if (thread_idx > MAX_THREAD_NUM) {
        printf("Too many threads!\n");
        exit(0);
    }
}

void static inline store(int svId, int tid) {
    if(stop_recording){
        return;
    }

    int currentIdx = GIDX[svId];
    if(currentIdx >= MAX_LOG_LEN){
	printf("Log is too long to record! Stop recording!\n");
	stop_recording = true;
	return;
    }

    if (currentIdx > 0 && (int) (GLOG[svId][currentIdx - 2]) == tid) {
        GLOG[svId][currentIdx - 1]++;
    } else {
        GLOG[svId][currentIdx] = tid;
        GLOG[svId][currentIdx + 1] = 1;
        GIDX[svId] += 2;
    }
}

extern "C" {

    void OnInit(int svsNum) {
        printf("OnInit-Record\n");
        initializeSigRoutine();

        //start = true;
        num_shared_vars = svsNum + 2; // one for fork, and the other is for synchronizations

        for (int i = 0; i < MAX_THREAD_NUM; i++) {
            thread_idx_map[i] = 0;
        }

{'fraction_non_alphanumeric': 0.13234455219623503, 'fraction_numerical': 0.013120365088419851, 'mean_word_length': 2.7954545454545454, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, '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': '5993533', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1261, 'n_words': 338}