<commit_before>/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2011-2012 Couchbase, Inc.
 *
 *   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 "config.h"
#include "settings.h"
#include <libcouchbase/couchbase.h>

#ifndef HAVE_GETHRTIME

#include <stdlib.h>
#include <time.h>
#if defined(__MACH__) && defined(__APPLE__)
#include <mach/mach_time.h>
#endif

#ifdef __linux__
#undef HAVE_CLOCK_GETTIME
#define HAVE_CLOCK_GETTIME 1
#endif

#define CLOCK_START_OFFSET (LCB_S2NS(3600 * 24))

hrtime_t gethrtime(void)
{
#ifdef __APPLE__

    /* Most things expect a pretty large timestamp - even though a smaller one
     * may be perfectly valid. Initialize the default with an offset of one day,
     * in nanoseconds
     */

    /* Use the various mach stuff:
     * https://developer.apple.com/library/mac/qa/qa1398/_index.html */

    static uint64_t start = CLOCK_START_OFFSET;
    uint64_t now ;
    static mach_timebase_info_data_t tmbi;

    if (start == 0) {
        start = mach_absolute_time();
        mach_timebase_info(&tmbi);
    }

    now = mach_absolute_time();
    return ((now - start) * tmbi.numer / tmbi.denom) + CLOCK_START_OFFSET;

#elif defined(HAVE_CLOCK_GETTIME)
    struct timespec tm;
    lcb_assert(clock_gettime(CLOCK_MONOTONIC, &tm) != -1);
    return (((hrtime_t)tm.tv_sec) * 1000000000) + (hrtime_t)tm.tv_nsec;
#elif defined(HAVE_GETTIMEOFDAY)

    hrtime_t ret;
    struct timeval tv;
    if (gettimeofday(&tv, NULL) == -1) {
        return -1;
    }
<commit_msg>JSCBC-176: Upgrade libcouchbase to include Mac FPE fix.<commit_after>/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2011-2012 Couchbase, Inc.
 *
 *   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 "config.h"
#include "settings.h"
#include <libcouchbase/couchbase.h>

#ifndef HAVE_GETHRTIME

#include <stdlib.h>
#include <time.h>
#if defined(__MACH__) && defined(__APPLE__)
#include <mach/mach_time.h>
#endif

#ifdef __linux__
#undef HAVE_CLOCK_GETTIME
#define HAVE_CLOCK_GETTIME 1
#endif

#define CLOCK_START_OFFSET (LCB_S2NS(3600 * 24))

hrtime_t gethrtime(void)
{
#ifdef __APPLE__

    /* Most things expect a pretty large timestamp - even though a smaller one
     * may be perfectly valid. Initialize the default with an offset of one day,
     * in nanoseconds
     */

    /* Use the various mach stuff:
     * https://developer.apple.com/library/mac/qa/qa1398/_index.html */

    static uint64_t start = 0;
    uint64_t now ;
    static mach_timebase_info_data_t tmbi;

    if (start == 0) {
        start = mach_absolute_time();
        mach_timebase_info(&tmbi);
    }

    now = mach_absolute_time();
    return ((now - start) * tmbi.numer / tmbi.denom) + CLOCK_START_OFFSET;

#elif defined(HAVE_CLOCK_GETTIME)
    struct timespec tm;
    lcb_assert(clock_gettime(CLOCK_MONOTONIC, &tm) != -1);
    return (((hrtime_t)tm.tv_sec) * 1000000000) + (hrtime_t)tm.tv_nsec;
#elif defined(HAVE_GETTIMEOFDAY)

    hrtime_t ret;
    struct timeval tv;
    if (gettimeofday(&tv, NULL) == -1) {
        return -1;
    }

{'fraction_non_alphanumeric': 0.10691222195646974, 'fraction_numerical': 0.022004305190145897, 'mean_word_length': 3.3744769874476988, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '2192786', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1397, 'n_words': 419}