getCPU.

@return array of cpu info
330424
public function getCPU()
    {

        // Time?
        if (!empty($this->settings['timer'])) {
            $t = new Timer('CPUs');
        }

        // File that has it
        $file = '/proc/cpuinfo';

        // Not there?
        if (!is_file($file) || !is_readable($file)) {
            Errors::add('Linfo Core', '/proc/cpuinfo not readable');

            return [];
        }

        /*
         * Get all info for all CPUs from the cpuinfo file
         */

        // Get contents
        $contents = Common::getContents($file);

        // Lines
        $lines = explode("\n", $contents);

        // Store CPUs here
        $cpus = [];

        // Holder for current CPU info
        $cur_cpu = [];

        // Go through lines in file
        $num_lines = count($lines);

        // We use the key of the first line to separate CPUs
        $first_line = substr($lines[0], 0, strpos($lines[0], ' '));

        for ($i = 0; $i < $num_lines; ++$i) {

            // Approaching new CPU? Save current and start new info for this
            if (strpos($lines[$i], $first_line) === 0 && count($cur_cpu) > 0) {
                $cpus[] = $cur_cpu;
                $cur_cpu = [];

                // Default to unknown
                $cur_cpu['Model'] = 'Unknown';
            }

            // Info here
            $line = explode(':', $lines[$i], 2);

            if (!array_key_exists(1, $line)) {
                continue;
            }

            $key = trim($line[0]);
            $value = trim($line[1]);

            // What we want are MHZ, Vendor, and Model.
            switch ($key) {

                // CPU model
                case 'model name':
                case 'cpu':
                case 'Processor':
                    $cur_cpu['Model'] = $value;
                break;

                // Speed in MHz
                case 'cpu MHz':
                    $cur_cpu['MHz'] = $value;
                break;

                case 'Cpu0ClkTck': // Old sun boxes
                    $cur_cpu['MHz'] = hexdec($value) / 1000000;
                break;

                // Brand/vendor
                case 'vendor_id':
                    $cur_cpu['Vendor'] = $value;
                break;

                // ID. Corresponds to percentage if enabled below
                case 'processor':
                    if (isset($this->cpu_percent['cpus'][$value])) {
                        $cur_cpu['usage_percentage'] = $this->cpu_percent['cpus'][$value];
                    }
                break;
            }
        }

        // Save remaining one
        if (count($cur_cpu) > 0) {
            $cpus[] = $cur_cpu;
        }

        // Return them
        return $cpus;
    }
1301511
def _actual_get_cpu_info_from_cpuid(queue):
	'''
	
	'''

	# Pipe all output to nothing
	sys.stdout = open(os.devnull, 'w')
	sys.stderr = open(os.devnull, 'w')

	# Get the CPU arch and bits
	arch, bits = _parse_arch(DataSource.arch_string_raw)

	# Return none if this is not an X86 CPU
	if not arch in ['X86_32', 'X86_64']:
		queue.put(_obj_to_b64({}))
		return

	# Return none if SE Linux is in enforcing mode
	cpuid = CPUID()
	if cpuid.is_selinux_enforcing:
		queue.put(_obj_to_b64({}))
		return

	# Get the cpu info from the CPUID register
	max_extension_support = cpuid.get_max_extension_support()
	cache_info = cpuid.get_cache(max_extension_support)
	info = cpuid.get_info()

	processor_brand = cpuid.get_processor_brand(max_extension_support)

	# Get the Hz and scale
	hz_actual = cpuid.get_raw_hz()
	hz_actual = _to_decimal_string(hz_actual)

	# Get the Hz and scale
	hz_advertised, scale = _parse_cpu_brand_string(processor_brand)
	info = {
	'vendor_id_raw' : cpuid.get_vendor_id(),
	'hardware_raw' : '',
	'brand_raw' : processor_brand,

	'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale),
	'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, 0),
	'hz_advertised' : _hz_short_to_full(hz_advertised, scale),
	'hz_actual' : _hz_short_to_full(hz_actual, 0),

	'l2_cache_size' : _to_friendly_bytes(cache_info['size_kb']),
	'l2_cache_line_size' : cache_info['line_size_b'],
	'l2_cache_associativity' : hex(cache_info['associativity']),

	'stepping' : info['stepping'],
	'model' : info['model'],
	'family' : info['family'],
	'processor_type' : info['processor_type'],
	'extended_model' : info['extended_model'],
	'extended_family' : info['extended_family'],
	'flags' : cpuid.get_flags(max_extension_support)
	}

	info = {k: v for k, v in info.items() if v}
	queue.put(_obj_to_b64(info))
1121007
public function getCpuData($snmpConnection) {
        
        $return = Array();
        $return['oneMinute'] = $snmpConnection->useLinux_Cpu()->loadOneMinute();
        $return['fiveMinute'] = $snmpConnection->useLinux_Cpu()->loadFiveMinutes();
        $return['fifteenMinute'] = $snmpConnection->useLinux_Cpu()->loadFifteenMinutes();
        $return['loadPercentage'] = 0;
        return $return;
    }
