<commit_before>/*
 * Copyright 2011-2015 Formal Methods and Tools, University of Twente
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <lace.h>
#include <sylvan_config.h>

#ifndef SYLVAN_STATS_H
#define SYLVAN_STATS_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef enum {
    BDD_ITE,
    BDD_AND,
    BDD_XOR,
    BDD_EXISTS,
    BDD_AND_EXISTS,
    BDD_RELNEXT,
    BDD_RELPREV,
    BDD_SATCOUNT,
    BDD_COMPOSE,
    BDD_RESTRICT,
    BDD_CONSTRAIN,
    BDD_CLOSURE,
    BDD_ISBDD,
    BDD_SUPPORT,
    BDD_PATHCOUNT,
    BDD_ITE_CACHEDPUT,
    BDD_AND_CACHEDPUT,
    BDD_XOR_CACHEDPUT,
    BDD_EXISTS_CACHEDPUT,
    BDD_AND_EXISTS_CACHEDPUT,
    BDD_RELNEXT_CACHEDPUT,
    BDD_RELPREV_CACHEDPUT,
    BDD_SATCOUNT_CACHEDPUT,
    BDD_COMPOSE_CACHEDPUT,
    BDD_RESTRICT_CACHEDPUT,
    BDD_CONSTRAIN_CACHEDPUT,
    BDD_CLOSURE_CACHEDPUT,
    BDD_ISBDD_CACHEDPUT,
    BDD_SUPPORT_CACHEDPUT,
    BDD_PATHCOUNT_CACHEDPUT,
    BDD_ITE_CACHED,
    BDD_AND_CACHED,
    BDD_XOR_CACHED,
    BDD_EXISTS_CACHED,
    BDD_AND_EXISTS_CACHED,
    BDD_RELNEXT_CACHED,
    BDD_RELPREV_CACHED,
    BDD_SATCOUNT_CACHED,
    BDD_COMPOSE_CACHED,
    BDD_RESTRICT_CACHED,
    BDD_CONSTRAIN_CACHED,
    BDD_CLOSURE_CACHED,
    BDD_ISBDD_CACHED,
    BDD_SUPPORT_CACHED,
    BDD_PATHCOUNT_CACHED,
    BDD_NODES_CREATED,
    BDD_NODES_REUSED,

    LDD_UNION,
    LDD_MINUS,
    LDD_INTERSECT,
    LDD_RELPROD,
    LDD_RELPREV,
    LDD_PROJECT,
    LDD_JOIN,
    LDD_MATCH,
    LDD_SATCOUNT,
    LDD_SATCOUNTL,
    LDD_ZIP,
    LDD_RELPROD_UNION,
    LDD_PROJECT_MINUS,
    LDD_UNION_CACHEDPUT,
    LDD_MINUS_CACHEDPUT,
    LDD_INTERSECT_CACHEDPUT,
    LDD_RELPROD_CACHEDPUT,
    LDD_RELPREV_CACHEDPUT,
    LDD_PROJECT_CACHEDPUT,
    LDD_JOIN_CACHEDPUT,
    LDD_MATCH_CACHEDPUT,
    LDD_SATCOUNT_CACHEDPUT,
    LDD_SATCOUNTL_CACHEDPUT,
    LDD_ZIP_CACHEDPUT,
    LDD_RELPROD_UNION_CACHEDPUT,
    LDD_PROJECT_MINUS_CACHEDPUT,
    LDD_UNION_CACHED,
    LDD_MINUS_CACHED,
    LDD_INTERSECT_CACHED,
    LDD_RELPROD_CACHED,
    LDD_RELPREV_CACHED,
    LDD_PROJECT_CACHED,
    LDD_JOIN_CACHED,
    LDD_MATCH_CACHED,
    LDD_SATCOUNT_CACHED,
    LDD_SATCOUNTL_CACHED,
    LDD_ZIP_CACHED,
    LDD_RELPROD_UNION_CACHED,
    LDD_PROJECT_MINUS_CACHED,
    LDD_NODES_CREATED,
    LDD_NODES_REUSED,

    SYLVAN_GC_COUNT,
    SYLVAN_COUNTER_COUNTER
} Sylvan_Counters;

typedef enum
{
    SYLVAN_GC,
    SYLVAN_TIMER_COUNTER
} Sylvan_Timers;

#define sylvan_stats_init() CALL(sylvan_stats_init)
VOID_TASK_DECL_0(sylvan_stats_init)

/**
 * Reset all counters (for statistics)
 */
