forked from flutter/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu_sample_intervals.dart
More file actions
34 lines (30 loc) · 1.25 KB
/
cpu_sample_intervals.dart
File metadata and controls
34 lines (30 loc) · 1.25 KB
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
// 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');
return;
}
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));
}
print(deltas);
}