Add support for getting the sessionId from instrumentation and sending it to the client

R=scheglov@google.com

Review URL: https://codereview.chromium.org/2359233002 .
This commit is contained in:
Brian Wilkerson 2016-09-22 10:26:13 -07:00
parent 1e744f3dc2
commit 74686371b3
10 changed files with 78 additions and 14 deletions

View file

@ -356,6 +356,7 @@ a:focus, a:hover {
"params": {
"<b>version</b>": String
"<b>pid</b>": int
"<b>sessionId</b>": <span style="color:#999999">optional</span> String
}
}</pre></div>
<p>
@ -375,6 +376,9 @@ a:focus, a:hover {
</dd><dt class="field"><b>pid (int)</b></dt><dd>
<p>The process id of the analysis server process.</p>
</dd><dt class="field"><b>sessionId (<span style="color:#999999">optional</span> String)</b></dt><dd>
<p>The session id for this session.</p>
</dd></dl></dd><dt class="notification"><a name="notification_server.error">server.error</a> (<a href="#notification_server.error">#</a>)</dt><dd><div class="box"><pre>notification: {
"event": "server.error"
"params": {

View file

@ -267,6 +267,7 @@ class ServerSetSubscriptionsResult {
* {
* "version": String
* "pid": int
* "sessionId": optional String
* }
*
* Clients may not extend, implement or mix-in this class.
@ -276,6 +277,8 @@ class ServerConnectedParams implements HasToJson {
int _pid;
String _sessionId;
/**
* The version number of the analysis server.
*/
@ -302,9 +305,22 @@ class ServerConnectedParams implements HasToJson {
this._pid = value;
}
ServerConnectedParams(String version, int pid) {
/**
* The session id for this session.
*/
String get sessionId => _sessionId;
/**
* The session id for this session.
*/
void set sessionId(String value) {
this._sessionId = value;
}
ServerConnectedParams(String version, int pid, {String sessionId}) {
this.version = version;
this.pid = pid;
this.sessionId = sessionId;
}
factory ServerConnectedParams.fromJson(JsonDecoder jsonDecoder, String jsonPath, Object json) {
@ -324,7 +340,11 @@ class ServerConnectedParams implements HasToJson {
} else {
throw jsonDecoder.missingKey(jsonPath, "pid");
}
return new ServerConnectedParams(version, pid);
String sessionId;
if (json.containsKey("sessionId")) {
sessionId = jsonDecoder.decodeString(jsonPath + ".sessionId", json["sessionId"]);
}
return new ServerConnectedParams(version, pid, sessionId: sessionId);
} else {
throw jsonDecoder.mismatch(jsonPath, "server.connected params", json);
}
@ -339,6 +359,9 @@ class ServerConnectedParams implements HasToJson {
Map<String, dynamic> result = {};
result["version"] = version;
result["pid"] = pid;
if (sessionId != null) {
result["sessionId"] = sessionId;
}
return result;
}
@ -353,7 +376,8 @@ class ServerConnectedParams implements HasToJson {
bool operator==(other) {
if (other is ServerConnectedParams) {
return version == other.version &&
pid == other.pid;
pid == other.pid &&
sessionId == other.sessionId;
}
return false;
}
@ -363,6 +387,7 @@ class ServerConnectedParams implements HasToJson {
int hash = 0;
hash = JenkinsSmiHash.combine(hash, version.hashCode);
hash = JenkinsSmiHash.combine(hash, pid.hashCode);
hash = JenkinsSmiHash.combine(hash, sessionId.hashCode);
return JenkinsSmiHash.finish(hash);
}
}

View file

@ -376,8 +376,9 @@ class AnalysisServer {
_setupIndexInvalidation();
pubSummaryManager =
new PubSummaryManager(resourceProvider, '${io.pid}.temp');
Notification notification =
new ServerConnectedParams(VERSION, io.pid).toNotification();
Notification notification = new ServerConnectedParams(VERSION, io.pid,
sessionId: instrumentationService.sessionId)
.toNotification();
channel.sendNotification(notification);
channel.listen(handleRequest, onDone: done, onError: error);
handlers = serverPlugin.createDomains(this);

View file

@ -92,6 +92,10 @@ abstract class IntegrationTestMixin {
* pid (int)
*
* The process id of the analysis server process.
*
* sessionId (optional String)
*
* The session id for this session.
*/
Stream<ServerConnectedParams> onServerConnected;

View file

@ -66,12 +66,15 @@ final Matcher isServerSetSubscriptionsResult = isNull;
* {
* "version": String
* "pid": int
* "sessionId": optional String
* }
*/
final Matcher isServerConnectedParams = new LazyMatcher(() => new MatchesJsonObject(
"server.connected params", {
"version": isString,
"pid": isInt
}, optionalFields: {
"sessionId": isString
}));
/**

View file

@ -32,27 +32,31 @@ SCRIPT_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/../../../.." ; pwd -P)"
BIN_DIR="${ROOT_DIR}/sdk/bin"
if [ -z "$DART_CONFIGURATION" ];
if [[ $1 == '--arch' && $2 == 'x64' ]];
then
DART_CONFIGURATION="ReleaseX64"
elif [ -z "$DART_CONFIGURATION" ];
then
DART_CONFIGURATION="ReleaseIA32"
fi
if [[ `uname` == 'Darwin' ]];
then
BUILD_DIR="${ROOT_DIR}/xcodebuild/$DART_CONFIGURATION"
else
BUILD_DIR="${ROOT_DIR}/out/$DART_CONFIGURATION"
if [[ $GYP_GENERATORS == 'ninja' ]];
then
BUILD_DIR="${ROOT_DIR}/out/$DART_CONFIGURATION"
else
BUILD_DIR="${ROOT_DIR}/xcodebuild/$DART_CONFIGURATION"
fi
fi
PKG_DIR="${BUILD_DIR}/packages"
PKG_FILE="${ROOT_DIR}/pkg/analysis_server/.packages"
DART="${BIN_DIR}/dart"
DART="${BUILD_DIR}/dart-sdk/bin/dart"
declare -a VM_OPTIONS
VM_OPTIONS+=("--checked")
VM_OPTIONS+=("--package-root=${PKG_DIR}")
VM_OPTIONS+=("--packages=${PKG_FILE}")
cd "${SCRIPT_DIR}"
"${DART}" "${VM_OPTIONS[@]}" "generate_all.dart"

View file

@ -243,6 +243,10 @@
<ref>int</ref>
<p>The process id of the analysis server process.</p>
</field>
<field name="sessionId" optional="true">
<ref>String</ref>
<p>The session id for this session.</p>
</field>
</params>
</notification>
<notification event="error">

View file

@ -20,6 +20,9 @@ class FileInstrumentationServer implements InstrumentationServer {
_sink = file.openWrite();
}
@override
String get sessionId => '';
@override
void log(String message) {
_sink.writeln(message);

View file

@ -22,6 +22,11 @@ class AnalysisPerformanceKind {
* server.
*/
abstract class InstrumentationServer {
/**
* Return the identifier used to identify the current session.
*/
String get sessionId;
/**
* Pass the given [message] to the instrumentation server so that it will be
* logged with other messages.
@ -95,6 +100,11 @@ class InstrumentationService {
*/
bool get isActive => _instrumentationServer != null;
/**
* Return the identifier used to identify the current session.
*/
String get sessionId => _instrumentationServer?.sessionId ?? '';
/**
* The current time, expressed as a decimal encoded number of milliseconds.
*/
@ -356,6 +366,9 @@ class MulticastInstrumentationServer implements InstrumentationServer {
MulticastInstrumentationServer(this._servers);
@override
String get sessionId => _servers[0].sessionId;
@override
void log(String message) {
for (InstrumentationServer server in _servers) {

View file

@ -164,6 +164,9 @@ class TestInstrumentationServer implements InstrumentationServer {
StringBuffer normalChannel = new StringBuffer();
StringBuffer priorityChannel = new StringBuffer();
@override
String get sessionId => '';
@override
void log(String message) {
normalChannel.writeln(message);