Skip to content

Commit babefb8

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ VM / Service ] Added VMFlagUpdated event to VM stream
Fixes #37557 Change-Id: I129c60a4ac8f42e2f338e6bd15f7fa6fcfe7f54a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109721 Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Siva Annamalai <[email protected]>
1 parent b41b868 commit babefb8

File tree

9 files changed

+95
-15
lines changed

9 files changed

+95
-15
lines changed

runtime/observatory/lib/src/service/object.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,7 @@ Level _findLogLevel(int value) {
20872087
class ServiceEvent extends ServiceObject {
20882088
/// The possible 'kind' values.
20892089
static const kVMUpdate = 'VMUpdate';
2090+
static const kVMFlagUpdate = 'VMFlagUpdate';
20902091
static const kIsolateStart = 'IsolateStart';
20912092
static const kIsolateRunnable = 'IsolateRunnable';
20922093
static const kIsolateExit = 'IsolateExit';
@@ -2123,6 +2124,8 @@ class ServiceEvent extends ServiceObject {
21232124

21242125
String kind;
21252126
DateTime timestamp;
2127+
String flag;
2128+
String newValue;
21262129
List<M.Breakpoint> pauseBreakpoints;
21272130
Breakpoint breakpoint;
21282131
Frame topFrame;
@@ -2253,6 +2256,12 @@ class ServiceEvent extends ServiceObject {
22532256
if (map['alias'] != null) {
22542257
alias = map['alias'];
22552258
}
2259+
if (map['flag'] != null) {
2260+
flag = map['flag'];
2261+
}
2262+
if (map['new_value'] != null) {
2263+
newValue = map['new_value'];
2264+
}
22562265
}
22572266

22582267
String toString() {

runtime/observatory/tests/service/get_flag_list_rpc_test.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:async';
6+
57
import 'package:observatory/service_io.dart';
68
import 'package:unittest/unittest.dart';
79

@@ -74,12 +76,25 @@ var tests = <VMTest>[
7476
final kProfilePeriod = 'profile_period';
7577
final kValue = 100;
7678
expect(await getFlagValue(vm, kProfilePeriod), '1000');
77-
var params = {
79+
final params = {
7880
'name': '$kProfilePeriod',
7981
'value': '$kValue',
8082
};
81-
var result = await vm.invokeRpcNoUpgrade('setFlag', params);
83+
final completer = Completer();
84+
final stream = await vm.getEventStream(VM.kVMStream);
85+
var subscription;
86+
subscription = stream.listen((ServiceEvent event) {
87+
if (event.kind == ServiceEvent.kVMFlagUpdate) {
88+
expect(event.owner.type, 'VM');
89+
expect(event.flag, kProfilePeriod);
90+
expect(event.newValue, kValue.toString());
91+
subscription.cancel();
92+
completer.complete();
93+
}
94+
});
95+
final result = await vm.invokeRpcNoUpgrade('setFlag', params);
8296
expect(result['type'], equals('Success'));
97+
await completer.future;
8398
expect(await getFlagValue(vm, kProfilePeriod), kValue.toString());
8499
}
85100
];

runtime/observatory/tests/service/get_version_rpc_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var tests = <VMTest>[
1212
var result = await vm.invokeRpcNoUpgrade('getVersion', {});
1313
expect(result['type'], equals('Version'));
1414
expect(result['major'], equals(3));
15-
expect(result['minor'], equals(22));
15+
expect(result['minor'], equals(23));
1616
expect(result['_privateMajor'], equals(0));
1717
expect(result['_privateMinor'], equals(0));
1818
},

runtime/vm/service.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4708,6 +4708,12 @@ static bool SetFlag(Thread* thread, JSONStream* js) {
47084708
// to notify the ThreadInterrupter to pick up the change.
47094709
Profiler::UpdateSamplePeriod();
47104710
}
4711+
if (Service::vm_stream.enabled()) {
4712+
ServiceEvent event(NULL, ServiceEvent::kVMFlagUpdate);
4713+
event.set_flag_name(flag_name);
4714+
event.set_flag_new_value(flag_value);
4715+
Service::HandleEvent(&event);
4716+
}
47114717
return true;
47124718
} else {
47134719
JSONObject jsobj(js);

runtime/vm/service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace dart {
1616

1717
#define SERVICE_PROTOCOL_MAJOR_VERSION 3
18-
#define SERVICE_PROTOCOL_MINOR_VERSION 22
18+
#define SERVICE_PROTOCOL_MINOR_VERSION 23
1919

2020
class Array;
2121
class EmbedderServiceHandler;

runtime/vm/service/service.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Dart VM Service Protocol 3.22
1+
# Dart VM Service Protocol 3.23
22

33
> Please post feedback to the [observatory-discuss group][discuss-list]
44
5-
This document describes of _version 3.22_ of the Dart VM Service Protocol. This
5+
This document describes of _version 3.23_ of the Dart VM Service Protocol. This
66
protocol is used to communicate with a running Dart Virtual Machine.
77

88
To use the Service Protocol, start the VM with the *--observe* flag.
@@ -1080,7 +1080,7 @@ The _streamId_ parameter may have the following published values:
10801080

10811081
streamId | event types provided
10821082
-------- | -----------
1083-
VM | VMUpdate
1083+
VM | VMUpdate, VMFlagUpdate
10841084
Isolate | IsolateStart, IsolateRunnable, IsolateExit, IsolateUpdate, IsolateReload, ServiceExtensionAdded
10851085
Debug | PauseStart, PauseExit, PauseBreakpoint, PauseInterrupted, PauseException, PausePostRequest, Resume, BreakpointAdded, BreakpointResolved, BreakpointRemoved, Inspect, None
10861086
GC | GC
@@ -1513,13 +1513,13 @@ class Event extends Response {
15131513
// The isolate with which this event is associated.
15141514
//
15151515
// This is provided for all event kinds except for:
1516-
// VMUpdate
1516+
// VMUpdate, VMFlagUpdate
15171517
@Isolate isolate [optional];
15181518
15191519
// The vm with which this event is associated.
15201520
//
15211521
// This is provided for the event kind:
1522-
// VMUpdate
1522+
// VMUpdate, VMFlagUpdate
15231523
@VM vm [optional];
15241524
15251525
// The timestamp (in milliseconds since the epoch) associated with this event.
@@ -1635,6 +1635,18 @@ class Event extends Response {
16351635
// This is provided for the event kinds:
16361636
// ServiceRegistered
16371637
String alias [optional];
1638+
1639+
// The name of the changed flag.
1640+
//
1641+
// This is provided for the event kinds:
1642+
// VMFlagUpdate
1643+
String flag [optional];
1644+
1645+
// The new value of the changed flag.
1646+
//
1647+
// This is provided for the event kinds:
1648+
// VMFlagUpdate
1649+
String newValue [optional];
16381650
}
16391651
```
16401652

@@ -1652,6 +1664,9 @@ enum EventKind {
16521664
// to notify of changes to the VM debugging name via setVMName.
16531665
VMUpdate,
16541666
1667+
// Notification that a VM flag has been changed via the service protocol.
1668+
VMFlagUpdate,
1669+
16551670
// Notification that a new isolate has started.
16561671
IsolateStart,
16571672
@@ -3127,5 +3142,6 @@ version | comments
31273142
3.20 | Add 'getInstances' RPC and 'InstanceSet' object.
31283143
3.21 | Add 'getVMTimelineMicros' RPC and 'Timestamp' object.
31293144
3.22 | Add `registerService` RPC, `Service` stream, and `ServiceRegistered` and `ServiceUnregistered` event kinds.
3145+
3.23 | Add `VMFlagUpdate` event kind to the `VM` stream.
31303146

31313147
[discuss-list]: https://groups.google.com/a/dartlang.org/forum/#!forum/observatory-discuss

runtime/vm/service/service_dev.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Dart VM Service Protocol 3.23-dev
1+
# Dart VM Service Protocol 3.24-dev
22

33
> Please post feedback to the [observatory-discuss group][discuss-list]
44
5-
This document describes of _version 3.23-dev_ of the Dart VM Service Protocol. This
5+
This document describes of _version 3.24-dev_ of the Dart VM Service Protocol. This
66
protocol is used to communicate with a running Dart Virtual Machine.
77

88
To use the Service Protocol, start the VM with the *--observe* flag.
@@ -1080,7 +1080,7 @@ The _streamId_ parameter may have the following published values:
10801080

10811081
streamId | event types provided
10821082
-------- | -----------
1083-
VM | VMUpdate
1083+
VM | VMUpdate, VMFlagUpdate
10841084
Isolate | IsolateStart, IsolateRunnable, IsolateExit, IsolateUpdate, IsolateReload, ServiceExtensionAdded
10851085
Debug | PauseStart, PauseExit, PauseBreakpoint, PauseInterrupted, PauseException, PausePostRequest, Resume, BreakpointAdded, BreakpointResolved, BreakpointRemoved, Inspect, None
10861086
GC | GC
@@ -1513,13 +1513,13 @@ class Event extends Response {
15131513
// The isolate with which this event is associated.
15141514
//
15151515
// This is provided for all event kinds except for:
1516-
// VMUpdate
1516+
// VMUpdate, VMFlagUpdate
15171517
@Isolate isolate [optional];
15181518
15191519
// The vm with which this event is associated.
15201520
//
15211521
// This is provided for the event kind:
1522-
// VMUpdate
1522+
// VMUpdate, VMFlagUpdate
15231523
@VM vm [optional];
15241524
15251525
// The timestamp (in milliseconds since the epoch) associated with this event.
@@ -1635,6 +1635,18 @@ class Event extends Response {
16351635
// This is provided for the event kinds:
16361636
// ServiceRegistered
16371637
String alias [optional];
1638+
1639+
// The name of the changed flag.
1640+
//
1641+
// This is provided for the event kinds:
1642+
// VMFlagUpdate
1643+
String flag [optional];
1644+
1645+
// The new value of the changed flag.
1646+
//
1647+
// This is provided for the event kinds:
1648+
// VMFlagUpdate
1649+
String newValue [optional];
16381650
}
16391651
```
16401652

@@ -1652,6 +1664,9 @@ enum EventKind {
16521664
// to notify of changes to the VM debugging name via setVMName.
16531665
VMUpdate,
16541666
1667+
// Notification that a VM flag has been changed via the service protocol.
1668+
VMFlagUpdate,
1669+
16551670
// Notification that a new isolate has started.
16561671
IsolateStart,
16571672
@@ -3127,5 +3142,6 @@ version | comments
31273142
3.20 | Add 'getInstances' RPC and 'InstanceSet' object.
31283143
3.21 | Add 'getVMTimelineMicros' RPC and 'Timestamp' object.
31293144
3.22 | Add `registerService` RPC, `Service` stream, and `ServiceRegistered` and `ServiceUnregistered` event kinds.
3145+
3.23 | Add `VMFlagUpdate` event kind to the `VM` stream.
31303146

31313147
[discuss-list]: https://groups.google.com/a/dartlang.org/forum/#!forum/observatory-discuss

runtime/vm/service_event.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace dart {
1515
ServiceEvent::ServiceEvent(Isolate* isolate, EventKind event_kind)
1616
: isolate_(isolate),
1717
kind_(event_kind),
18+
flag_name_(NULL),
19+
flag_new_value_(NULL),
1820
embedder_kind_(NULL),
1921
embedder_stream_id_(NULL),
2022
breakpoint_(NULL),
@@ -52,6 +54,8 @@ const char* ServiceEvent::KindAsCString() const {
5254
switch (kind()) {
5355
case kVMUpdate:
5456
return "VMUpdate";
57+
case kVMFlagUpdate:
58+
return "VMFlagUpdate";
5559
case kIsolateStart:
5660
return "IsolateStart";
5761
case kIsolateRunnable:
@@ -113,6 +117,7 @@ const char* ServiceEvent::KindAsCString() const {
113117
const StreamInfo* ServiceEvent::stream_info() const {
114118
switch (kind()) {
115119
case kVMUpdate:
120+
case kVMFlagUpdate:
116121
return &Service::vm_stream;
117122

118123
case kIsolateStart:
@@ -173,6 +178,10 @@ const char* ServiceEvent::stream_id() const {
173178
void ServiceEvent::PrintJSON(JSONStream* js) const {
174179
JSONObject jsobj(js);
175180
PrintJSONHeader(&jsobj);
181+
if (kind() == kVMFlagUpdate) {
182+
jsobj.AddProperty("flag", flag_name());
183+
jsobj.AddProperty("new_value", flag_new_value());
184+
}
176185
if (kind() == kIsolateReload) {
177186
if (reload_error_ == NULL) {
178187
jsobj.AddProperty("status", "success");

runtime/vm/service_event.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class TimelineEventBlock;
2222
class ServiceEvent {
2323
public:
2424
enum EventKind {
25-
kVMUpdate, // VM identity information has changed
25+
kVMUpdate, // VM identity information has changed
26+
kVMFlagUpdate, // VM flags updated
2627

2728
kIsolateStart, // New isolate has started
2829
kIsolateRunnable, // Isolate is ready to run
@@ -98,6 +99,12 @@ class ServiceEvent {
9899
}
99100
}
100101

102+
const char* flag_name() const { return flag_name_; }
103+
void set_flag_name(const char* flag) { flag_name_ = flag; }
104+
105+
const char* flag_new_value() const { return flag_new_value_; }
106+
void set_flag_new_value(const char* value) { flag_new_value_ = value; }
107+
101108
const char* embedder_kind() const { return embedder_kind_; }
102109

103110
const char* KindAsCString() const;
@@ -214,6 +221,8 @@ class ServiceEvent {
214221
private:
215222
Isolate* isolate_;
216223
EventKind kind_;
224+
const char* flag_name_;
225+
const char* flag_new_value_;
217226
const char* embedder_kind_;
218227
const char* embedder_stream_id_;
219228
Breakpoint* breakpoint_;

0 commit comments

Comments
 (0)