blob: 50ec2a4d5912353f7dbf73cea012e75332853b44 [file] [log] [blame]
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io' as io;
import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:vm/bytecode/ngrams.dart';
final ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
help: 'Only allow control flow as the last instruction in a window',
defaultsTo: true)
abbr: 'o', help: 'Path to output file', defaultsTo: null)
help: 'Do not distinguish among different kinds of Push opcodes',
defaultsTo: false)
abbr: 's', help: 'Sort the output by ngram frequency', defaultsTo: true)
abbr: 't', help: 'Minimum ngram count threshold', defaultsTo: "1")
..addOption('window', abbr: 'w', help: 'Window size', defaultsTo: "3");
final String _usage = '''
Usage: dump_bytecode_ngrams [options] input.trace
Dumps stats about a dynamic bytecode instruction trace produced with the
Dart VM option --interpreter-trace-file, e.g.:
\$ dart --enable-interpreter --interpreter-trace-file=trace program.dart
const int _badUsageExitCode = 1;
void main(List<String> arguments) {
final ArgResults options = _argParser.parse(arguments);
if (( != 1) || (options['output'] == null)) {
final basicBlocks = options['basic-blocks'];
final input =;
final output = options['output'];
final mergePushes = options['merge-pushes'];
final windowSize = int.parse(options['window']);
final sort = options['sort'];
final threshold = int.parse(options['threshold']);
if (!(new io.File(input).existsSync())) {
print("The file '$input' does not exist");
NGramReader nGramReader = new NGramReader(input);
basicBlocks: basicBlocks, mergePushes: mergePushes);
nGramReader.writeNGramStats(output, sort: sort, minCount: threshold);