• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:io';
6import 'dart:convert';
7
8bool includeFunction(String function) {
9  return function.startsWith("dart:") ||
10         function.startsWith("package:flutter/") ||
11         function.startsWith("package:vector_math/");
12}
13
14main(List<String> args) async {
15  if (args.length != 1) {
16    print("Usage:\n"
17          " fx syslog | dart topaz/runtime/flutter_runner/collect_traces.dart output.txt");
18    exitCode = 1;
19    return;
20  }
21
22  var functionCounts = Map<String, int>();
23
24  ProcessSignal.sigint.watch().listen((_) {
25    var functions = List<String>();
26    // TODO(flutter): Investigate consensus functions to avoid bloat.
27    var minimumCount = 1;
28    functionCounts.forEach((String function, int count) {
29      if (count >= minimumCount) {
30        functions.add(function);
31      }
32    });
33
34    functions.sort();
35
36    var sb = StringBuffer();
37    for (var function in functions) {
38      sb.writeln(function);
39    }
40
41    File(args[0]).writeAsString(sb.toString(), flush: true).then((_) { exit(0); });
42  });
43
44  final stdinAsLines = LineSplitter().bind(Utf8Decoder().bind(stdin));
45  await for (final line in stdinAsLines) {
46    final marker = "compilation-trace: ";
47    final markerPosition = line.indexOf(marker);
48    if (markerPosition == -1) {
49      continue;
50    }
51
52    final function = line.substring(markerPosition + marker.length);
53    if (!includeFunction(function)) {
54      continue;
55    }
56    print(function);
57
58    var count = functionCounts[function];
59    if (count == null) {
60      count = 1;
61    } else {
62      count++;
63    }
64    functionCounts[function] = count;
65  }
66}
67