Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: pkg/analysis_server/lib/src/status/get_handler.dart

Issue 2140583003: Initial memory use status page (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analysis_server.src.status.get_handler; 5 library analysis_server.src.status.get_handler;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:math'; 10 import 'dart:math';
11 11
12 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; 12 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element;
13 import 'package:analysis_server/src/analysis_server.dart'; 13 import 'package:analysis_server/src/analysis_server.dart';
14 import 'package:analysis_server/src/domain_completion.dart'; 14 import 'package:analysis_server/src/domain_completion.dart';
15 import 'package:analysis_server/src/domain_diagnostic.dart'; 15 import 'package:analysis_server/src/domain_diagnostic.dart';
16 import 'package:analysis_server/src/domain_execution.dart'; 16 import 'package:analysis_server/src/domain_execution.dart';
17 import 'package:analysis_server/src/operation/operation.dart'; 17 import 'package:analysis_server/src/operation/operation.dart';
18 import 'package:analysis_server/src/operation/operation_analysis.dart'; 18 import 'package:analysis_server/src/operation/operation_analysis.dart';
19 import 'package:analysis_server/src/operation/operation_queue.dart'; 19 import 'package:analysis_server/src/operation/operation_queue.dart';
20 import 'package:analysis_server/src/services/completion/completion_performance.d art'; 20 import 'package:analysis_server/src/services/completion/completion_performance.d art';
21 import 'package:analysis_server/src/socket_server.dart'; 21 import 'package:analysis_server/src/socket_server.dart';
22 import 'package:analysis_server/src/status/ast_writer.dart'; 22 import 'package:analysis_server/src/status/ast_writer.dart';
23 import 'package:analysis_server/src/status/element_writer.dart'; 23 import 'package:analysis_server/src/status/element_writer.dart';
24 import 'package:analysis_server/src/status/memory_use.dart';
24 import 'package:analysis_server/src/status/validator.dart'; 25 import 'package:analysis_server/src/status/validator.dart';
25 import 'package:analysis_server/src/utilities/average.dart'; 26 import 'package:analysis_server/src/utilities/average.dart';
26 import 'package:analyzer/dart/ast/ast.dart'; 27 import 'package:analyzer/dart/ast/ast.dart';
27 import 'package:analyzer/dart/element/element.dart'; 28 import 'package:analyzer/dart/element/element.dart';
28 import 'package:analyzer/dart/element/visitor.dart'; 29 import 'package:analyzer/dart/element/visitor.dart';
29 import 'package:analyzer/file_system/file_system.dart'; 30 import 'package:analyzer/file_system/file_system.dart';
30 import 'package:analyzer/source/embedder.dart'; 31 import 'package:analyzer/source/embedder.dart';
31 import 'package:analyzer/source/error_processor.dart'; 32 import 'package:analyzer/source/error_processor.dart';
32 import 'package:analyzer/source/sdk_ext.dart'; 33 import 'package:analyzer/source/sdk_ext.dart';
33 import 'package:analyzer/src/context/cache.dart'; 34 import 'package:analyzer/src/context/cache.dart';
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 * The path used to request diagnostic information. 252 * The path used to request diagnostic information.
252 */ 253 */
253 static const String DIAGNOSTIC_PATH = '/diagnostic'; 254 static const String DIAGNOSTIC_PATH = '/diagnostic';
254 255
255 /** 256 /**
256 * The path used to request information about a element model. 257 * The path used to request information about a element model.
257 */ 258 */
258 static const String ELEMENT_PATH = '/element'; 259 static const String ELEMENT_PATH = '/element';
259 260
260 /** 261 /**
262 * The path used to request an analysis of the memory use of the analyzer.
263 */
264 static const String MEMORY_USE_PATH = '/memoryUse';
265
266 /**
261 * The path used to request an overlay contents. 267 * The path used to request an overlay contents.
262 */ 268 */
263 static const String OVERLAY_PATH = '/overlay'; 269 static const String OVERLAY_PATH = '/overlay';
264 270
265 /** 271 /**
266 * The path used to request overlays information. 272 * The path used to request overlays information.
267 */ 273 */
268 static const String OVERLAYS_PATH = '/overlays'; 274 static const String OVERLAYS_PATH = '/overlays';
269 275
270 /** 276 /**
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } else if (path == CONTEXT_DIAGNOSTICS_PATH) { 389 } else if (path == CONTEXT_DIAGNOSTICS_PATH) {
384 _returnContextDiagnostics(request); 390 _returnContextDiagnostics(request);
385 } else if (path == CONTEXT_VALIDATION_DIAGNOSTICS_PATH) { 391 } else if (path == CONTEXT_VALIDATION_DIAGNOSTICS_PATH) {
386 _returnContextValidationDiagnostics(request); 392 _returnContextValidationDiagnostics(request);
387 } else if (path == CONTEXT_PATH) { 393 } else if (path == CONTEXT_PATH) {
388 _returnContextInfo(request); 394 _returnContextInfo(request);
389 } else if (path == DIAGNOSTIC_PATH) { 395 } else if (path == DIAGNOSTIC_PATH) {
390 _returnDiagnosticInfo(request); 396 _returnDiagnosticInfo(request);
391 } else if (path == ELEMENT_PATH) { 397 } else if (path == ELEMENT_PATH) {
392 _returnElement(request); 398 _returnElement(request);
399 } else if (path == MEMORY_USE_PATH) {
400 _returnMemoryUsage(request);
393 } else if (path == OVERLAY_PATH) { 401 } else if (path == OVERLAY_PATH) {
394 _returnOverlayContents(request); 402 _returnOverlayContents(request);
395 } else if (path == OVERLAYS_PATH) { 403 } else if (path == OVERLAYS_PATH) {
396 _returnOverlaysInfo(request); 404 _returnOverlaysInfo(request);
397 } else { 405 } else {
398 _returnUnknownRequest(request); 406 _returnUnknownRequest(request);
399 } 407 }
400 } 408 }
401 409
402 /** 410 /**
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 1645
1638 void _returnFailure(HttpRequest request, String message) { 1646 void _returnFailure(HttpRequest request, String message) {
1639 _writeResponse(request, (StringBuffer buffer) { 1647 _writeResponse(request, (StringBuffer buffer) {
1640 _writePage(buffer, 'Analysis Server - Failure', [], 1648 _writePage(buffer, 'Analysis Server - Failure', [],
1641 (StringBuffer buffer) { 1649 (StringBuffer buffer) {
1642 buffer.write(HTML_ESCAPE.convert(message)); 1650 buffer.write(HTML_ESCAPE.convert(message));
1643 }); 1651 });
1644 }); 1652 });
1645 } 1653 }
1646 1654
1655 void _returnMemoryUsage(HttpRequest request) {
1656 _writeResponse(request, (StringBuffer buffer) {
1657 _writePage(buffer, 'Analysis Server - Memory Use', [],
1658 (StringBuffer buffer) {
1659 AnalysisServer server = _server.analysisServer;
1660 MemoryUseData data = new MemoryUseData();
1661 data.processAnalysisServer(server);
1662 Map<Type, HashSet> instances = data.instances;
1663 List<Type> classNames = instances.keys.toList();
scheglov 2016/07/11 15:27:49 These are not names, but types. Just in case if th
Brian Wilkerson 2016/07/11 17:26:36 It was accidental, thanks. Done.
1664 classNames.sort((Type left, Type right) =>
1665 left.toString().compareTo(right.toString()));
1666
1667 buffer.write('<h3>Instance Counts (reachable from contexts)</h3>');
1668 buffer.write('<table>');
1669 _writeRow(buffer, ['Count', 'Class name'], header: true);
1670 classNames.forEach((Type type) {
1671 _writeRow(buffer, [instances[type].length, type],
1672 classes: ['right', null]);
1673 });
1674 buffer.write('</table>');
1675
1676 void writeCountMap(String title, Map<Type, int> counts) {
1677 List<Type> classNames = counts.keys.toList();
1678 classNames.sort((Type left, Type right) =>
1679 left.toString().compareTo(right.toString()));
1680
1681 buffer.write('<h3>$title</h3>');
1682 buffer.write('<table>');
1683 _writeRow(buffer, ['Count', 'Class name'], header: true);
1684 classNames.forEach((Type type) {
1685 _writeRow(buffer, [counts[type], type], classes: ['right', null]);
1686 });
1687 buffer.write('</table>');
1688 }
1689 writeCountMap('Directly Held AST Nodes', data.directNodeCounts);
1690 writeCountMap('Indirectly Held AST Nodes', data.indirectNodeCounts);
1691 writeCountMap('Directly Held Elements', data.elementCounts);
1692
1693 buffer.write('<h3>Other Data</h3>');
1694 buffer.write('<p>');
1695 buffer.write(data.uniqueTargetedResults.length);
1696 buffer.write(' non-equal TargetedResults</p>');
1697 buffer.write('<p>');
1698 buffer.write(data.uniqueLSUs.length);
1699 buffer.write(' non-equal LibrarySpecificUnits</p>');
1700 });
1701 });
1702 }
1703
1647 void _returnOverlayContents(HttpRequest request) { 1704 void _returnOverlayContents(HttpRequest request) {
1648 String path = request.requestedUri.queryParameters[PATH_PARAM]; 1705 String path = request.requestedUri.queryParameters[PATH_PARAM];
1649 if (path == null) { 1706 if (path == null) {
1650 return _returnFailure(request, 'Query parameter $PATH_PARAM required'); 1707 return _returnFailure(request, 'Query parameter $PATH_PARAM required');
1651 } 1708 }
1652 String contents = _overlayContents[path]; 1709 String contents = _overlayContents[path];
1653 1710
1654 _writeResponse(request, (StringBuffer buffer) { 1711 _writeResponse(request, (StringBuffer buffer) {
1655 _writePage(buffer, 'Analysis Server - Overlay', [], 1712 _writePage(buffer, 'Analysis Server - Overlay', [],
1656 (StringBuffer buffer) { 1713 (StringBuffer buffer) {
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2221 /** 2278 /**
2222 * Write to the given [buffer] a representation of the given [map] of strings 2279 * Write to the given [buffer] a representation of the given [map] of strings
2223 * to strings. 2280 * to strings.
2224 */ 2281 */
2225 void _writeMapOfStringToString(StringBuffer buffer, Map<String, String> map) { 2282 void _writeMapOfStringToString(StringBuffer buffer, Map<String, String> map) {
2226 List<String> keys = map.keys.toList(); 2283 List<String> keys = map.keys.toList();
2227 keys.sort(); 2284 keys.sort();
2228 int length = keys.length; 2285 int length = keys.length;
2229 buffer.write('{'); 2286 buffer.write('{');
2230 for (int i = 0; i < length; i++) { 2287 for (int i = 0; i < length; i++) {
2288 buffer.write('<br>');
2231 String key = keys[i]; 2289 String key = keys[i];
2232 if (i > 0) { 2290 if (i > 0) {
2233 buffer.write(', '); 2291 buffer.write(', ');
2234 } 2292 }
2235 buffer.write(key); 2293 buffer.write(key);
2236 buffer.write(' = '); 2294 buffer.write(' = ');
2237 buffer.write(map[key]); 2295 buffer.write(map[key]);
2238 } 2296 }
2239 buffer.write('}'); 2297 buffer.write('<br>}');
2240 } 2298 }
2241 2299
2242 /** 2300 /**
2243 * Write a representation of an analysis option with the given [name] and 2301 * Write a representation of an analysis option with the given [name] and
2244 * [value] to the given [buffer]. The option should be separated from other 2302 * [value] to the given [buffer]. The option should be separated from other
2245 * options unless the [last] flag is true, indicating that this is the last 2303 * options unless the [last] flag is true, indicating that this is the last
2246 * option in the list of options. 2304 * option in the list of options.
2247 */ 2305 */
2248 void _writeOption(StringBuffer buffer, String name, Object value, 2306 void _writeOption(StringBuffer buffer, String name, Object value,
2249 {bool last: false}) { 2307 {bool last: false}) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 buffer.write( 2340 buffer.write(
2283 'h3 {background-color: #DDDDDD; margin-top: 0em; margin-bottom: 0em;}'); 2341 'h3 {background-color: #DDDDDD; margin-top: 0em; margin-bottom: 0em;}');
2284 buffer.write('p {margin-top: 0.5em; margin-bottom: 0.5em;}'); 2342 buffer.write('p {margin-top: 0.5em; margin-bottom: 0.5em;}');
2285 buffer.write( 2343 buffer.write(
2286 'p.commentary {margin-top: 1em; margin-bottom: 1em; margin-left: 2em; fo nt-style: italic;}'); 2344 'p.commentary {margin-top: 1em; margin-bottom: 1em; margin-left: 2em; fo nt-style: italic;}');
2287 // response.write('span.error {text-decoration-line: underline; text-decorati on-color: red; text-decoration-style: wavy;}'); 2345 // response.write('span.error {text-decoration-line: underline; text-decorati on-color: red; text-decoration-style: wavy;}');
2288 buffer.write( 2346 buffer.write(
2289 'table.column {border: 0px solid black; width: 100%; table-layout: fixed ;}'); 2347 'table.column {border: 0px solid black; width: 100%; table-layout: fixed ;}');
2290 buffer.write('td.column {vertical-align: top; width: 50%;}'); 2348 buffer.write('td.column {vertical-align: top; width: 50%;}');
2291 buffer.write('td.right {text-align: right;}'); 2349 buffer.write('td.right {text-align: right;}');
2350 buffer.write('th {text-align: left;}');
2292 buffer.write('</style>'); 2351 buffer.write('</style>');
2293 buffer.write('</head>'); 2352 buffer.write('</head>');
2294 2353
2295 buffer.write('<body>'); 2354 buffer.write('<body>');
2296 buffer.write( 2355 buffer.write(
2297 '<h2>$title <small><small>(as of $time on $date)</small></small></h2>'); 2356 '<h2>$title <small><small>(as of $time on $date)</small></small></h2>');
2298 if (subtitles != null && subtitles.isNotEmpty) { 2357 if (subtitles != null && subtitles.isNotEmpty) {
2299 buffer.write('<blockquote>'); 2358 buffer.write('<blockquote>');
2300 bool first = true; 2359 bool first = true;
2301 for (String subtitle in subtitles) { 2360 for (String subtitle in subtitles) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2440 buffer.write('</p>'); 2499 buffer.write('</p>');
2441 2500
2442 buffer.write('<p><b>Performance Data</b></p>'); 2501 buffer.write('<p><b>Performance Data</b></p>');
2443 buffer.write('<p>'); 2502 buffer.write('<p>');
2444 buffer.write(makeLink( 2503 buffer.write(makeLink(
2445 COMMUNICATION_PERFORMANCE_PATH, {}, 'Communication performance')); 2504 COMMUNICATION_PERFORMANCE_PATH, {}, 'Communication performance'));
2446 buffer.write('</p>'); 2505 buffer.write('</p>');
2447 buffer.write('<p>'); 2506 buffer.write('<p>');
2448 buffer.write(makeLink(DIAGNOSTIC_PATH, {}, 'General diagnostics')); 2507 buffer.write(makeLink(DIAGNOSTIC_PATH, {}, 'General diagnostics'));
2449 buffer.write('</p>'); 2508 buffer.write('</p>');
2509 buffer.write('<p>');
2510 buffer.write(makeLink(MEMORY_USE_PATH, {}, 'Memory usage'));
2511 buffer.write(' <small>(long running)</small></p>');
2450 }, (StringBuffer buffer) { 2512 }, (StringBuffer buffer) {
2451 _writeSubscriptionList(buffer, ServerService.VALUES, services); 2513 _writeSubscriptionList(buffer, ServerService.VALUES, services);
2452 }); 2514 });
2453 return analysisServer != null; 2515 return analysisServer != null;
2454 } 2516 }
2455 2517
2456 /** 2518 /**
2457 * Write a representation of the given [stackTrace] to the given [buffer]. 2519 * Write a representation of the given [stackTrace] to the given [buffer].
2458 */ 2520 */
2459 void _writeStackTrace(StringBuffer buffer, StackTrace stackTrace) { 2521 void _writeStackTrace(StringBuffer buffer, StackTrace stackTrace) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2647 */ 2709 */
2648 static String makeLink( 2710 static String makeLink(
2649 String path, Map<String, String> params, String innerHtml, 2711 String path, Map<String, String> params, String innerHtml,
2650 [bool hasError = false]) { 2712 [bool hasError = false]) {
2651 Uri uri = new Uri(path: path, queryParameters: params); 2713 Uri uri = new Uri(path: path, queryParameters: params);
2652 String href = HTML_ESCAPE.convert(uri.toString()); 2714 String href = HTML_ESCAPE.convert(uri.toString());
2653 String classAttribute = hasError ? ' class="error"' : ''; 2715 String classAttribute = hasError ? ' class="error"' : '';
2654 return '<a href="$href"$classAttribute>$innerHtml</a>'; 2716 return '<a href="$href"$classAttribute>$innerHtml</a>';
2655 } 2717 }
2656 } 2718 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/status/memory_use.dart » ('j') | pkg/analysis_server/lib/src/status/memory_use.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698