blob: af550028034c1e41ec57c0d0bd97c0f00685969b [file] [log] [blame]
// Copyright 2019 The Chromium Authors. 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:convert';
import 'dart:io';
/// Outputs the time intervals between adjacent cpu samples.
/// A json file path is required as a command line argument.
/// Ex: dart cpu_sample_intervals.dart ~/Downloads/example_json.dart
void main(List<String> arguments) async {
if (arguments.isEmpty) {
print('You must specify a json input file path.\n'
'Ex: dart cpu_sample_intervals.dart ~/Downloads/example.json');
final File file = File(arguments.first);
final Map<String, dynamic> timelineDump =
(jsonDecode(await file.readAsString()) as Map).cast<String, dynamic>();
final List<dynamic> cpuSampleTraceEvents =
timelineDump['cpuProfile']['traceEvents'] as List;
final List<int> deltas = [];
for (int i = 0; i < cpuSampleTraceEvents.length - 1; i++) {
final Map<String, dynamic> current =
(cpuSampleTraceEvents[i] as Map).cast<String, dynamic>();
final Map<String, dynamic> next =
(cpuSampleTraceEvents[i + 1] as Map).cast<String, dynamic>();
deltas.add((next['ts'] as int) - (current['ts'] as int));