#define sylvan_stats_reset() CALL(sylvan_stats_reset)
VOID_TASK_DECL_0(sylvan_stats_reset)

/**
 * Write statistic report to file (stdout, stderr, etc)
 */
void sylvan_stats_report(FILE* target, int color);

/* Infrastructure for internal markings */
typedef struct
{
    uint64_t counters[SYLVAN_COUNTER_COUNTER];
    uint64_t timers[SYLVAN_TIMER_COUNTER];
    uint64_t timers_startstop[SYLVAN_TIMER_COUNTER];
} sylvan_stats_t;

#if SYLVAN_STATS

#ifdef __MACH__
#include <mach/mach_time.h>
#define getabstime() mach_absolute_time()
#else
#include <time.h>
static uint64_t
getabstime()
{
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    uint64_t t = ts.tv_sec;
    t *= 1000000000UL;
    t += ts.tv_nsec;
}
#endif

#ifdef __ELF__
extern __thread sylvan_stats_t sylvan_stats;
#else
#include <pthread.h>
extern pthread_key_t sylvan_stats_key;
#endif

static inline void
sylvan_stats_count(size_t counter)
{
#ifdef __ELF__
    sylvan_stats.counters[counter]++;
#else
    sylvan_stats_t *sylvan_stats = (sylvan_stats_t*)pthread_getspecific(sylvan_stats_key);
    sylvan_stats->counters[counter]++;
#endif
}

