Returns the number of processors on this machine.
540283
def cpu_count() -> int:
    """"""
    if multiprocessing is None:
        return 1
    try:
        return multiprocessing.cpu_count()
    except NotImplementedError:
        pass
    try:
        return os.sysconf("SC_NPROCESSORS_CONF")
    except (AttributeError, ValueError):
        pass
    gen_log.error("Could not detect number of processors; assuming 1")
    return 1
1326462
def set_cpu_affinity(n, process_ids, actual=not Conf.TESTING):
    
    # check if we have the psutil module
    if not psutil:
        logger.warning('Skipping cpu affinity because psutil was not found.')
        return
    # check if the platform supports cpu_affinity
    if actual and not hasattr(psutil.Process(process_ids[0]), 'cpu_affinity'):
        logger.warning('Faking cpu affinity because it is not supported on this platform')
        actual = False
    # get the available processors
    cpu_list = list(range(psutil.cpu_count()))
    # affinities of 0 or gte cpu_count, equals to no affinity
    if not n or n >= len(cpu_list):
        return
    # spread the workers over the available processors.
    index = 0
    for pid in process_ids:
        affinity = []
        for k in range(n):
            if index == len(cpu_list):
                index = 0
            affinity.append(cpu_list[index])
            index += 1
        if psutil.pid_exists(pid):
            p = psutil.Process(pid)
            if actual:
                p.cpu_affinity(affinity)
            logger.info(_('{} will use cpu {}').format(pid, affinity))
1280728
def detect_number_of_threads():
    
    log.warning('Deprecated, use `init_num_threads` instead.')
    try:
        nthreads = int(os.environ.get('NUMEXPR_NUM_THREADS', ''))
    except ValueError:
        try:
            nthreads = int(os.environ.get('OMP_NUM_THREADS', ''))
        except ValueError:
            nthreads = detect_number_of_cores()

    # Check that we don't surpass the MAX_THREADS in interpreter.cpp
    if nthreads > MAX_THREADS:
        nthreads = MAX_THREADS
    return nthreads
1123075
public java.util.List<ProcessorFeature> getProcessorFeatures() {
        if (processorFeatures == null) {
            processorFeatures = new com.amazonaws.internal.SdkInternalList<ProcessorFeature>();
        }
        return processorFeatures;
    }
924563
public int getThreadNumber() {
        if (cli.hasOption(THREAD_NUMBER)) {
            return Integer.valueOf(cli.getOptionValue(THREAD_NUMBER));
        }

        return DEFAULT_THREAD_NUMBER;
    }
902416
public Set<? extends Processor<?, ?>> getAllProcessors() {
        IdentityHashMap<Processor<?, ?>, Void> all = new IdentityHashMap<>();
        all.put(this.getProcessor(), null);
        for (ProcessorGraphNode<?, ?> dependency: this.dependencies) {
            for (Processor<?, ?> p: dependency.getAllProcessors()) {
                all.put(p, null);
            }
        }
        return all.keySet();
    }
984210
def get_machine_usage(machine, start, end):
    

    try:
        cache = MachineCache.objects.get(
            machine=machine, date=datetime.date.today(),
            start=start, end=end)
        return cache.cpu_time, cache.no_jobs
    except MachineCache.DoesNotExist:
        return 0, 0
362646
public int getNumberOfInputExecutionVertices() {

		int retVal = 0;

		final Iterator<ExecutionGroupVertex> it = this.stageMembers.iterator();
		while (it.hasNext()) {

			final ExecutionGroupVertex groupVertex = it.next();
			if (groupVertex.isInputVertex()) {
				retVal += groupVertex.getCurrentNumberOfGroupMembers();
			}
		}

		return retVal;
	}
338028
def machine_info():
    
    import psutil
    BYTES_IN_GIG = 1073741824.0
    free_bytes = psutil.virtual_memory().total
    return [{"memory": float("%.1f" % (free_bytes / BYTES_IN_GIG)), "cores": multiprocessing.cpu_count(),
             "name": socket.gethostname()}]
366402
public float getCpuUsagePercent() {
		if (nanoBefore == null || cpuBefore == null) {
			throw new IllegalStateException("nanoBefore or cpuBefore where null: nanoBefore: " + nanoBefore + ", " +
					" cpuBefore: " + cpuBefore);
		}
		long cpuAfter = processCpuTime.getProcessCpuTime();
		long nanoAfter = System.nanoTime();

		float utilisation = ((float)(cpuAfter - cpuBefore)) / (nanoAfter - nanoBefore);
		return utilisation / Runtime.getRuntime().availableProcessors();
	}
187874
private function _get_Win32_Processor()
    {
        if ($this->_Win32_Processor === null) $this->_Win32_Processor = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('LoadPercentage', 'AddressWidth', 'Name', 'L2CacheSize', 'L3CacheSize', 'CurrentClockSpeed', 'ExtClock', 'NumberOfCores', 'NumberOfLogicalProcessors', 'MaxClockSpeed'));
        return $this->_Win32_Processor;
    }
696550
@Override
    public int getNumberOfDevices() {
        if (numberOfDevices.get() < 0) {
            synchronized (this) {
                if (numberOfDevices.get() < 1) {
                    numberOfDevices.set(NativeOpsHolder.getInstance().getDeviceNativeOps().getAvailableDevices());
                }
            }
        }

        return numberOfDevices.get();
    }
915352
public static int getCpuCores() {
        // 找不到文件或者异常，则去物理机的核心数
        int cpu = RpcConfigs.getIntValue(RpcOptions.SYSTEM_CPU_CORES);
        return cpu > 0 ? cpu : Runtime.getRuntime().availableProcessors();
    }
1080163
public int count() {
        int n = 0;
        for (ConcurrentMap<?, ?> bag : registry.values()) {
            n += bag.size();
        }
        return n;
    }
214855
def get_processor(self,
                      name,
                      mappings=None,
                      processor_type=None,
                      **kwargs):
        
        try:
            return self.processors[name]
        except KeyError:
            return  self.make_processor(name,
                                        mappings,
                                        processor_type,
                                        **kwargs)
171689
public function cpu_usage()
    {
        if ($this->host_os === 'WINDOWS') {
            $wmi = new \COM("winmgmts:\\\\.\\root\\cimv2");
            $cpus = $wmi->ExecQuery("SELECT LoadPercentage FROM Win32_Processor");

            foreach ($cpus as $cpu) {
                $return = $cpu->LoadPercentage;
            }
        } else {
            $return = shell_exec('top -d 0.5 -b -n2 | grep "Cpu(s)"|tail -n 1 | awk \'{print $2 + $4}\'');
        }
        return trim($return);
    }
600815
@Exported
    public int getTotalExecutors() {
        int r=0;
        for (Computer c : get_all()) {
            if(c.isOnline())
                r += c.countExecutors();
        }
        return r;
    }