ic-processor-driver.mjs 2.25 KB
Newer Older
1 2 3 4
// Copyright 2017 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.

5
import { Processor } from "./system-analyzer/processor.mjs";
6
import { WebInspector } from "./sourcemap.mjs";
7
import { BaseArgumentsProcessor } from "./arguments.mjs";
8

9
function processArguments(args) {
10
  const processor = new ArgumentsProcessor(args);
11 12 13 14 15 16 17
  if (processor.parse()) {
    return processor.result();
  } else {
    processor.printUsageAndExit();
  }
}

18 19 20 21 22 23 24
/**
 * A thin wrapper around shell's 'read' function showing a file name on error.
 */
export function readFile(fileName) {
  try {
    return read(fileName);
  } catch (e) {
25
    console.log(fileName + ': ' + (e.message || e));
26 27 28 29
    throw e;
  }
}

30
function initSourceMapSupport() {
31
  // Pull dev tools source maps into our name space.
32 33 34 35
  SourceMap = WebInspector.SourceMap;

  // Overwrite the load function to load scripts synchronously.
  SourceMap.load = function(sourceMapURL) {
36 37
    const content = readFile(sourceMapURL);
    const sourceMapObject = (JSON.parse(content));
38 39 40 41
    return new SourceMap(sourceMapURL, sourceMapObject);
  };
}

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
class ArgumentsProcessor extends BaseArgumentsProcessor {
  getArgsDispatch() {
    return {
      '--range': ['range', 'auto,auto',
          'Specify the range limit as [start],[end]'],
      '--source-map': ['sourceMap', null,
          'Specify the source map that should be used for output']
    };
  }
  getDefaultResults() {
   return {
      logFileName: 'v8.log',
      range: 'auto,auto',
    };
  }
}

const params = processArguments(arguments);
let sourceMap = null;
61 62 63 64
if (params.sourceMap) {
  initSourceMapSupport();
  sourceMap = SourceMap.load(params.sourceMap);
}
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
const processor = new Processor();
processor.processLogFile(params.logFileName);

const typeAccumulator = new Map();

const accumulator = {
  __proto__: null, 
  LoadGlobalIC: 0,
  StoreGlobalIC: 0,
  LoadIC: 0,
  StoreIC: 0,
  KeyedLoadIC: 0,
  KeyedStoreIC: 0,
  StoreInArrayLiteralIC: 0, 
}
for (const ic of processor.icTimeline.all) {
81
  console.log(Object.values(ic));
82 83 84
  accumulator[ic.type]++;
}

85
console.log("========================================");
86
for (const key of Object.keys(accumulator)) {
87
  console.log(key + ": " + accumulator[key]);
88 89 90
}