static inline void
sylvan_timer_start(size_t timer)
{
    uint64_t t = getabstime();
<commit_msg>stats: add forgotten return line<commit_after>/*
 * Copyright 2011-2015 Formal Methods and Tools, University of Twente
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <lace.h>
#include <sylvan_config.h>

#ifndef SYLVAN_STATS_H
#define SYLVAN_STATS_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef enum {
    BDD_ITE,
    BDD_AND,
    BDD_XOR,
    BDD_EXISTS,
    BDD_AND_EXISTS,
    BDD_RELNEXT,
    BDD_RELPREV,
    BDD_SATCOUNT,
    BDD_COMPOSE,
    BDD_RESTRICT,
    BDD_CONSTRAIN,
    BDD_CLOSURE,
    BDD_ISBDD,
    BDD_SUPPORT,
    BDD_PATHCOUNT,
    BDD_ITE_CACHEDPUT,
    BDD_AND_CACHEDPUT,
    BDD_XOR_CACHEDPUT,
    BDD_EXISTS_CACHEDPUT,
    BDD_AND_EXISTS_CACHEDPUT,
    BDD_RELNEXT_CACHEDPUT,
    BDD_RELPREV_CACHEDPUT,
    BDD_SATCOUNT_CACHEDPUT,
    BDD_COMPOSE_CACHEDPUT,
    BDD_RESTRICT_CACHEDPUT,
    BDD_CONSTRAIN_CACHEDPUT,
    BDD_CLOSURE_CACHEDPUT,
    BDD_ISBDD_CACHEDPUT,
    BDD_SUPPORT_CACHEDPUT,
    BDD_PATHCOUNT_CACHEDPUT,
    BDD_ITE_CACHED,
    BDD_AND_CACHED,
    BDD_XOR_CACHED,
    BDD_EXISTS_CACHED,
    BDD_AND_EXISTS_CACHED,
    BDD_RELNEXT_CACHED,
    BDD_RELPREV_CACHED,
    BDD_SATCOUNT_CACHED,
    BDD_COMPOSE_CACHED,
    BDD_RESTRICT_CACHED,
    BDD_CONSTRAIN_CACHED,
    BDD_CLOSURE_CACHED,
    BDD_ISBDD_CACHED,
    BDD_SUPPORT_CACHED,
    BDD_PATHCOUNT_CACHED,
    BDD_NODES_CREATED,
    BDD_NODES_REUSED,

    LDD_UNION,
    LDD_MINUS,
    LDD_INTERSECT,
    LDD_RELPROD,
    LDD_RELPREV,
    LDD_PROJECT,
    LDD_JOIN,
    LDD_MATCH,
    LDD_SATCOUNT,
    LDD_SATCOUNTL,
    LDD_ZIP,
    LDD_RELPROD_UNION,
    LDD_PROJECT_MINUS,
    LDD_UNION_CACHEDPUT,
    LDD_MINUS_CACHEDPUT,
    LDD_INTERSECT_CACHEDPUT,
    LDD_RELPROD_CACHEDPUT,
    LDD_RELPREV_CACHEDPUT,
    LDD_PROJECT_CACHEDPUT,
    LDD_JOIN_CACHEDPUT,
    LDD_MATCH_CACHEDPUT,
    LDD_SATCOUNT_CACHEDPUT,
    LDD_SATCOUNTL_CACHEDPUT,
    LDD_ZIP_CACHEDPUT,
    LDD_RELPROD_UNION_CACHEDPUT,
    LDD_PROJECT_MINUS_CACHEDPUT,
    LDD_UNION_CACHED,
    LDD_MINUS_CACHED,
    LDD_INTERSECT_CACHED,
    LDD_RELPROD_CACHED,
    LDD_RELPREV_CACHED,
    LDD_PROJECT_CACHED,
    LDD_JOIN_CACHED,
    LDD_MATCH_CACHED,
    LDD_SATCOUNT_CACHED,
    LDD_SATCOUNTL_CACHED,
    LDD_ZIP_CACHED,
    LDD_RELPROD_UNION_CACHED,
    LDD_PROJECT_MINUS_CACHED,
    LDD_NODES_CREATED,
    LDD_NODES_REUSED,

    SYLVAN_GC_COUNT,
    SYLVAN_COUNTER_COUNTER
} Sylvan_Counters;

typedef enum
{
    SYLVAN_GC,
    SYLVAN_TIMER_COUNTER
} Sylvan_Timers;

#define sylvan_stats_init() CALL(sylvan_stats_init)
VOID_TASK_DECL_0(sylvan_stats_init)

/**
 * Reset all counters (for statistics)
 */
#define sylvan_stats_reset() CALL(sylvan_stats_reset)
VOID_TASK_DECL_0(sylvan_stats_reset)

/**
 * Write statistic report to file (stdout, stderr, etc)
 */
void sylvan_stats_report(FILE* target, int color);

/* Infrastructure for internal markings */
typedef struct
{
    uint64_t counters[SYLVAN_COUNTER_COUNTER];
    uint64_t timers[SYLVAN_TIMER_COUNTER];
    uint64_t timers_startstop[SYLVAN_TIMER_COUNTER];
} sylvan_stats_t;

#if SYLVAN_STATS

#ifdef __MACH__
#include <mach/mach_time.h>
#define getabstime() mach_absolute_time()
#else
#include <time.h>
static uint64_t
getabstime()
{
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    uint64_t t = ts.tv_sec;
    t *= 1000000000UL;
    t += ts.tv_nsec;
    return t;
}
#endif

#ifdef __ELF__
extern __thread sylvan_stats_t sylvan_stats;
#else
#include <pthread.h>
extern pthread_key_t sylvan_stats_key;
#endif

static inline void
sylvan_stats_count(size_t counter)
{
#ifdef __ELF__
    sylvan_stats.counters[counter]++;
#else
    sylvan_stats_t *sylvan_stats = (sylvan_stats_t*)pthread_getspecific(sylvan_stats_key);
    sylvan_stats->counters[counter]++;
#endif
}

static inline void
sylvan_timer_start(size_t timer)
{
    uint64_t t = getabstime();

{'fraction_non_alphanumeric': 0.06871023713128976, 'fraction_numerical': 0.008328513591671487, 'mean_word_length': 4.174147217235189, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2698220', 'n_tokens_mistral': 3751, 'n_tokens_neox': 3722, 'n_words': 610}