659951
public function getVersion()
    {
        $cpuinfo = preg_split("/\n/", file_get_contents('/proc/cpuinfo'));
        foreach ($cpuinfo as $line) {
            if (preg_match('/Revision\s*:\s*([^\s]*)\s*/', $line, $matches)) {
                return hexdec($matches[1]);
            }
        }

        return 0;
    }
620130
public function getPerformance()
    {
        try {
            return [
                'memory' => $this->performanceAnalyzer->getMemory(),
                'storage' => $this->performanceAnalyzer->getStorage(),
                'cpu' => $this->performanceAnalyzer->getCpu(),
            ];
        } catch (Exception $e) {
            $this->issueService->exception($e);
        }
    }
749552
protected function cpu_info()
    {

        $this->cpu_info = array();
        if (!stristr(PHP_OS, 'win')) {
            exec("cat /proc/cpuinfo", $output);
            foreach ($output as $line) {
                $parts = explode(':', $line);

                if (empty($parts[0])) continue;

                $this->cpu_info[trim($parts[0])] = (!empty($parts[1])) ? trim($parts[1]) : null;
            }
        }

        return true;
    }
967899
def _get_cpu_info_from_lscpu():
	'''
	
	'''
	try:
		if not DataSource.has_lscpu():
			return {}

		returncode, output = DataSource.lscpu()
		if returncode != 0:
			return {}

		info = {}

		new_hz = _get_field(False, output, None, None, 'CPU max MHz', 'CPU MHz')
		if new_hz:
			new_hz = _to_decimal_string(new_hz)
			scale = 6
			info['hz_advertised_friendly'] = _hz_short_to_friendly(new_hz, scale)
			info['hz_actual_friendly'] = _hz_short_to_friendly(new_hz, scale)
			info['hz_advertised'] = _hz_short_to_full(new_hz, scale)
			info['hz_actual'] = _hz_short_to_full(new_hz, scale)

		vendor_id = _get_field(False, output, None, None, 'Vendor ID')
		if vendor_id:
			info['vendor_id_raw'] = vendor_id

		brand = _get_field(False, output, None, None, 'Model name')
		if brand:
			info['brand_raw'] = brand

		family = _get_field(False, output, None, None, 'CPU family')
		if family and family.isdigit():
			info['family'] = int(family)

		stepping = _get_field(False, output, None, None, 'Stepping')
		if stepping and stepping.isdigit():
			info['stepping'] = int(stepping)

		model = _get_field(False, output, None, None, 'Model')
		if model and model.isdigit():
			info['model'] = int(model)

		l1_data_cache_size = _get_field(False, output, None, None, 'L1d cache')
		if l1_data_cache_size:
			info['l1_data_cache_size'] = _to_friendly_bytes(l1_data_cache_size)

		l1_instruction_cache_size = _get_field(False, output, None, None, 'L1i cache')
		if l1_instruction_cache_size:
			info['l1_instruction_cache_size'] = _to_friendly_bytes(l1_instruction_cache_size)

		l2_cache_size = _get_field(False, output, None, None, 'L2 cache')
		if l2_cache_size:
			info['l2_cache_size'] = _to_friendly_bytes(l2_cache_size)

		l3_cache_size = _get_field(False, output, None, None, 'L3 cache')
		if l3_cache_size:
			info['l3_cache_size'] = _to_friendly_bytes(l3_cache_size)

		# Flags
		flags = _get_field(False, output, None, None, 'flags', 'Features')
		if flags:
			flags = flags.split()
			flags.sort()
			info['flags'] = flags

		info = {k: v for k, v in info.items() if v}
		return info
	except:
		#raise # NOTE: To have this throw on error, uncomment this line
		return {}
977619
def _freecpu(conn):
    '''
    
    '''
    cpus = conn.getInfo()[2]
    for dom in _get_domain(conn, iterable=True):
        if dom.ID() > 0:
            cpus -= dom.info()[3]
    return cpus
649760
public static function getUnits() {
        return [
            self::FILE_SIZE_UNIT_B,
            self::FILE_SIZE_UNIT_KB,
            self::FILE_SIZE_UNIT_MB,
            self::FILE_SIZE_UNIT_GB,
            self::FILE_SIZE_UNIT_TB,
            self::FILE_SIZE_UNIT_PB,
            self::FILE_SIZE_UNIT_EB,
            self::FILE_SIZE_UNIT_ZB,
            self::FILE_SIZE_UNIT_YB,
        ];
    }
83062
public function getSystemInfo()
    {
        $info = ezcSystemInfo::getInstance();
        $accelerator = false;
        if ($info->phpAccelerator) {
            $accelerator = [
                'name' => $info->phpAccelerator->name,
                'url' => $info->phpAccelerator->url,
                'enabled' => $info->phpAccelerator->isEnabled,
                'versionString' => $info->phpAccelerator->versionString,
            ];
        }

        return [
            'cpuType' => $info->cpuType,
            'cpuSpeed' => $info->cpuSpeed,
            'cpuCount' => $info->cpuCount,
            'memorySize' => $info->memorySize,
            'phpVersion' => PHP_VERSION,
            'phpAccelerator' => $accelerator,
            'database' => [
                'type' => $this->connection->getDatabasePlatform()->getName(),
                'name' => $this->connection->getDatabase(),
                'host' => $this->connection->getHost(),
                'username' => $this->connection->getUsername(),
            ],
        ];
    }
