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

Side by Side Diff: pkg/analysis_server/test/performance/instrumentation_input_converter.dart

Issue 1182933005: analysis server performance measurement - work in progress (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 6 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) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
1 library input.transformer.instrumentation; 5 library input.transformer.instrumentation;
2 6
3 import 'dart:convert'; 7 import 'dart:convert';
4 8
9 import 'package:analyzer/src/generated/java_engine.dart';
10 import 'package:analyzer/instrumentation/instrumentation.dart';
5 import 'package:logging/logging.dart'; 11 import 'package:logging/logging.dart';
6 12
13 import 'input_converter.dart';
7 import 'operation.dart'; 14 import 'operation.dart';
8 15
9 final int COLON = ':'.codeUnitAt(0); 16 final int COLON = ':'.codeUnitAt(0);
10 17
11 /** 18 /**
12 * [InstrumentationInputConverter] converts an instrumentation stream 19 * [InstrumentationInputConverter] converts an instrumentation stream
13 * into a series of operations to be sent to the analysis server. 20 * into a series of operations to be sent to the analysis server.
14 */ 21 */
15 class InstrumentationInputConverter extends Converter<String, Operation> { 22 class InstrumentationInputConverter extends CommonInputConverter {
16 final Logger logger = new Logger('InstrumentationInputConverter'); 23 final Set<String> codesSeen = new Set<String>();
17 final Set<String> _codesSeen = new Set<String>(); 24
18 final Set<String> _methodsSeen = new Set<String>(); 25 /**
19 final Set<String> _eventsSeen = new Set<String>(); 26 * [readBuffer] holds the contents of the file being read from disk
27 * as recorded in the instrumentation log
28 * or `null` if not converting a "Read" entry.
29 */
30 StringBuffer readBuffer = null;
31
32 InstrumentationInputConverter(Map<String, String> srcPathMap)
33 : super(srcPathMap);
20 34
21 @override 35 @override
22 Operation convert(String line) { 36 Operation convert(String line) {
37 List<String> fields;
23 try { 38 try {
24 List<String> fields = _parseFields(line); 39 fields = _parseFields(line);
25 if (fields.length < 2) { 40 if (fields.length < 2) {
26 //return new InfoOperation('Ignored line:\n $line'); 41 if (readBuffer != null) {
27 return null; 42 readBuffer.writeln(fields.length == 1 ? fields[0] : '');
43 return null;
44 }
45 throw 'Failed to process line:\n$line';
28 } 46 }
29 // int timeStamp = int.parse(fields[0], onError: (_) => -1); 47 if (readBuffer != null) {
30 String opCode = fields[1]; 48 readBuffer = null;
31 if (opCode == 'Req') {
32 return convertRequest(line, fields);
33 } 49 }
34 if (opCode == 'Noti') { 50 } catch (e, s) {
35 return convertNotification(fields); 51 throw new AnalysisException(
36 } 52 'Failed to parse line\n$line', new CaughtException(e, s));
37 if (opCode == 'Ver') { 53 }
38 // 1433195174666:Ver:1421765742287333878467:org.dartlang.dartplugin:0.0. 0:1.7.0:1.11.0-edge.131698 54 // int timeStamp = int.parse(fields[0], onError: (_) => -1);
39 return new StartServerOperation(); 55 String opCode = fields[1];
40 } 56 if (opCode == InstrumentationService.TAG_NOTIFICATION) {
41 if (_codesSeen.add(opCode)) { 57 return convertNotification(decodeJson(line, fields[2]));
42 logger.log(Level.INFO, 'Ignored op code: $opCode\n $line'); 58 } else if (opCode == 'Read') {
43 } 59 // 1434096943209:Read:/some/file/path:1434095535000:<file content>
60 //String filePath = fields[2];
61 readBuffer = new StringBuffer(fields.length > 4 ? fields[4] : '');
44 return null; 62 return null;
63 } else if (opCode == InstrumentationService.TAG_REQUEST) {
64 return convertRequest(decodeJson(line, fields[2]));
65 } else if (opCode == InstrumentationService.TAG_RESPONSE) {
66 // 1434096937454:Res:{"id"::"0","result"::{"version"::"1.7.0"}}
67 recordResponse(decodeJson(line, fields[2]));
68 return null;
69 } else if (opCode == InstrumentationService.TAG_ANALYSIS_TASK) {
70 // 1434096943208:Task:/Users/
71 return null;
72 } else if (opCode == InstrumentationService.TAG_LOG_ENTRY) {
73 // 1434096937454:Res:{"id"::"0","result"::{"version"::"1.7.0"}}
74 return null;
75 } else if (opCode == InstrumentationService.TAG_PERFORMANCE) {
76 //1434096960092:Perf:analysis_full:16884:context_id=0
77 return null;
78 } else if (opCode == InstrumentationService.TAG_SUBPROCESS_START) {
79 // 1434096938634:SPStart:0:/Users/da
80 return null;
81 } else if (opCode == InstrumentationService.TAG_SUBPROCESS_RESULT) {
82 // 1434096939068:SPResult:0:0:"{\"packages\"::{\"rpi_lidar\"::\"/Users
83 return null;
84 } else if (opCode == InstrumentationService.TAG_VERSION) {
85 // 1434096937358:Ver:1421765742287333878467:org.dartlang.dartplugin
86 return null;
87 } else if (opCode == InstrumentationService.TAG_WATCH_EVENT) {
88 // 1434097460414:Watch:/some/file/path
89 return null;
90 }
91 if (codesSeen.add(opCode)) {
92 logger.log(
93 Level.WARNING, 'Ignored instrumentation op code: $opCode\n $line');
94 }
95 return null;
96 }
97
98 Map<String, dynamic> decodeJson(String line, String text) {
99 try {
100 return JSON.decode(text);
45 } catch (e, s) { 101 } catch (e, s) {
46 throw 'Failed to parse line\n $line\n$e\n$s'; 102 throw new AnalysisException(
103 'Failed to decode JSON: $text\n$line', new CaughtException(e, s));
47 } 104 }
48 } 105 }
49 106
50 /** 107 /**
51 * Return an operation for the notification defined by [line] and [fields]
52 * or `null` if none.
53 */
54 Operation convertNotification(List<String> fields) {
55 //1433344448533:Noti:{"event"::"server.status","params"::{"analysis"::{"isAn alyzing"::false}}}
56 Map<String, dynamic> json = JSON.decode(fields[2]);
57 String event = json['event'];
58 if (event == 'server.status') {
59 Map<String, dynamic> params = json['params'];
60 if (params != null) {
61 Map<String, dynamic> analysis = params['analysis'];
62 if (analysis != null && analysis['isAnalyzing'] == false) {
63 return new WaitForAnalysisCompleteOperation();
64 }
65 }
66 }
67 if (event == 'server.connected') {
68 // Handled by the driver
69 return null;
70 }
71 if (_eventsSeen.add(event)) {
72 logger.log(Level.INFO, 'Ignored notification: $event');
73 }
74 return null;
75 }
76
77 /**
78 * Return an operation for the request defined by [line] and [fields]
79 * or `null` if none.
80 */
81 Operation convertRequest(String line, List<String> fields) {
82 Map<String, dynamic> json = JSON.decode(fields[2]);
83 String method = json['method'];
84 if (method == 'analysis.setAnalysisRoots') {
85 // 1433343174749:Req:{"id"::"3","method"::"analysis.setAnalysisRoots","par ams"::{"included"::["/usr/local/google/home/danrubel/work/git/dart_sdk/sdk/pkg/a nalysis_server","/usr/local/google/home/danrubel/work/git/dart_sdk/sdk/pkg/analy zer"],"excluded"::[],"packageRoots"::{}},"clientRequestTime"::1433343174702}
86 return new RequestOperation(json);
87 }
88 if (method == 'server.setSubscriptions') {
89 // 1433343174741:Req:{"id"::"1","method"::"server.setSubscriptions","param s"::{"subscriptions"::["STATUS"]},"clientRequestTime"::1433343172679}
90 return new RequestOperation(json);
91 }
92 if (_methodsSeen.add(method)) {
93 logger.log(Level.INFO, 'Ignored request: $method\n $line');
94 }
95 return null;
96 }
97
98 /**
99 * Determine if the given line is from an instrumentation file. 108 * Determine if the given line is from an instrumentation file.
100 * For example: 109 * For example:
101 * `1433175833005:Ver:1421765742287333878467:org.dartlang.dartplugin:0.0.0:1.6 .2:1.11.0-edge.131698` 110 * `1433175833005:Ver:1421765742287333878467:org.dartlang.dartplugin:0.0.0:1.6 .2:1.11.0-edge.131698`
102 */ 111 */
103 static bool isFormat(String line) { 112 static bool isFormat(String line) {
104 List<String> fields = _parseFields(line); 113 List<String> fields = _parseFields(line);
114 if (fields.length < 2) return false;
105 int timeStamp = int.parse(fields[0], onError: (_) => -1); 115 int timeStamp = int.parse(fields[0], onError: (_) => -1);
106 String opCode = fields[1]; 116 String opCode = fields[1];
107 return timeStamp > 0 && opCode == 'Ver'; 117 return timeStamp > 0 && opCode == 'Ver';
108 } 118 }
109 119
110 /** 120 /**
111 * Extract fields from the given [line]. 121 * Extract fields from the given [line].
112 */ 122 */
113 static List<String> _parseFields(String line) { 123 static List<String> _parseFields(String line) {
114 List<String> fields = new List<String>(); 124 List<String> fields = new List<String>();
(...skipping 15 matching lines...) Expand all
130 sb.writeCharCode(code); 140 sb.writeCharCode(code);
131 } 141 }
132 ++index; 142 ++index;
133 } 143 }
134 if (sb.isNotEmpty) { 144 if (sb.isNotEmpty) {
135 fields.add(sb.toString()); 145 fields.add(sb.toString());
136 } 146 }
137 return fields; 147 return fields;
138 } 148 }
139 } 149 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/performance/input_converter.dart ('k') | pkg/analysis_server/test/performance/local_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698