本文整理匯總了TypeScript中v8-profiler.startProfiling函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript startProfiling函數的具體用法?TypeScript startProfiling怎麽用?TypeScript startProfiling使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了startProfiling函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setTimeout
/// <reference path="v8-profiler.d.ts" />
import * as fs from "fs";
import * as profiler from "v8-profiler";
{
var snapshot1 = profiler.takeSnapshot('1');
var snapshot2 = profiler.takeSnapshot();
profiler.deleteAllSnapshots();
}
{
profiler.startProfiling('', true);
setTimeout(function () {
var profile = profiler.stopProfiling('');
profiler.deleteAllProfiles();
}, 1000);
}
{
var snapshot1 = profiler.takeSnapshot();
var snapshot2 = profiler.takeSnapshot();
console.log(snapshot1.getHeader(), snapshot2.getHeader());
console.log(snapshot1.compare(snapshot2));
// Export snapshot to file file
snapshot1.export(function (error, result) {
fs.writeFileSync('snapshot1.json', result);
snapshot1.delete();
});
示例2: while
}
}
}
// Check the parent.
cwd = path.dirname(cwd);
} while (cwd != path.dirname(cwd));
return null;
}
// Check if we need to profile this CLI run.
if (process.env['NG_CLI_PROFILING']) {
const profiler = require('v8-profiler'); // tslint:disable-line:no-implicit-dependencies
profiler.startProfiling();
const exitHandler = (options: { cleanup?: boolean, exit?: boolean }) => {
if (options.cleanup) {
const cpuProfile = profiler.stopProfiling();
fs.writeFileSync(
path.resolve(process.cwd(), process.env.NG_CLI_PROFILING || '') + '.cpuprofile',
JSON.stringify(cpuProfile),
);
}
if (options.exit) {
process.exit();
}
};
process.on('exit', () => exitHandler({ cleanup: true }));
示例3:
import { createWriteStream } from 'fs'
import * as profiler from 'v8-profiler'
import { findAll } from '..'
import { ALL_CONSTRAINTS } from './pentomino/field'
profiler.startProfiling('1', true)
findAll(ALL_CONSTRAINTS)
const profile = profiler.stopProfiling()
profile.export().pipe(createWriteStream('profile.cpuprofile'))