Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search to the Network profiler #2333

Merged
merged 4 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/devtools_app/lib/src/http/http_request_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ class HttpRequestData extends NetworkRequest {
/// around the issue by displaying them as "in-progress". It would be
/// reasonable to display them as "unknown start time" but that seems like
/// more complexity than it is worth.
bool get isValid => _startEvent != null;
// TODO(kenz): https://github.com/flutter/devtools/issues/2335 - figure out
// how to handle HTTP body events in the network profiler. For now, mark them
// as invalid.
bool get isValid =>
_startEvent != null && !_startEvent.name.contains('HTTP CLIENT response');
kenzieschmoll marked this conversation as resolved.
Show resolved Hide resolved

/// True if either the request or response contained cookies.
bool get hasCookies =>
Expand Down
23 changes: 22 additions & 1 deletion packages/devtools_app/lib/src/network/network_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import '../config_specific/logger/allowed_error.dart';
import '../globals.dart';
import '../http/http_request_data.dart';
import '../http/http_service.dart';
import '../ui/search.dart';
import 'network_model.dart';
import 'network_service.dart';

class NetworkController {
class NetworkController with SearchControllerMixin<NetworkRequest> {
NetworkController() {
_networkService = NetworkService(this);
}
Expand Down Expand Up @@ -168,6 +169,7 @@ class NetworkController {
invalidRequests: [],
outstandingRequestsMap: Map.from(requests.value.outstandingHttpRequests),
);
refreshSearchMatches();
}

Future<void> _toggleHttpTimelineRecording(bool state) async {
Expand Down Expand Up @@ -253,6 +255,25 @@ class NetworkController {
Future<void> clear() async {
await _networkService.clearData();
_requests.value = NetworkRequests();
refreshSearchMatches();
_selectedRequest.value = null;
}

@override
List<NetworkRequest> matchesForSearch(String search) {
if (search == null || search.isEmpty) return [];
final matches = <NetworkRequest>[];
final caseInsensitiveSearch = search.toLowerCase();

// TODO(kenz): support intelligent search queries like t:http (type = http)
// or m:GET (method = GET).

final currentRequests = _requests.value.requests;
for (final request in currentRequests) {
if (request.uri.toLowerCase().contains(caseInsensitiveSearch)) {
matches.add(request);
}
}
return matches;
}
}
29 changes: 27 additions & 2 deletions packages/devtools_app/lib/src/network/network_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:provider/provider.dart';
Expand All @@ -15,11 +16,14 @@ import '../split.dart';
import '../table.dart';
import '../table_data.dart';
import '../theme.dart';
import '../ui/search.dart';
import '../utils.dart';
import 'network_controller.dart';
import 'network_model.dart';
import 'network_request_inspector.dart';

final networkSearchFieldKey = GlobalKey(debugLabel: 'NetworkSearchFieldKey');

class NetworkScreen extends Screen {
const NetworkScreen()
: super.conditional(
Expand Down Expand Up @@ -88,7 +92,7 @@ class NetworkScreenBody extends StatefulWidget {
}

class _NetworkScreenBodyState extends State<NetworkScreenBody>
with AutoDisposeMixin {
with AutoDisposeMixin, SearchFieldMixin {
NetworkController _networkController;

bool recording;
Expand Down Expand Up @@ -137,7 +141,7 @@ class _NetworkScreenBodyState extends State<NetworkScreenBody>
/// pause, etc.)
Row _buildProfilerControls() {
const double includeTextWidth = 600;

final hasRequests = requests.requests.isNotEmpty;
return Row(
children: [
recordButton(
Expand All @@ -161,6 +165,18 @@ class _NetworkScreenBodyState extends State<NetworkScreenBody>
_networkController.clear();
},
),
const Expanded(child: SizedBox()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change the properties on the row instead of adding this degenerate expanded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are six other items in the row, so changing the row alignment would affect all of those items as well. I could wrap all the other items in their own row, and then use spaceBetween but this felt simpler and cleaner

Container(
width: wideSearchTextWidth,
height: defaultSearchTextHeight,
child: buildSearchField(
controller: _networkController,
searchFieldKey: networkSearchFieldKey,
searchFieldEnabled: hasRequests,
shouldRequestFocus: false,
supportsNavigation: true,
),
),
],
);
}
Expand Down Expand Up @@ -190,6 +206,9 @@ class _NetworkScreenBodyState extends State<NetworkScreenBody>
NetworkRequestsTable(
networkController: _networkController,
requests: requests,
searchMatchesNotifier: _networkController.searchMatches,
activeSearchMatchNotifier:
_networkController.activeSearchMatch,
),
NetworkRequestInspector(selectedRequest),
],
Expand All @@ -216,6 +235,8 @@ class NetworkRequestsTable extends StatelessWidget {
Key key,
@required this.networkController,
@required this.requests,
@required this.searchMatchesNotifier,
@required this.activeSearchMatchNotifier,
}) : super(key: key);

static MethodColumn methodColumn = MethodColumn();
Expand All @@ -227,6 +248,8 @@ class NetworkRequestsTable extends StatelessWidget {

final NetworkController networkController;
final List<NetworkRequest> requests;
final ValueListenable<List<NetworkRequest>> searchMatchesNotifier;
final ValueListenable<NetworkRequest> activeSearchMatchNotifier;

@override
Widget build(BuildContext context) {
Expand All @@ -248,6 +271,8 @@ class NetworkRequestsTable extends StatelessWidget {
autoScrollContent: true,
sortColumn: timestampColumn,
sortDirection: SortDirection.ascending,
searchMatchesNotifier: searchMatchesNotifier,
activeSearchMatchNotifier: activeSearchMatchNotifier,
),
);
}
Expand Down
Loading