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

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: 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
5 import 'package:logging/logging.dart'; 9 import 'package:logging/logging.dart';
6 10
11 import 'input_converter.dart';
7 import 'operation.dart'; 12 import 'operation.dart';
8 13
9 final int COLON = ':'.codeUnitAt(0); 14 final int COLON = ':'.codeUnitAt(0);
10 15
11 /** 16 /**
12 * [InstrumentationInputConverter] converts an instrumentation stream 17 * [InstrumentationInputConverter] converts an instrumentation stream
13 * into a series of operations to be sent to the analysis server. 18 * into a series of operations to be sent to the analysis server.
14 */ 19 */
15 class InstrumentationInputConverter extends Converter<String, Operation> { 20 class InstrumentationInputConverter extends CommonInputConverter {
16 final Logger logger = new Logger('InstrumentationInputConverter'); 21 final Set<String> codesSeen = new Set<String>();
17 final Set<String> _codesSeen = new Set<String>(); 22
18 final Set<String> _methodsSeen = new Set<String>(); 23 /**
19 final Set<String> _eventsSeen = new Set<String>(); 24 * [readBuffer] holds the contents of the file being read from disk
25 * as recorded in the instrumentation log
26 * or `null` if not converting a "Read" entry.
27 */
28 StringBuffer readBuffer = null;
29
30 InstrumentationInputConverter(Map<String, String> srcPathMap)
31 : super(srcPathMap);
20 32
21 @override 33 @override
22 Operation convert(String line) { 34 Operation convert(String line) {
35 List<String> fields;
23 try { 36 try {
24 List<String> fields = _parseFields(line); 37 fields = _parseFields(line);
25 if (fields.length < 2) { 38 if (fields.length < 2) {
26 //return new InfoOperation('Ignored line:\n $line'); 39 if (readBuffer != null) {
27 return null; 40 readBuffer.writeln(fields.length == 1 ? fields[0] : '');
41 return null;
42 }
43 throw 'Failed to process line:\n$line';
28 } 44 }
29 // int timeStamp = int.parse(fields[0], onError: (_) => -1); 45 if (readBuffer != null) {
30 String opCode = fields[1]; 46 readBuffer = null;
31 if (opCode == 'Req') {
32 return convertRequest(line, fields);
33 } 47 }
34 if (opCode == 'Noti') {
35 return convertNotification(fields);
36 }
37 if (opCode == 'Ver') {
38 // 1433195174666:Ver:1421765742287333878467:org.dartlang.dartplugin:0.0. 0:1.7.0:1.11.0-edge.131698
39 return new StartServerOperation();
40 }
41 if (_codesSeen.add(opCode)) {
42 logger.log(Level.INFO, 'Ignored op code: $opCode\n $line');
43 }
44 return null;
45 } catch (e, s) { 48 } catch (e, s) {
46 throw 'Failed to parse line\n $line\n$e\n$s'; 49 throw 'Failed to parse line\n $line\n$e\n$s';
47 } 50 }
51 // int timeStamp = int.parse(fields[0], onError: (_) => -1);
52 String opCode = fields[1];
53 if (opCode == 'Noti') {
Brian Wilkerson 2015/06/15 17:37:47 Use constants in InstrumentationService to protect
danrubel 2015/06/17 15:35:32 Good point. Done.
54 return convertNotification(decodeJson(line, fields[2]));
55 } else if (opCode == 'Read') {
56 // 1434096943209:Read:/some/file/path:1434095535000:<file content>
57 //String filePath = fields[2];
58 readBuffer = new StringBuffer(fields.length > 4 ? fields[4] : '');
59 return null;
60 } else if (opCode == 'Req') {
61 return convertRequest(decodeJson(line, fields[2]));
62 } else if (opCode == 'Res') {
63 // 1434096937454:Res:{"id"::"0","result"::{"version"::"1.7.0"}}
64 recordResponse(decodeJson(line, fields[2]));
65 return null;
66 } else if (opCode == 'Task') {
67 // 1434096943208:Task:/Users/
68 return null;
69 } else if (opCode == 'Log') {
70 // 1434096937454:Res:{"id"::"0","result"::{"version"::"1.7.0"}}
71 return null;
72 } else if (opCode == 'Perf') {
73 //1434096960092:Perf:analysis_full:16884:context_id=0
74 return null;
75 } else if (opCode == 'SPStart') {
76 // 1434096938634:SPStart:0:/Users/da
77 return null;
78 } else if (opCode == 'SPResult') {
79 // 1434096939068:SPResult:0:0:"{\"packages\"::{\"rpi_lidar\"::\"/Users
80 return null;
81 } else if (opCode == 'Ver') {
82 // 1434096937358:Ver:1421765742287333878467:org.dartlang.dartplugin
83 return null;
84 } else if (opCode == 'Watch') {
85 // 1434097460414:Watch:/some/file/path
86 return null;
87 }
88 if (codesSeen.add(opCode)) {
89 logger.log(Level.INFO, 'Ignored op code: $opCode\n $line');
90 throw 'Unhandled op code: $opCode in:\n$line';
91 }
92 return null;
93 }
94
95 Map<String, dynamic> decodeJson(String line, String text) {
96 try {
97 return JSON.decode(text);
98 } catch (e) {
99 throw 'Failed to decode JSON: $text\n $line';
100 }
48 } 101 }
49 102
50 /** 103 /**
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. 104 * Determine if the given line is from an instrumentation file.
100 * For example: 105 * For example:
101 * `1433175833005:Ver:1421765742287333878467:org.dartlang.dartplugin:0.0.0:1.6 .2:1.11.0-edge.131698` 106 * `1433175833005:Ver:1421765742287333878467:org.dartlang.dartplugin:0.0.0:1.6 .2:1.11.0-edge.131698`
102 */ 107 */
103 static bool isFormat(String line) { 108 static bool isFormat(String line) {
104 List<String> fields = _parseFields(line); 109 List<String> fields = _parseFields(line);
110 if (fields.length < 2) return false;
105 int timeStamp = int.parse(fields[0], onError: (_) => -1); 111 int timeStamp = int.parse(fields[0], onError: (_) => -1);
106 String opCode = fields[1]; 112 String opCode = fields[1];
107 return timeStamp > 0 && opCode == 'Ver'; 113 return timeStamp > 0 && opCode == 'Ver';
108 } 114 }
109 115
110 /** 116 /**
111 * Extract fields from the given [line]. 117 * Extract fields from the given [line].
112 */ 118 */
113 static List<String> _parseFields(String line) { 119 static List<String> _parseFields(String line) {
114 List<String> fields = new List<String>(); 120 List<String> fields = new List<String>();
(...skipping 15 matching lines...) Expand all
130 sb.writeCharCode(code); 136 sb.writeCharCode(code);
131 } 137 }
132 ++index; 138 ++index;
133 } 139 }
134 if (sb.isNotEmpty) { 140 if (sb.isNotEmpty) {
135 fields.add(sb.toString()); 141 fields.add(sb.toString());
136 } 142 }
137 return fields; 143 return fields;
138 } 144 }
139 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698