當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript os.cpus函數代碼示例

本文整理匯總了TypeScript中os.cpus函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript cpus函數的具體用法?TypeScript cpus怎麽用?TypeScript cpus使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了cpus函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getMaxWorkers

export default function getMaxWorkers(
  argv: Partial<Pick<Config.Argv, 'maxWorkers' | 'runInBand' | 'watch'>>,
): number {
  if (argv.runInBand) {
    return 1;
  } else if (argv.maxWorkers) {
    // TODO: How to type this properly? Should probably use `coerce` from `yargs`
    const maxWorkers = (argv.maxWorkers as unknown) as number | string;
    const parsed = parseInt(maxWorkers as string, 10);

    if (
      typeof maxWorkers === 'string' &&
      maxWorkers.trim().endsWith('%') &&
      parsed > 0 &&
      parsed <= 100
    ) {
      const cpus = os.cpus().length;
      const workers = Math.floor((parsed / 100) * cpus);
      return workers >= 1 ? workers : 1;
    }

    return parsed > 0 ? parsed : 1;
  } else {
    const cpus = os.cpus() ? os.cpus().length : 1;
    return Math.max(argv.watch ? Math.floor(cpus / 2) : cpus - 1, 1);
  }
}
開發者ID:Volune,項目名稱:jest,代碼行數:27,代碼來源:getMaxWorkers.ts

示例2: constructor

  constructor(workerPath: string, options?: FarmOptions) {
    this._options = {...options};
    this._ending = false;

    const workerPoolOptions: WorkerPoolOptions = {
      enableWorkerThreads: this._options.enableWorkerThreads || false,
      forkOptions: this._options.forkOptions || {},
      maxRetries: this._options.maxRetries || 3,
      numWorkers: this._options.numWorkers || Math.max(os.cpus().length - 1, 1),
      setupArgs: this._options.setupArgs || [],
    };

    if (this._options.WorkerPool) {
      // @ts-ignore: constructor target any?
      this._workerPool = new this._options.WorkerPool(
        workerPath,
        workerPoolOptions,
      );
    } else {
      this._workerPool = new WorkerPool(workerPath, workerPoolOptions);
    }

    this._farm = new Farm(
      workerPoolOptions.numWorkers,
      this._workerPool.send.bind(this._workerPool),
      this._options.computeWorkerKey,
    );

    this._bindExposedWorkerMethods(workerPath, this._options);
  }
開發者ID:Volune,項目名稱:jest,代碼行數:30,代碼來源:index.ts

示例3: computeStartupMetrics

	public computeStartupMetrics(): void {
		const now = Date.now();
		const initialStartup = !!this.isInitialStartup;
		const start = initialStartup ? this.start : this.windowLoad;

		let totalmem: number;
		let freemem: number;
		let cpus: { count: number; speed: number; model: string; };
		let platform: string;
		let release: string;
		let loadavg: number[];
		let meminfo: IMemoryInfo;

		try {
			totalmem = os.totalmem();
			freemem = os.freemem();
			platform = os.platform();
			release = os.release();
			loadavg = os.loadavg();
			meminfo = process.getProcessMemoryInfo();

			const rawCpus = os.cpus();
			if (rawCpus && rawCpus.length > 0) {
				cpus = { count: rawCpus.length, speed: rawCpus[0].speed, model: rawCpus[0].model };
			}
		} catch (error) {
			console.error(error); // be on the safe side with these hardware method calls
		}

		this._startupMetrics = {
			version: 1,
			ellapsed: Math.round(this.workbenchStarted.getTime() - start.getTime()),
			timers: {
				ellapsedExtensions: Math.round(this.afterExtensionLoad.getTime() - this.beforeExtensionLoad.getTime()),
				ellapsedExtensionsReady: Math.round(this.afterExtensionLoad.getTime() - start.getTime()),
				ellapsedRequire: Math.round(this.afterLoadWorkbenchMain.getTime() - this.beforeLoadWorkbenchMain.getTime()),
				ellapsedViewletRestore: Math.round(this.restoreViewletDuration),
				ellapsedEditorRestore: Math.round(this.restoreEditorsDuration),
				ellapsedWorkbench: Math.round(this.workbenchStarted.getTime() - this.beforeWorkbenchOpen.getTime()),
				ellapsedWindowLoadToRequire: Math.round(this.beforeLoadWorkbenchMain.getTime() - this.windowLoad.getTime()),
				ellapsedTimersToTimersComputed: Date.now() - now
			},
			platform,
			release,
			totalmem,
			freemem,
			meminfo,
			cpus,
			loadavg,
			initialStartup,
			hasAccessibilitySupport: !!this.hasAccessibilitySupport,
			emptyWorkbench: this.isEmptyWorkbench
		};

		if (initialStartup) {
			this._startupMetrics.timers.ellapsedAppReady = Math.round(this.appReady.getTime() - this.start.getTime());
			this._startupMetrics.timers.ellapsedWindowLoad = Math.round(this.windowLoad.getTime() - this.appReady.getTime());
		}
	}
