-
Notifications
You must be signed in to change notification settings - Fork 306
/
event_details.dart
204 lines (171 loc) · 6.28 KB
/
event_details.dart
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// 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:html' as html;
import '../globals.dart';
import '../profiler/cpu_profile_flame_chart.dart';
import '../profiler/cpu_profile_tables.dart';
import '../profiler/cpu_profiler.dart';
import '../ui/colors.dart';
import '../ui/elements.dart';
import '../ui/fake_flutter/dart_ui/dart_ui.dart';
import '../ui/flutter_html_shim.dart';
import '../ui/theme.dart';
import '../utils.dart';
import 'timeline_controller.dart';
class EventDetails extends CoreElement {
EventDetails(this.timelineController) : super('div') {
flex();
layoutVertical();
_initContent();
_initListeners();
// The size of the event details section will change as the splitter is
// is moved. Observe resizing so that we can rebuild the flame chart canvas
// as necessary.
// TODO(jacobr): Change argument type when
// https://github.com/dart-lang/sdk/issues/36798 is fixed.
final observer = html.ResizeObserver((List<dynamic> entries, _) {
cpuProfiler.flameChart.updateForContainerResize();
});
observer.observe(element);
assert(tabNav != null);
assert(content != null);
add([tabNav.element, content]);
}
static const defaultTitleText = '[No event selected]';
static const defaultTitleBackground = ThemedColor(
Color(0xFFF6F6F6),
Color(0xFF2D2E31), // Material Dark Grey 900+2
);
final TimelineController timelineController;
CpuProfilerTabNav tabNav;
CoreElement content;
CoreElement _title;
_CpuProfiler cpuProfiler;
CoreElement gpuEventDetails;
Color titleBackgroundColor = defaultTitleBackground;
Color titleTextColor = contrastForeground;
void _initContent() {
_title = div(text: defaultTitleText, c: 'event-details-heading');
_title.element.style
..color = colorToCss(titleTextColor)
..backgroundColor = colorToCss(titleBackgroundColor);
final details = div(c: 'event-details')
..layoutVertical()
..flex()
..add([
cpuProfiler = _CpuProfiler(
timelineController,
() => timelineController.timelineData.cpuProfileData,
)..hidden(true),
// TODO(kenzie): eventually we should show something in this area that
// is useful for GPU events as well (tips, links to docs, etc).
gpuEventDetails = div(
text: 'CPU profiling is not available for GPU events.',
c: 'centered-single-line-message',
)..hidden(true),
]);
content = div(c: 'event-details-section section-border')
..flex()
..add(<CoreElement>[_title, details]);
tabNav = CpuProfilerTabNav(
cpuProfiler,
CpuProfilerTabOrder(
first: CpuProfilerViewType.flameChart,
second: CpuProfilerViewType.callTree,
third: CpuProfilerViewType.bottomUp,
),
);
}
void _initListeners() {
timelineController.onSelectedFrame.listen((_) => reset());
timelineController.onSelectedTimelineEvent
.listen((_) async => await update());
timelineController.onLoadOfflineData.listen((_) async {
if (timelineController.timelineData.selectedEvent != null) {
titleTextColor = Colors.black;
titleBackgroundColor = mainUiColor;
await update();
}
});
}
Future<void> update({bool hide = false}) async {
final selectedEvent = timelineController.timelineData?.selectedEvent;
_title.text = selectedEvent != null
? '${selectedEvent.name} - ${msText(selectedEvent.time.duration)}'
: defaultTitleText;
_title.element.style
..backgroundColor = colorToCss(titleBackgroundColor)
..color = colorToCss(titleTextColor);
hidden(hide);
gpuEventDetails.hidden(selectedEvent?.isUiEvent ?? true);
cpuProfiler.hidden(selectedEvent?.isGpuEvent ?? true);
if (selectedEvent != null && selectedEvent.isUiEvent) {
await cpuProfiler.update();
}
}
void reset({bool hide = false}) {
titleTextColor = contrastForeground;
titleBackgroundColor = defaultTitleBackground;
update(hide: hide);
}
}
class _CpuProfiler extends CpuProfiler {
_CpuProfiler(
this._timelineController,
CpuProfileDataProvider profileDataProvider,
) : super(
CpuFlameChart(profileDataProvider),
CpuCallTree(profileDataProvider),
CpuBottomUp(profileDataProvider),
);
final TimelineController _timelineController;
@override
Future<void> prepareCpuProfile() async {
// Fetch a profile if we are not loading from offline.
if (!offlineMode || _timelineController.offlineTimelineData == null) {
await _timelineController.getCpuProfileForSelectedEvent();
}
}
@override
bool maybeShowMessageOnUpdate() {
if (offlineMode &&
_timelineController.timelineData.selectedEvent !=
_timelineController.offlineTimelineData?.selectedEvent) {
final offlineModeMessage = div()
..add(span(
text:
'CPU profiling is not yet available for snapshots. You can only'
' view '));
if (_timelineController.offlineTimelineData?.cpuProfileData != null) {
offlineModeMessage
..add(span(text: 'the '))
..add(span(text: 'CPU profile', c: 'message-action')
..click(
() => _timelineController.restoreCpuProfileFromOfflineData()))
..add(span(text: ' included in the snapshot.'));
} else {
offlineModeMessage.add(span(
text:
'a CPU profile if it is included in the imported snapshot file.'));
}
showMessage(offlineModeMessage);
return true;
}
if (_timelineController.timelineData.cpuProfileData.stackFrames.isEmpty) {
final frameOffset =
_timelineController.timelineData.selectedFrame.time.start;
final startTime =
_timelineController.timelineData.selectedEvent.time.start -
frameOffset;
final endTime =
_timelineController.timelineData.selectedEvent.time.end - frameOffset;
showMessage(div(
text: 'CPU profile unavailable for time range'
' [${msText(startTime, fractionDigits: 2)} -'
' ${msText(endTime, fractionDigits: 2)}]'));
return true;
}
return false;
}
}