<commit_before>/*
 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
 */

#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/mach.h>
#include <mach/task.h>
#endif

#include "sys/times.h"
#include <cstdlib>
#include <base/cpuinfo.h>

#include <fstream>
#include <iostream>

#include <boost/algorithm/string/find.hpp>
#include <boost/algorithm/string/find_iterator.hpp>
#include <boost/algorithm/string/split.hpp>

using namespace boost;

static void LoadAvg(CpuLoad &load) {
    double averages[3];
    getloadavg(averages, 3);
    load.one_min_avg = averages[0];
    load.five_min_avg = averages[1];
    load.fifteen_min_avg = averages[2];
}

static uint32_t NumCpus() {
    static uint32_t count = 0;

    if (count != 0) {
        return count;
    }

#ifdef __APPLE__
    size_t len = sizeof(count);
    sysctlbyname("hw.logicalcpu", &count, &len, NULL, 0);
    return count;
#else
    std::ifstream file("/proc/cpuinfo");
    std::string content((std::istreambuf_iterator<char>(file)),
                   std::istreambuf_iterator<char>());
    // Create a find_iterator
    typedef find_iterator<std::string::iterator> string_find_iterator;

    for(string_find_iterator it = 
        make_find_iterator(content, first_finder("model name", is_iequal()));
        it!=string_find_iterator(); ++it, count++);
    return count;
#endif
}

static void ProcessMemInfo(ProcessMemInfo &info) {
#ifdef __APPLE__
    struct task_basic_info t_info;
    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;<commit_msg>Send load average info per cpu instead of per system. closes-bug:#1344472<commit_after>/*
 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
 */

#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/mach.h>
#include <mach/task.h>
#endif

#include "sys/times.h"
#include <cstdlib>
#include <base/cpuinfo.h>

#include <fstream>
#include <iostream>

#include <boost/algorithm/string/find.hpp>
#include <boost/algorithm/string/find_iterator.hpp>
#include <boost/algorithm/string/split.hpp>

using namespace boost;

static uint32_t NumCpus() {
    static uint32_t count = 0;

    if (count != 0) {
        return count;
    }

#ifdef __APPLE__
    size_t len = sizeof(count);
    sysctlbyname("hw.logicalcpu", &count, &len, NULL, 0);
    return count;
#else
    std::ifstream file("/proc/cpuinfo");
    std::string content((std::istreambuf_iterator<char>(file)),
                   std::istreambuf_iterator<char>());
    // Create a find_iterator
    typedef find_iterator<std::string::iterator> string_find_iterator;

    for(string_find_iterator it = 
        make_find_iterator(content, first_finder("model name", is_iequal()));
        it!=string_find_iterator(); ++it, count++);
    return count;
#endif
}

static void LoadAvg(CpuLoad &load) {
    double averages[3];
    uint32_t num_cpus = NumCpus();
    getloadavg(averages, 3);
    if (num_cpus > 0) {
        load.one_min_avg = averages[0]/num_cpus;
        load.five_min_avg = averages[1]/num_cpus;
        load.fifteen_min_avg = averages[2]/num_cpus;
    }
}

static void ProcessMemInfo(ProcessMemInfo &info) {
#ifdef __APPLE__
    struct task_basic_info t_info;
    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
{'fraction_non_alphanumeric': 0.13146682897139378, 'fraction_numerical': 0.01278149726110773, 'mean_word_length': 4.056923076923077, 'pattern_counts': {'":': 0, '<': 31, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7088019', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1148, 'n_words': 243}