Unverified Commit d377c1ba authored by Dan Field's avatar Dan Field Committed by GitHub

Always write full timeline before summary (#79310)

parent 6b3093b6
......@@ -50,7 +50,6 @@ void main() {
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeSummaryToFile(summaryName, pretty: true);
await summary.writeTimelineToFile(summaryName, pretty: true);
}
......
......@@ -36,7 +36,6 @@ Future<void> main() async {
if (timeline != null) {
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeSummaryToFile(fileName, pretty: true);
await summary.writeTimelineToFile(fileName, pretty: true);
}
......
......@@ -67,7 +67,6 @@ void macroPerfTest(
expect(timeline, isNotNull);
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeSummaryToFile(testName, pretty: true);
await summary.writeTimelineToFile(testName, pretty: true);
}, timeout: Timeout(timeout));
}
......@@ -47,7 +47,6 @@ void main() {
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeSummaryToFile(summaryName, pretty: true);
await summary.writeTimelineToFile(summaryName, pretty: true);
}
......
......@@ -47,7 +47,6 @@ void main() {
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
summary.writeSummaryToFile(summaryName, pretty: true);
summary.writeTimelineToFile(summaryName, pretty: true);
}
......
......@@ -40,7 +40,6 @@ void main() {
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeSummaryToFile('stocks_scroll_perf', pretty: true);
await summary.writeTimelineToFile('stocks_scroll_perf', pretty: true);
});
});
......
......@@ -44,7 +44,6 @@ void main() {
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeSummaryToFile('home_scroll_perf', pretty: true);
await summary.writeTimelineToFile('home_scroll_perf', pretty: true);
});
});
......
......@@ -207,7 +207,6 @@ void main([List<String> args = const <String>[]]) {
// that follows a 'Start Transition' event. The Gallery app adds a
// 'Start Transition' event when a demo is launched (see GalleryItem).
final TimelineSummary summary = TimelineSummary.summarize(timeline);
await summary.writeSummaryToFile('transitions', pretty: true);
await summary.writeTimelineToFile('transitions', pretty: true);
final String histogramPath = path.join(testOutputsDirectory, 'transition_durations.timeline.json');
await saveDurationsHistogram(
......
......@@ -202,6 +202,10 @@ class TimelineSummary {
/// Writes all of the recorded timeline data to a file.
///
/// By default, this will dump [summaryJson] to a companion file named
/// `$traceName.timeline_summary.json`. If you want to skip the summary, set
/// the `includeSummary` parameter to false.
///
/// See also:
///
/// * [Timeline.fromJson], which explains detail about the timeline data.
......@@ -209,20 +213,37 @@ class TimelineSummary {
String traceName, {
String? destinationDirectory,
bool pretty = false,
bool includeSummary = true,
}) async {
destinationDirectory ??= testOutputsDirectory;
await fs.directory(destinationDirectory).create(recursive: true);
final File file = fs.file(path.join(destinationDirectory, '$traceName.timeline.json'));
await file.writeAsString(_encodeJson(_timeline.json, pretty));
if (includeSummary) {
await _writeSummaryToFile(traceName, destinationDirectory: destinationDirectory, pretty: pretty);
}
}
/// Writes [summaryJson] to a file.
@Deprecated(
'Use TimelineSummary.writeTimelineToFile. '
'This feature was deprecated after v2.1.0-13.0.pre.'
)
Future<void> writeSummaryToFile(
String traceName, {
String? destinationDirectory,
bool pretty = false,
}) async {
destinationDirectory ??= testOutputsDirectory;
await _writeSummaryToFile(traceName, destinationDirectory: destinationDirectory, pretty: pretty);
}
Future<void> _writeSummaryToFile(
String traceName, {
required String destinationDirectory,
bool pretty = false,
}) async {
await fs.directory(destinationDirectory).create(recursive: true);
final File file = fs.file(path.join(destinationDirectory, '$traceName.timeline_summary.json'));
await file.writeAsString(_encodeJson(summaryJson, pretty));
......
......@@ -434,14 +434,36 @@ void main() {
restoreFileSystem();
});
test('writes timeline to JSON file', () async {
test('writes timeline to JSON file without summary', () async {
await summarize(<Map<String, String>>[<String, String>{'foo': 'bar'}])
.writeTimelineToFile('test', destinationDirectory: tempDir.path);
.writeTimelineToFile('test', destinationDirectory: tempDir.path, includeSummary: false);
final String written =
await fs.file(path.join(tempDir.path, 'test.timeline.json')).readAsString();
expect(written, '{"traceEvents":[{"foo":"bar"}]}');
});
test('writes timeline to JSON file with summary', () async {
await summarize(<Map<String, dynamic>>[
<String, String>{'foo': 'bar'},
begin(1000), end(19000),
frameBegin(1000), frameEnd(18000),
]).writeTimelineToFile(
'test',
destinationDirectory: tempDir.path,
includeSummary: true,
);
final String written =
await fs.file(path.join(tempDir.path, 'test.timeline.json')).readAsString();
expect(
written,
'{"traceEvents":[{"foo":"bar"},'
'{"name":"GPURasterizer::Draw","ph":"B","ts":1000},'
'{"name":"GPURasterizer::Draw","ph":"E","ts":19000},'
'{"name":"Frame","ph":"B","ts":1000},'
'{"name":"Frame","ph":"E","ts":18000}]}',
);
});
test('writes summary to JSON file', () async {
await summarize(<Map<String, dynamic>>[
begin(1000), end(19000),
......@@ -456,7 +478,7 @@ void main() {
cpuUsage(5000, 20), cpuUsage(5010, 60),
memoryUsage(6000, 20, 40), memoryUsage(6100, 30, 45),
platformVsync(7000), vsyncCallback(7500),
]).writeSummaryToFile('test', destinationDirectory: tempDir.path);
]).writeTimelineToFile('test', destinationDirectory: tempDir.path);
final String written =
await fs.file(path.join(tempDir.path, 'test.timeline_summary.json')).readAsString();
expect(json.decode(written), <String, dynamic>{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment