<commit_before>// +build darwin,cgo

package cpu

import (
	"fmt"
	"unsafe"
)

// #include <mach/mach_host.h>
// #include <mach/host_info.h>
import "C"

// Get cpu statistics
func Get() (*CPU, error) {
	return collectCPUStats()
}

// CPU represents cpu statistics for darwin
type CPU struct {
	User, System, Idle, Nice, Total uint64
}

func collectCPUStats() (*CPU, error) {
	var cpuLoad C.host_cpu_load_info_data_t
	var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT
	ret := C.host_statistics(C.host_t(C.mach_host_self()), C.HOST_CPU_LOAD_INFO, C.host_info_t(unsafe.Pointer(&cpuLoad)), &count)
	if ret != C.KERN_SUCCESS {
		return nil, fmt.Errorf("%d", ret)
	}
	cpu := CPU{
		User:   uint64(cpuLoad.cpu_ticks[C.CPU_STATE_USER]),
		System: uint64(cpuLoad.cpu_ticks[C.CPU_STATE_SYSTEM]),
		Idle:   uint64(cpuLoad.cpu_ticks[C.CPU_STATE_IDLE]),
		Nice:   uint64(cpuLoad.cpu_ticks[C.CPU_STATE_NICE]),
	}
	cpu.Total = cpu.User + cpu.System + cpu.Idle + cpu.Nice
	return &cpu, nil
}
<commit_msg>improve error message for cpu statistics<commit_after>// +build darwin,cgo

package cpu

import (
	"fmt"
	"unsafe"
)

// #include <mach/mach_host.h>
// #include <mach/host_info.h>
import "C"

// Get cpu statistics
func Get() (*CPU, error) {
	return collectCPUStats()
}

// CPU represents cpu statistics for darwin
type CPU struct {
	User, System, Idle, Nice, Total uint64
}

func collectCPUStats() (*CPU, error) {
	var cpuLoad C.host_cpu_load_info_data_t
	var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT
	ret := C.host_statistics(C.host_t(C.mach_host_self()), C.HOST_CPU_LOAD_INFO, C.host_info_t(unsafe.Pointer(&cpuLoad)), &count)
	if ret != C.KERN_SUCCESS {
		return nil, fmt.Errorf("host_statistics failed: %d", ret)
	}
	cpu := CPU{
		User:   uint64(cpuLoad.cpu_ticks[C.CPU_STATE_USER]),
		System: uint64(cpuLoad.cpu_ticks[C.CPU_STATE_SYSTEM]),
		Idle:   uint64(cpuLoad.cpu_ticks[C.CPU_STATE_IDLE]),
		Nice:   uint64(cpuLoad.cpu_ticks[C.CPU_STATE_NICE]),
	}
	cpu.Total = cpu.User + cpu.System + cpu.Idle + cpu.Nice
	return &cpu, nil
}

{'fraction_non_alphanumeric': 0.14063260340632602, 'fraction_numerical': 0.009732360097323601, 'mean_word_length': 4.743016759776537, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6573102', 'n_tokens_mistral': 855, 'n_tokens_neox': 824, 'n_words': 165}