<commit_before>package cpu

import (
	utils "github.com/DataDog/gohai/windowsutils"
	// "strconv"
	"fmt"
	"regexp"
	"strings"
)

var cpuMap = map[string]string{
	"machdep.cpu.vendor":       "vendor_id",
	"machdep.cpu.brand_string": "model_name",
	"hw.physicalcpu":           "cpu_cores",
	"hw.logicalcpu":            "cpu_logical_processors",
	"hw.cpufrequency":          "mhz",
	"machdep.cpu.family":       "family",
	"machdep.cpu.model":        "model",
	"machdep.cpu.stepping":     "stepping",
}

func getCpuInfo() (cpuInfo map[string]string, err error) {

	cpuInfo = make(map[string]string)

	cpu, err := utils.WindowsWMICommand("CPU",
		"CurrentClockSpeed", "Name", "NumberOfCores",
		"NumberOfLogicalProcessors", "Caption", "Manufacturer")
	if err != nil {
		return
	}
	cpuInfo["mhz"] = cpu["CurrentClockSpeed"]
	cpuInfo["model_name"] = cpu["Name"]
	cpuInfo["cpu_cores"] = cpu["NumberOfCores"]
	cpuInfo["cpu_logical_processors"] = cpu["NumberOfLogicalProcessors"]
	cpuInfo["vendor_id"] = cpu["Manufacturer"]

	caption := fmt.Sprintf(" %s ", cpu["Caption"])
	cpuInfo["family"] = extract(caption, "Family")
	cpuInfo["model"] = extract(caption, "Model")
	cpuInfo["stepping"] = extract(caption, "Stepping")

	return
}

func extract(caption, field string) string {
	re := regexp.MustCompile(fmt.Sprintf("%s [0-9]* ", field))
	return strings.Split(re.FindStringSubmatch(caption)[0], " ")[1]
}<commit_msg>Check number of lines of response.  Using same algorithm as Linux, multiply number of cores and virtual processors (HT) by nummber of responses.<commit_after>package cpu

import (
	"fmt"
	utils "github.com/DataDog/gohai/windowsutils"
	"regexp"
	"strconv"
	"strings"
)

// Values that need to be multiplied by the number of physical processors
var perPhysicalProcValues = []string{
	"cpu_cores",
	"cpu_logical_processors",
}

func getCpuInfo() (cpuInfo map[string]string, err error) {

	cpuInfo = make(map[string]string)

	cpus, err := utils.WindowsWMIMultilineCommand("CPU",
		"CurrentClockSpeed", "Name", "NumberOfCores",
		"NumberOfLogicalProcessors", "Caption", "Manufacturer")
	if err != nil {
		return
	}
	// each line represents a different CPUx
	numberOfPhysicalCpus := len(cpus)
	cpu := cpus[0]

	cpuInfo["mhz"] = cpu["CurrentClockSpeed"]
	cpuInfo["model_name"] = cpu["Name"]
	cpuInfo["cpu_cores"] = cpu["NumberOfCores"]
	cpuInfo["cpu_logical_processors"] = cpu["NumberOfLogicalProcessors"]
	cpuInfo["vendor_id"] = cpu["Manufacturer"]

	caption := fmt.Sprintf(" %s ", cpu["Caption"])
	cpuInfo["family"] = extract(caption, "Family")
	cpuInfo["model"] = extract(caption, "Model")
	cpuInfo["stepping"] = extract(caption, "Stepping")

	// Multiply the values that are "per physical processor" by the number of physical procs
	for _, field := range perPhysicalProcValues {
		if value, ok := cpuInfo[field]; ok {
			intValue, err := strconv.Atoi(value)
			if err != nil {
				continue
			}

			cpuInfo[field] = strconv.Itoa(intValue * numberOfPhysicalCpus)
		}
	}

	return
}

func extract(caption, field string) string {
	re := regexp.MustCompile(fmt.Sprintf("%s [0-9]* ", field))
	return strings.Split(re.FindStringSubmatch(caption)[0], " ")[1]
}
{'fraction_non_alphanumeric': 0.1585791309863622, 'fraction_numerical': 0.0028544243577545195, 'mean_word_length': 5.148148148148148, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '4357096', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1094, 'n_words': 233}