summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/tools/processor.mjs
blob: 93090cf27eaec2c038463358b44e9dad0af0daab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --logfile='+' --log --log-maps --log-ic --log-code
// Flags: --log-function-events --no-stress-opt --no-predictable

import { Processor } from "../../../tools/system-analyzer/processor.mjs";

// log code start
function doWork() {
  let array = [];
  for (let i = 0; i < 500; i++) {
    doWorkStep(i, array);
  }
  let sum = 0;
  for (let i = 0; i < 500; i++) {
    sum += array[i]["property" + i];
  }
  return sum;
}

function doWorkStep(i, array) {
  const obj = {
    ["property" + i]: i,
  };
  array.push(obj);
  obj.custom1 = 1;
  obj.custom2 = 2;
}

const result = doWork();
 // log code end

const logString = d8.log.getAndStop();
const processor = new Processor();
await processor.processChunk(logString);
await processor.finalize();

const maps = processor.mapTimeline;
const ics = processor.icTimeline;
const scripts = processor.scripts;

(function testResults() {
  assertEquals(result, 124750);
  assertTrue(maps.length > 0);
  assertTrue(ics.length > 0);
  assertTrue(scripts.length > 0);
})();

(function testIcKeys() {
  const keys = new Set();
  ics.forEach(ic => keys.add(ic.key));
  assertTrue(keys.has("custom1"));
  assertTrue(keys.has("custom2"));
  assertTrue(keys.has("push"));
})();