TypeScript v8 writeHeapSnapshot示例

说明

typescript v8 writeheapsnapshot示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: TypeScript

命名空间/包名称: v8

示例#1
文件: v8.ts 项目: ChaosinaCan/DefinitelyTyped

import * as v8 from 'v8';
import { Readable } from 'stream';

const heapStats = v8.getHeapStatistics();
const heapSpaceStats = v8.getHeapSpaceStatistics();

const zapsGarbage: number = heapStats.does_zap_garbage;

v8.setFlagsFromString('--collect_maps');

const stream: Readable = v8.getHeapSnapshot();
const fileName = v8.writeHeapSnapshot('file');

示例#2
文件: heapdump.ts 项目: sogehige/SogeBot

/**
 * Saves a given snapshot
 *
 * @param datadir Location to save to
 */
function saveHeapSnapshot(datadir) {
  const name = datadir + (isMainThread ? 'master' : 'cluster') + '-' + Date.now() + '.heapsnapshot';
  writeHeapSnapshot(name);
  global.log.info('Heap snapshot written to ' + name);
}

展开阅读全文