1330179
def __get_percpu(self):
        """"""
        # Never update more than 1 time per cached_time
        if self.timer_percpu.finished():
            self.percpu_percent = []
            for cpu_number, cputimes in enumerate(psutil.cpu_times_percent(interval=0.0, percpu=True)):
                cpu = {'key': self.get_key(),
                       'cpu_number': cpu_number,
                       'total': round(100 - cputimes.idle, 1),
                       'user': cputimes.user,
                       'system': cputimes.system,
                       'idle': cputimes.idle}
                # The following stats are for API purposes only
                if hasattr(cputimes, 'nice'):
                    cpu['nice'] = cputimes.nice
                if hasattr(cputimes, 'iowait'):
                    cpu['iowait'] = cputimes.iowait
                if hasattr(cputimes, 'irq'):
                    cpu['irq'] = cputimes.irq
                if hasattr(cputimes, 'softirq'):
                    cpu['softirq'] = cputimes.softirq
                if hasattr(cputimes, 'steal'):
                    cpu['steal'] = cputimes.steal
                if hasattr(cputimes, 'guest'):
                    cpu['guest'] = cputimes.guest
                if hasattr(cputimes, 'guest_nice'):
                    cpu['guest_nice'] = cputimes.guest_nice
                # Append new CPU to the list
                self.percpu_percent.append(cpu)
                # Reset timer for cache
                self.timer_percpu = Timer(self.cached_time)
        return self.percpu_percent
50156
public static systemcpu_stats[] get(nitro_service service) throws Exception{
		systemcpu_stats obj = new systemcpu_stats();
		systemcpu_stats[] response = (systemcpu_stats[])obj.stat_resources(service);
		return response;
	}
137830
def getCPUuse(self):
        
        hz = os.sysconf('SC_CLK_TCK')
        info_dict = {}
        try:
            fp = open(cpustatFile, 'r')
            line = fp.readline()
            fp.close()
        except:
            raise IOError('Failed reading stats from file: %s' % cpustatFile)
        headers = ['user', 'nice', 'system', 'idle', 'iowait', 'irq', 'softirq', 'steal', 'guest']
        arr = line.split()
        if len(arr) > 1 and arr[0] == 'cpu':
            return dict(zip(headers[0:len(arr)], [(float(t) / hz) for t in arr[1:]]))
        return info_dict
1138921
public function getAsPair()
    {
        $result = array();

        foreach ($this->data as $key => $options) {
            $result[$key] = $options[self::CACHE_PARAM_VALUE];
        }

        return $result;
    }
1300770
public function getProcessorAttributes()
    {
        if (-1 === $this->index || !$this->valid()) {
            return null;
        }

        return $this->processors[$this->index][1];
    }
190165
public function getServerInfo()
    {
        // init empty variables (can be filled if exec is allowed)
        $iMemTotal = $iMemFree = $sCpuModelName = $sCpuModel = $sCpuFreq = $iCpuCores = null;

        // fill, if exec is allowed
        if ($this->isExecAllowed()) {
            $iCpuAmnt = $this->_getCpuAmount();
            $iCpuMhz = $this->_getCpuMhz();
            $iBogo = $this->_getBogoMips();
            $iMemTotal = $this->_getMemoryTotal();
            $iMemFree = $this->_getMemoryFree();
            $sCpuModelName = $this->_getCpuModel();
            $sCpuModel = $iCpuAmnt . 'x ' . $sCpuModelName;
            $sCpuFreq = $iCpuMhz . ' MHz';

            // prevent "division by zero" error
            if ($iBogo && $iCpuMhz) {
                $iCpuCores = $iBogo / $iCpuMhz;
            }
        }

        $aServerInfo = [
            'Server OS'     => @php_uname('s'),
            'VM'            => $this->_getVirtualizationSystem(),
            'PHP'           => $this->_getPhpVersion(),
            'MySQL'         => $this->_getMySqlServerInfo(),
            'Apache'        => $this->_getApacheVersion(),
            'Disk total'    => $this->_getDiskTotalSpace(),
            'Disk free'     => $this->_getDiskFreeSpace(),
            'Memory total'  => $iMemTotal,
            'Memory free'   => $iMemFree,
            'CPU Model'     => $sCpuModel,
            'CPU frequency' => $sCpuFreq,
            'CPU cores'     => round($iCpuCores, 0),
        ];

        return $aServerInfo;
    }
1123488
public com.google.appengine.v1.CpuUtilization getCpuUtilization() {
    return cpuUtilization_ == null ? com.google.appengine.v1.CpuUtilization.getDefaultInstance() : cpuUtilization_;
  }