• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const assert = require('assert');
4const v8 = require('v8');
5
6const s = v8.getHeapStatistics();
7const keys = [
8  'does_zap_garbage',
9  'heap_size_limit',
10  'malloced_memory',
11  'number_of_detached_contexts',
12  'number_of_native_contexts',
13  'peak_malloced_memory',
14  'total_available_size',
15  'total_heap_size',
16  'total_heap_size_executable',
17  'total_physical_size',
18  'used_heap_size'];
19assert.deepStrictEqual(Object.keys(s).sort(), keys);
20keys.forEach(function(key) {
21  assert.strictEqual(typeof s[key], 'number');
22});
23
24
25const heapCodeStatistics = v8.getHeapCodeStatistics();
26const heapCodeStatisticsKeys = [
27  'bytecode_and_metadata_size',
28  'code_and_metadata_size',
29  'external_script_source_size'];
30assert.deepStrictEqual(Object.keys(heapCodeStatistics).sort(),
31                       heapCodeStatisticsKeys);
32heapCodeStatisticsKeys.forEach(function(key) {
33  assert.strictEqual(typeof heapCodeStatistics[key], 'number');
34});
35
36
37const expectedHeapSpaces = [
38  'code_large_object_space',
39  'code_space',
40  'large_object_space',
41  'map_space',
42  'new_large_object_space',
43  'new_space',
44  'old_space',
45  'read_only_space',
46];
47const heapSpaceStatistics = v8.getHeapSpaceStatistics();
48const actualHeapSpaceNames = heapSpaceStatistics.map((s) => s.space_name);
49assert.deepStrictEqual(actualHeapSpaceNames.sort(), expectedHeapSpaces.sort());
50heapSpaceStatistics.forEach((heapSpace) => {
51  assert.strictEqual(typeof heapSpace.space_name, 'string');
52  assert.strictEqual(typeof heapSpace.space_size, 'number');
53  assert.strictEqual(typeof heapSpace.space_used_size, 'number');
54  assert.strictEqual(typeof heapSpace.space_available_size, 'number');
55  assert.strictEqual(typeof heapSpace.physical_space_size, 'number');
56});
57