開發者ID:fs814,項目名稱:vscode,代碼行數:59,代碼來源:timerService.ts

示例4:

 handler: () => ({
   hostname: os.hostname(),
   arch: os.arch(),
   platfoirm: os.platform(),
   cpus: os.cpus().length,
   totalmem: humanize.filesize(os.totalmem()),
   networkInterfaces: os.networkInterfaces()
 })
開發者ID:pdxmholmes,項目名稱:alpine-node-hello,代碼行數:8,代碼來源:index.ts

示例5: execute

 static execute (applicationEntryPoint: EntryPoint): void {
   if (cluster.isMaster) {
     logger.info(`Master process running on ${process.pid}`)
     const numberOfCores = cpus().length
     this.forkListenerProcesses(numberOfCores)
   } else {
     applicationEntryPoint()
   }
 }
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:9,代碼來源:applicationCluster.ts

示例6: init

/**
 * Init app
 */
async function init(): Promise<State> {
	console.log('Welcome to Misskey!\n');

	console.log(chalk.bold('Misskey Core <aoi>'));

	let warn = false;

	// Get commit info
	const commit = await prominence(git).getLastCommit();
	console.log(`commit: ${commit.shortHash} ${commit.author.name} <${commit.author.email}>`);
	console.log(`        ${new Date(parseInt(commit.committedOn, 10) * 1000)}`);

	console.log('\nInitializing...\n');

	if (IS_DEBUG) {
		logWarn('It is not in the Production mode. Do not use in the Production environment.');
	}

	logInfo(`environment: ${env}`);

	// Get machine info
	const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
	const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
	logInfo(`MACHINE: ${os.hostname()}`);
	logInfo(`MACHINE: CPU: ${os.cpus().length}core`);
	logInfo(`MACHINE: MEM: ${totalmem}GB (available: ${freemem}GB)`);

	if (!fs.existsSync(require('./config').configPath)) {
		logFailed('Configuration not found');
		return State.failed;
	}

	// Load config
	const conf = require('./config').default;

	logDone('Success to load configuration');
	logInfo(`maintainer: ${conf.maintainer}`);

	checkDependencies();

	// Check if a port is being used
	if (await portUsed.check(conf.port)) {
		logFailed(`Port: ${conf.port} is already used!`);
		return State.failed;
	}

	// Try to connect to MongoDB
	try {
		await initdb(conf);
		logDone('Success to connect to MongoDB');
	} catch (e) {
		logFailed(`MongoDB: ${e}`);
		return State.failed;
	}

	return warn ? State.warn : State.success;
}
開發者ID:syuilo,項目名稱:misskey-core,代碼行數:60,代碼來源:index.ts

示例7: spawnWorkers

export function spawnWorkers (options: ClusterOptions = {}) {
  // use the number of CPUs as number of workers.
  if (!options.numWorkers) {
    options.numWorkers = os.cpus().length;
  }

  for (var i = 0, len = options.numWorkers; i < len; i++) {
    spawnWorker();
  }
}
開發者ID:truonglvx,項目名稱:colyseus,代碼行數:10,代碼來源:Master.ts

示例8: runners

 return new Promise<TestRunnerMetadata[]>((resolve, reject) => {
   let cpuCount = os.cpus().length;
   let testRunnerMetadatas: TestRunnerMetadata[] = [];
   let allPromises: Promise<any>[] = [];
   console.log(`INFO: Creating ${cpuCount} test runners (based on cpu count)`);
   for (let i = 0; i < cpuCount; i++) {
     allPromises.push(this.createTestRunner(i).then(testRunnerMetadata => testRunnerMetadatas.push(testRunnerMetadata)));
   }
   Promise.all(allPromises).then(() => resolve(testRunnerMetadatas));
 });
開發者ID:Dragnipur,項目名稱:stryker,代碼行數:10,代碼來源:TestRunnerOrchestrator.ts

示例9: show

	public static show(): void {
		const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
		const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
		const logger = new Logger('Machine');
		logger.info(`Hostname: ${os.hostname()}`);
		logger.info(`Platform: ${process.platform}`);
		logger.info(`Architecture: ${process.arch}`);
		logger.info(`CPU: ${os.cpus().length} core`);
		logger.info(`MEM: ${totalmem}GB (available: ${freemem}GB)`);
	}
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:10,代碼來源:machineInfo.ts

示例10: default

export default () => new Promise(async (res, rej) => {
	const meta: any = (await Meta.findOne()) || {};

	res({
		maintainer: config.maintainer,

		version: pkg.version,
		clientVersion: client.version,

		secure: config.https != null,
		machine: os.hostname(),
		os: os.platform(),
		node: process.version,
		cpu: {
			model: os.cpus()[0].model,
			cores: os.cpus().length
		},
		broadcasts: meta.broadcasts
	});
});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:20,代碼來源:meta.ts


注:本文中的os.cpus函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。