<commit_before>/**
 * This file defines the `d2::core::framework` class.
 */

#ifndef D2_CORE_FRAMEWORK_HPP
#define D2_CORE_FRAMEWORK_HPP

#include <d2/core/events.hpp>
#include <d2/core/filesystem_dispatcher.hpp>
#include <d2/core/lock_id.hpp>
#include <d2/core/segment.hpp>
#include <d2/core/thread_id.hpp>
#include <d2/detail/atomic.hpp>
#include <d2/detail/mutex.hpp>

#include <boost/assert.hpp>
#include <boost/move/utility.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/unordered_map.hpp>
#include <cstddef>


namespace d2 {
namespace core {
struct framework {
    framework()
        : event_logging_enabled_(false)
    { }

    void enable() { event_logging_enabled_ = true; }
    void disable() { event_logging_enabled_ = false; }

    bool is_enabled() const { return event_logging_enabled_; }
    bool is_disabled() const { return !is_enabled(); }

    template <typename Path>
    int set_repository(BOOST_FWD_REF(Path) path) {
        // Note: 0 for success and anything else but 0 for failure.
        return dispatcher_.set_repository_noexcept(boost::forward<Path>(path))
                                                                    ? 0 : 1;
    }

    void unset_repository() {
        dispatcher_.unset_repository();
    }

    void notify_acquire(std::size_t thread_id, std::size_t lock_id) {
        if (is_enabled()) {
            events::acquire event((ThreadId(thread_id)), LockId(lock_id));
                            // ignore current frame
            event.info.init_call_stack(1);
            dispatcher_.dispatch(event);<commit_msg>Use D2_REPOSITORY envvar to set initial repo.<commit_after>/**
 * This file defines the `d2::core::framework` class.
 */

#ifndef D2_CORE_FRAMEWORK_HPP
#define D2_CORE_FRAMEWORK_HPP

#include <d2/core/events.hpp>
#include <d2/core/filesystem_dispatcher.hpp>
#include <d2/core/lock_id.hpp>
#include <d2/core/segment.hpp>
#include <d2/core/thread_id.hpp>
#include <d2/detail/atomic.hpp>
#include <d2/detail/mutex.hpp>

#include <boost/assert.hpp>
#include <boost/move/utility.hpp>
#include <boost/thread/lock_guard.hpp>
#include <boost/unordered_map.hpp>
#include <cstddef>
#include <cstdlib>


namespace d2 {
namespace core {
struct framework {
    framework() : event_logging_enabled_(false) {
        char const* repo = std::getenv("D2_REPOSITORY");
        if (repo) {
            enable();
            set_repository(repo);
        }
    }

    ~framework() {
        if (is_enabled()) {
            disable();
            unset_repository();
        }
    }

    void enable() { event_logging_enabled_ = true; }
    void disable() { event_logging_enabled_ = false; }

    bool is_enabled() const { return event_logging_enabled_; }
    bool is_disabled() const { return !is_enabled(); }

    template <typename Path>
    int set_repository(BOOST_FWD_REF(Path) path) {
        // Note: 0 for success and anything else but 0 for failure.
        return dispatcher_.set_repository_noexcept(boost::forward<Path>(path))
                                                                    ? 0 : 1;
    }

    void unset_repository() {
        dispatcher_.unset_repository();
    }

    void notify_acquire(std::size_t thread_id, std::size_t lock_id) {
        if (is_enabled()) {
            events::acquire event((ThreadId(thread_id)), LockId(lock_id));
                            // ignore current frame
            event.info.init_call_stack(1);
            dispatcher_.dispatch(event);
{'fraction_non_alphanumeric': 0.11991928509656961, 'fraction_numerical': 0.009801095416546555, 'mean_word_length': 2.7513513513513512, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4985158', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1074, 'n_words': 220}