Commit e43fd1c5 authored by Gityuan's avatar Gityuan Committed by Francisco Magdaleno

fix duration event of timeline summary (#47742)

* fix duration event of timeline summary

* Revert "fix duration event of timeline summary"

This reverts commit 699aa45ed3d115f8bbea95cf6d37116b442db399.

* fix duration event of timeline summary
parent ae24f184
...@@ -57,27 +57,27 @@ class TimelineSummary { ...@@ -57,27 +57,27 @@ class TimelineSummary {
/// ///
/// Returns null if no frames were recorded. /// Returns null if no frames were recorded.
double computeAverageFrameRasterizerTimeMillis() { double computeAverageFrameRasterizerTimeMillis() {
return _averageInMillis(_extractDuration(_extractGpuRasterizerDrawEvents())); return _averageInMillis(_extractGpuRasterizerDrawDurations());
} }
/// The longest frame rasterization time in milliseconds. /// The longest frame rasterization time in milliseconds.
/// ///
/// Returns null if no frames were recorded. /// Returns null if no frames were recorded.
double computeWorstFrameRasterizerTimeMillis() { double computeWorstFrameRasterizerTimeMillis() {
return _maxInMillis(_extractDuration(_extractGpuRasterizerDrawEvents())); return _maxInMillis(_extractGpuRasterizerDrawDurations());
} }
/// The [p]-th percentile frame rasterization time in milliseconds. /// The [p]-th percentile frame rasterization time in milliseconds.
/// ///
/// Returns null if no frames were recorded. /// Returns null if no frames were recorded.
double computePercentileFrameRasterizerTimeMillis(double p) { double computePercentileFrameRasterizerTimeMillis(double p) {
return _percentileInMillis(_extractDuration(_extractGpuRasterizerDrawEvents()), p); return _percentileInMillis(_extractGpuRasterizerDrawDurations(), p);
} }
/// The number of frames that missed the [kBuildBudget] on the GPU and /// The number of frames that missed the [kBuildBudget] on the GPU and
/// therefore are in the danger of missing frames. /// therefore are in the danger of missing frames.
int computeMissedFrameRasterizerBudgetCount([ Duration frameBuildBudget = kBuildBudget ]) => _extractGpuRasterizerDrawEvents() int computeMissedFrameRasterizerBudgetCount([ Duration frameBuildBudget = kBuildBudget ]) => _extractGpuRasterizerDrawDurations()
.where((TimedEvent event) => event.duration > kBuildBudget) .where((Duration duration) => duration > kBuildBudget)
.length; .length;
/// The total number of frames recorded in the timeline. /// The total number of frames recorded in the timeline.
...@@ -100,8 +100,8 @@ class TimelineSummary { ...@@ -100,8 +100,8 @@ class TimelineSummary {
'frame_build_times': _extractFrameDurations() 'frame_build_times': _extractFrameDurations()
.map<int>((Duration duration) => duration.inMicroseconds) .map<int>((Duration duration) => duration.inMicroseconds)
.toList(), .toList(),
'frame_rasterizer_times': _extractGpuRasterizerDrawEvents() 'frame_rasterizer_times': _extractGpuRasterizerDrawDurations()
.map<int>((TimedEvent event) => event.duration.inMicroseconds) .map<int>((Duration duration) => duration.inMicroseconds)
.toList(), .toList(),
}; };
} }
...@@ -142,15 +142,11 @@ class TimelineSummary { ...@@ -142,15 +142,11 @@ class TimelineSummary {
.toList(); .toList();
} }
List<Duration> _extractDurations(String name) { /// Extracts Duration list that are reported as a pair of begin/end events.
return _extractNamedEvents(name).map<Duration>((TimelineEvent event) => event.duration).toList();
}
/// Extracts timed events that are reported as a pair of begin/end events.
/// ///
/// See: https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU /// See: https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU
List<TimedEvent> _extractBeginEndEvents(String name) { List<Duration> _extractBeginEndEvents(String name) {
final List<TimedEvent> result = <TimedEvent>[]; final List<Duration> result = <Duration>[];
// Timeline does not guarantee that the first event is the "begin" event. // Timeline does not guarantee that the first event is the "begin" event.
final Iterator<TimelineEvent> events = _extractNamedEvents(name) final Iterator<TimelineEvent> events = _extractNamedEvents(name)
...@@ -159,10 +155,7 @@ class TimelineSummary { ...@@ -159,10 +155,7 @@ class TimelineSummary {
final TimelineEvent beginEvent = events.current; final TimelineEvent beginEvent = events.current;
if (events.moveNext()) { if (events.moveNext()) {
final TimelineEvent endEvent = events.current; final TimelineEvent endEvent = events.current;
result.add(TimedEvent( result.add(Duration(microseconds: endEvent.timestampMicros - beginEvent.timestampMicros));
beginEvent.timestampMicros,
endEvent.timestampMicros,
));
} }
} }
...@@ -194,21 +187,7 @@ class TimelineSummary { ...@@ -194,21 +187,7 @@ class TimelineSummary {
.reduce(math.max); .reduce(math.max);
} }
List<TimedEvent> _extractGpuRasterizerDrawEvents() => _extractBeginEndEvents('GPURasterizer::Draw'); List<Duration> _extractGpuRasterizerDrawDurations() => _extractBeginEndEvents('GPURasterizer::Draw');
List<Duration> _extractFrameDurations() => _extractDurations('Frame');
Iterable<Duration> _extractDuration(Iterable<TimedEvent> events) {
return events.map<Duration>((TimedEvent e) => e.duration);
}
}
/// Timing information about an event that happened in the event loop.
class TimedEvent {
/// Creates a timed event given begin and end timestamps in microseconds.
TimedEvent(int beginTimeMicros, int endTimeMicros)
: duration = Duration(microseconds: endTimeMicros - beginTimeMicros);
/// The duration of the event. List<Duration> _extractFrameDurations() => _extractBeginEndEvents('Frame');
final Duration duration;
} }
...@@ -20,11 +20,16 @@ void main() { ...@@ -20,11 +20,16 @@ void main() {
})); }));
} }
Map<String, dynamic> build(int timeStamp, int duration) => <String, dynamic>{ Map<String, dynamic> frameBegin(int timeStamp) => <String, dynamic>{
'name': 'Frame', 'name': 'Frame',
'ph': 'X', 'ph': 'B',
'ts': timeStamp,
};
Map<String, dynamic> frameEnd(int timeStamp) => <String, dynamic>{
'name': 'Frame',
'ph': 'E',
'ts': timeStamp, 'ts': timeStamp,
'dur': duration,
}; };
Map<String, dynamic> begin(int timeStamp) => <String, dynamic>{ Map<String, dynamic> begin(int timeStamp) => <String, dynamic>{
...@@ -54,8 +59,8 @@ void main() { ...@@ -54,8 +59,8 @@ void main() {
test('counts frames', () { test('counts frames', () {
expect( expect(
summarize(<Map<String, dynamic>>[ summarize(<Map<String, dynamic>>[
build(1000, 1000), frameBegin(1000), frameEnd(2000),
build(3000, 2000), frameBegin(3000), frameEnd(5000),
]).countFrames(), ]).countFrames(),
2, 2,
); );
...@@ -73,12 +78,32 @@ void main() { ...@@ -73,12 +78,32 @@ void main() {
test('computes average frame build time in milliseconds', () { test('computes average frame build time in milliseconds', () {
expect( expect(
summarize(<Map<String, dynamic>>[ summarize(<Map<String, dynamic>>[
build(1000, 1000), frameBegin(1000), frameEnd(2000),
build(3000, 2000), frameBegin(3000), frameEnd(5000),
]).computeAverageFrameBuildTimeMillis(), ]).computeAverageFrameBuildTimeMillis(),
1.5, 1.5,
); );
}); });
test('skips leading "end" events', () {
expect(
summarize(<Map<String, dynamic>>[
frameEnd(1000),
frameBegin(2000), frameEnd(4000),
]).computeAverageFrameBuildTimeMillis(),
2.0,
);
});
test('skips trailing "begin" events', () {
expect(
summarize(<Map<String, dynamic>>[
frameBegin(2000), frameEnd(4000),
frameBegin(5000),
]).computeAverageFrameBuildTimeMillis(),
2.0,
);
});
}); });
group('worst_frame_build_time_millis', () { group('worst_frame_build_time_millis', () {
...@@ -92,15 +117,35 @@ void main() { ...@@ -92,15 +117,35 @@ void main() {
test('computes worst frame build time in milliseconds', () { test('computes worst frame build time in milliseconds', () {
expect( expect(
summarize(<Map<String, dynamic>>[ summarize(<Map<String, dynamic>>[
build(1000, 1000), frameBegin(1000), frameEnd(2000),
build(3000, 2000), frameBegin(3000), frameEnd(5000),
]).computeWorstFrameBuildTimeMillis(),
2.0,
);
expect(
summarize(<Map<String, dynamic>>[
frameBegin(3000), frameEnd(5000),
frameBegin(1000), frameEnd(2000),
]).computeWorstFrameBuildTimeMillis(), ]).computeWorstFrameBuildTimeMillis(),
2.0, 2.0,
); );
});
test('skips leading "end" events', () {
expect(
summarize(<Map<String, dynamic>>[
frameEnd(1000),
frameBegin(2000), frameEnd(4000),
]).computeWorstFrameBuildTimeMillis(),
2.0,
);
});
test('skips trailing "begin" events', () {
expect( expect(
summarize(<Map<String, dynamic>>[ summarize(<Map<String, dynamic>>[
build(3000, 2000), frameBegin(2000), frameEnd(4000),
build(1000, 1000), frameBegin(5000),
]).computeWorstFrameBuildTimeMillis(), ]).computeWorstFrameBuildTimeMillis(),
2.0, 2.0,
); );
...@@ -110,9 +155,9 @@ void main() { ...@@ -110,9 +155,9 @@ void main() {
group('computeMissedFrameBuildBudgetCount', () { group('computeMissedFrameBuildBudgetCount', () {
test('computes the number of missed build budgets', () { test('computes the number of missed build budgets', () {
final TimelineSummary summary = summarize(<Map<String, dynamic>>[ final TimelineSummary summary = summarize(<Map<String, dynamic>>[
build(1000, 17000), frameBegin(1000), frameEnd(18000),
build(19000, 9000), frameBegin(19000), frameEnd(28000),
build(29000, 18000), frameBegin(29000), frameEnd(47000),
]); ]);
expect(summary.countFrames(), 3); expect(summary.countFrames(), 3);
...@@ -267,9 +312,9 @@ void main() { ...@@ -267,9 +312,9 @@ void main() {
begin(1000), end(19000), begin(1000), end(19000),
begin(19000), end(29000), begin(19000), end(29000),
begin(29000), end(49000), begin(29000), end(49000),
build(1000, 17000), frameBegin(1000), frameEnd(18000),
build(19000, 9000), frameBegin(19000), frameEnd(28000),
build(29000, 19000), frameBegin(29000), frameEnd(48000),
]).summaryJson, ]).summaryJson,
<String, dynamic>{ <String, dynamic>{
'average_frame_build_time_millis': 15.0, 'average_frame_build_time_millis': 15.0,
...@@ -317,9 +362,9 @@ void main() { ...@@ -317,9 +362,9 @@ void main() {
begin(1000), end(19000), begin(1000), end(19000),
begin(19000), end(29000), begin(19000), end(29000),
begin(29000), end(49000), begin(29000), end(49000),
build(1000, 17000), frameBegin(1000), frameEnd(18000),
build(19000, 9000), frameBegin(19000), frameEnd(28000),
build(29000, 19000), frameBegin(29000), frameEnd(48000),
]).writeSummaryToFile('test', destinationDirectory: tempDir.path); ]).writeSummaryToFile('test', destinationDirectory: tempDir.path);
final String written = final String written =
await fs.file(path.join(tempDir.path, 'test.timeline_summary.json')).readAsString(); await fs.file(path.join(tempDir.path, 'test.timeline_summary.json')).readAsString();
......
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