Skip to content

Commit 1ab217a

Browse files
rmacnak-googleCommit Bot
authored and
Commit Bot
committed
Reland "[vm] Forward dynamic events names to os_signposts as arguments."
Assume the embedder provides static strings for event labels. TEST=Instruments Bug: #49178 Change-Id: I40aa4996fed2b1230da64d182e6f172f60480fdf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251145 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent d8d8403 commit 1ab217a

File tree

6 files changed

+70
-57
lines changed

6 files changed

+70
-57
lines changed

runtime/vm/dart_api_impl_test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9553,8 +9553,7 @@ TEST_CASE(DartAPI_TimelineCategories) {
95539553
JSONArray jstream(&obj, "available");
95549554
Timeline::PrintFlagsToJSONArray(&jstream);
95559555
const char* js_str = js.ToCString();
9556-
#define TIMELINE_STREAM_CHECK(name, fuchsia_name) \
9557-
EXPECT_SUBSTRING(#name, js_str);
9556+
#define TIMELINE_STREAM_CHECK(name, ...) EXPECT_SUBSTRING(#name, js_str);
95589557
TIMELINE_STREAM_LIST(TIMELINE_STREAM_CHECK)
95599558
#undef TIMELINE_STREAM_CHECK
95609559
}

runtime/vm/service.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class EnumListParameter : public MethodParameter {
296296
#if defined(SUPPORT_TIMELINE)
297297
static const char* const timeline_streams_enum_names[] = {
298298
"all",
299-
#define DEFINE_NAME(name, unused) #name,
299+
#define DEFINE_NAME(name, ...) #name,
300300
TIMELINE_STREAM_LIST(DEFINE_NAME)
301301
#undef DEFINE_NAME
302302
NULL};
@@ -328,7 +328,7 @@ bool Service::EnableTimelineStreams(char* categories_list) {
328328
return false;
329329
}
330330

331-
#define SET_ENABLE_STREAM(name, unused) \
331+
#define SET_ENABLE_STREAM(name, ...) \
332332
Timeline::SetStream##name##Enabled(HasStream(streams, #name));
333333
TIMELINE_STREAM_LIST(SET_ENABLE_STREAM);
334334
#undef SET_ENABLE_STREAM

runtime/vm/timeline.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void Timeline::Init() {
202202
ASSERT(recorder_ != NULL);
203203
enabled_streams_ = GetEnabledByDefaultTimelineStreams();
204204
// Global overrides.
205-
#define TIMELINE_STREAM_FLAG_DEFAULT(name, fuchsia_name) \
205+
#define TIMELINE_STREAM_FLAG_DEFAULT(name, ...) \
206206
stream_##name##_.set_enabled(HasStream(enabled_streams_, #name));
207207
TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAG_DEFAULT)
208208
#undef TIMELINE_STREAM_FLAG_DEFAULT
@@ -218,7 +218,7 @@ void Timeline::Cleanup() {
218218
#endif
219219

220220
// Disable global streams.
221-
#define TIMELINE_STREAM_DISABLE(name, fuchsia_name) \
221+
#define TIMELINE_STREAM_DISABLE(name, ...) \
222222
Timeline::stream_##name##_.set_enabled(false);
223223
TIMELINE_STREAM_LIST(TIMELINE_STREAM_DISABLE)
224224
#undef TIMELINE_STREAM_DISABLE
@@ -265,7 +265,7 @@ void Timeline::ReclaimCachedBlocksFromThreadsUnsafe() {
265265

266266
#ifndef PRODUCT
267267
void Timeline::PrintFlagsToJSONArray(JSONArray* arr) {
268-
#define ADD_RECORDED_STREAM_NAME(name, fuchsia_name) \
268+
#define ADD_RECORDED_STREAM_NAME(name, ...) \
269269
if (stream_##name##_.enabled()) { \
270270
arr->AddValue(#name); \
271271
}
@@ -285,13 +285,13 @@ void Timeline::PrintFlagsToJSON(JSONStream* js) {
285285
}
286286
{
287287
JSONArray availableStreams(&obj, "availableStreams");
288-
#define ADD_STREAM_NAME(name, fuchsia_name) availableStreams.AddValue(#name);
288+
#define ADD_STREAM_NAME(name, ...) availableStreams.AddValue(#name);
289289
TIMELINE_STREAM_LIST(ADD_STREAM_NAME);
290290
#undef ADD_STREAM_NAME
291291
}
292292
{
293293
JSONArray recordedStreams(&obj, "recordedStreams");
294-
#define ADD_RECORDED_STREAM_NAME(name, fuchsia_name) \
294+
#define ADD_RECORDED_STREAM_NAME(name, ...) \
295295
if (stream_##name##_.enabled()) { \
296296
recordedStreams.AddValue(#name); \
297297
}
@@ -402,8 +402,9 @@ TimelineEventRecorder* Timeline::recorder_ = NULL;
402402
MallocGrowableArray<char*>* Timeline::enabled_streams_ = NULL;
403403
bool Timeline::recorder_discards_clock_values_ = false;
404404

405-
#define TIMELINE_STREAM_DEFINE(name, fuchsia_name) \
406-
TimelineStream Timeline::stream_##name##_(#name, fuchsia_name, false);
405+
#define TIMELINE_STREAM_DEFINE(name, fuchsia_name, static_labels) \
406+
TimelineStream Timeline::stream_##name##_(#name, fuchsia_name, \
407+
static_labels, false);
407408
TIMELINE_STREAM_LIST(TIMELINE_STREAM_DEFINE)
408409
#undef TIMELINE_STREAM_DEFINE
409410

@@ -774,6 +775,7 @@ int64_t TimelineEvent::ThreadCPUTimeDuration() const {
774775

775776
TimelineStream::TimelineStream(const char* name,
776777
const char* fuchsia_name,
778+
bool has_static_labels,
777779
bool enabled)
778780
: name_(name),
779781
fuchsia_name_(fuchsia_name),
@@ -786,6 +788,7 @@ TimelineStream::TimelineStream(const char* name,
786788
#if defined(DART_HOST_OS_MACOS)
787789
if (__builtin_available(iOS 12.0, macOS 10.14, *)) {
788790
macos_log_ = os_log_create("Dart", name);
791+
has_static_labels_ = has_static_labels;
789792
}
790793
#endif
791794
}

runtime/vm/timeline.h

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,26 @@ class Zone;
5757
#define STARTUP_RECORDER_NAME "Startup"
5858
#define SYSTRACE_RECORDER_NAME "Systrace"
5959

60-
// (name, fuchsia_name).
60+
// (name, fuchsia_name, has_static_labels).
6161
#define TIMELINE_STREAM_LIST(V) \
62-
V(API, "dart:api") \
63-
V(Compiler, "dart:compiler") \
64-
V(CompilerVerbose, "dart:compiler.verbose") \
65-
V(Dart, "dart:dart") \
66-
V(Debugger, "dart:debugger") \
67-
V(Embedder, "dart:embedder") \
68-
V(GC, "dart:gc") \
69-
V(Isolate, "dart:isolate") \
70-
V(VM, "dart:vm")
62+
V(API, "dart:api", true) \
63+
V(Compiler, "dart:compiler", true) \
64+
V(CompilerVerbose, "dart:compiler.verbose", true) \
65+
V(Dart, "dart:dart", false) \
66+
V(Debugger, "dart:debugger", true) \
67+
V(Embedder, "dart:embedder", true) \
68+
V(GC, "dart:gc", true) \
69+
V(Isolate, "dart:isolate", true) \
70+
V(VM, "dart:vm", true)
7171

7272
// A stream of timeline events. A stream has a name and can be enabled or
7373
// disabled (globally and per isolate).
7474
class TimelineStream {
7575
public:
76-
TimelineStream(const char* name, const char* fuchsia_name, bool enabled);
76+
TimelineStream(const char* name,
77+
const char* fuchsia_name,
78+
bool static_labels,
79+
bool enabled);
7780

7881
const char* name() const { return name_; }
7982
const char* fuchsia_name() const { return fuchsia_name_; }
@@ -105,7 +108,8 @@ class TimelineStream {
105108
#if defined(DART_HOST_OS_FUCHSIA)
106109
trace_site_t* trace_site() { return &trace_site_; }
107110
#elif defined(DART_HOST_OS_MACOS)
108-
os_log_t macos_log() { return macos_log_; }
111+
os_log_t macos_log() const { return macos_log_; }
112+
bool has_static_labels() const { return has_static_labels_; }
109113
#endif
110114

111115
private:
@@ -120,6 +124,7 @@ class TimelineStream {
120124
trace_site_t trace_site_ = {};
121125
#elif defined(DART_HOST_OS_MACOS)
122126
os_log_t macos_log_ = {};
127+
bool has_static_labels_ = false;
123128
#endif
124129
};
125130

@@ -196,12 +201,12 @@ class Timeline : public AllStatic {
196201
static void PrintFlagsToJSONArray(JSONArray* arr);
197202
#endif
198203

199-
#define TIMELINE_STREAM_ACCESSOR(name, fuchsia_name) \
204+
#define TIMELINE_STREAM_ACCESSOR(name, ...) \
200205
static TimelineStream* Get##name##Stream() { return &stream_##name##_; }
201206
TIMELINE_STREAM_LIST(TIMELINE_STREAM_ACCESSOR)
202207
#undef TIMELINE_STREAM_ACCESSOR
203208

204-
#define TIMELINE_STREAM_FLAGS(name, fuchsia_name) \
209+
#define TIMELINE_STREAM_FLAGS(name, ...) \
205210
static void SetStream##name##Enabled(bool enabled) { \
206211
stream_##name##_.set_enabled(enabled); \
207212
}
@@ -216,7 +221,7 @@ class Timeline : public AllStatic {
216221
static MallocGrowableArray<char*>* enabled_streams_;
217222
static bool recorder_discards_clock_values_;
218223

219-
#define TIMELINE_STREAM_DECLARE(name, fuchsia_name) \
224+
#define TIMELINE_STREAM_DECLARE(name, ...) \
220225
static TimelineStream stream_##name##_;
221226
TIMELINE_STREAM_LIST(TIMELINE_STREAM_DECLARE)
222227
#undef TIMELINE_STREAM_DECLARE

runtime/vm/timeline_macos.cc

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,45 @@ void TimelineEventMacosRecorder::OnEvent(TimelineEvent* event) {
3030
}
3131

3232
const char* label = event->label();
33+
bool is_static_label = event->stream_->has_static_labels();
3334
uint8_t _Alignas(16) buffer[64];
3435
buffer[0] = 0;
3536

3637
switch (event->event_type()) {
37-
case TimelineEvent::kInstant: {
38-
_os_signpost_emit_with_name_impl(&__dso_handle, log, OS_SIGNPOST_EVENT,
39-
OS_SIGNPOST_ID_EXCLUSIVE, label, "",
40-
buffer, sizeof(buffer));
38+
case TimelineEvent::kInstant:
39+
if (is_static_label) {
40+
_os_signpost_emit_with_name_impl(&__dso_handle, log, OS_SIGNPOST_EVENT,
41+
OS_SIGNPOST_ID_EXCLUSIVE, label, "",
42+
buffer, sizeof(buffer));
43+
} else {
44+
os_signpost_event_emit(log, OS_SIGNPOST_ID_EXCLUSIVE, "Event", "%s",
45+
label);
46+
}
4147
break;
42-
}
4348
case TimelineEvent::kBegin:
44-
case TimelineEvent::kAsyncBegin: {
45-
_os_signpost_emit_with_name_impl(&__dso_handle, log,
46-
OS_SIGNPOST_INTERVAL_BEGIN, event->Id(),
47-
label, "", buffer, sizeof(buffer));
49+
case TimelineEvent::kAsyncBegin:
50+
if (is_static_label) {
51+
_os_signpost_emit_with_name_impl(
52+
&__dso_handle, log, OS_SIGNPOST_INTERVAL_BEGIN, event->Id(), label,
53+
"", buffer, sizeof(buffer));
54+
} else {
55+
os_signpost_interval_begin(log, event->Id(), "Event", "%s", label);
56+
}
4857
break;
49-
}
5058
case TimelineEvent::kEnd:
51-
case TimelineEvent::kAsyncEnd: {
52-
_os_signpost_emit_with_name_impl(&__dso_handle, log,
53-
OS_SIGNPOST_INTERVAL_END, event->Id(),
54-
label, "", buffer, sizeof(buffer));
59+
case TimelineEvent::kAsyncEnd:
60+
if (is_static_label) {
61+
_os_signpost_emit_with_name_impl(&__dso_handle, log,
62+
OS_SIGNPOST_INTERVAL_END, event->Id(),
63+
label, "", buffer, sizeof(buffer));
64+
} else {
65+
os_signpost_interval_end(log, event->Id(), "Event");
66+
}
5567
break;
56-
}
57-
case TimelineEvent::kCounter: {
58-
const char* fmt = "%s";
59-
Utils::SNPrint(reinterpret_cast<char*>(buffer), sizeof(buffer), fmt,
60-
event->arguments()[0].value);
61-
_os_signpost_emit_with_name_impl(&__dso_handle, log, OS_SIGNPOST_EVENT,
62-
OS_SIGNPOST_ID_EXCLUSIVE, label, fmt,
63-
buffer, sizeof(buffer));
68+
case TimelineEvent::kCounter:
69+
os_signpost_event_emit(log, OS_SIGNPOST_ID_EXCLUSIVE, "Counter", "%s=%s",
70+
label, event->arguments()[0].value);
6471
break;
65-
}
6672
default:
6773
break;
6874
}

runtime/vm/timeline_test.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class TimelineTestHelper : public AllStatic {
105105

106106
TEST_CASE(TimelineEventIsValid) {
107107
// Create a test stream.
108-
TimelineStream stream("testStream", "testStream", true);
108+
TimelineStream stream("testStream", "testStream", false, true);
109109

110110
TimelineEvent event;
111111
TimelineTestHelper::SetStream(&event, &stream);
@@ -124,7 +124,7 @@ TEST_CASE(TimelineEventIsValid) {
124124

125125
TEST_CASE(TimelineEventDuration) {
126126
// Create a test stream.
127-
TimelineStream stream("testStream", "testStream", true);
127+
TimelineStream stream("testStream", "testStream", false, true);
128128

129129
// Create a test event.
130130
TimelineEvent event;
@@ -139,7 +139,7 @@ TEST_CASE(TimelineEventDuration) {
139139

140140
TEST_CASE(TimelineEventDurationPrintJSON) {
141141
// Create a test stream.
142-
TimelineStream stream("testStream", "testStream", true);
142+
TimelineStream stream("testStream", "testStream", false, true);
143143

144144
// Create a test event.
145145
TimelineEvent event;
@@ -169,7 +169,7 @@ TEST_CASE(TimelineEventPrintSystrace) {
169169
char buffer[kBufferLength];
170170

171171
// Create a test stream.
172-
TimelineStream stream("testStream", "testStream", true);
172+
TimelineStream stream("testStream", "testStream", false, true);
173173

174174
// Create a test event.
175175
TimelineEvent event;
@@ -213,7 +213,7 @@ TEST_CASE(TimelineEventPrintSystrace) {
213213

214214
TEST_CASE(TimelineEventArguments) {
215215
// Create a test stream.
216-
TimelineStream stream("testStream", "testStream", true);
216+
TimelineStream stream("testStream", "testStream", false, true);
217217

218218
// Create a test event.
219219
TimelineEvent event;
@@ -233,7 +233,7 @@ TEST_CASE(TimelineEventArguments) {
233233

234234
TEST_CASE(TimelineEventArgumentsPrintJSON) {
235235
// Create a test stream.
236-
TimelineStream stream("testStream", "testStream", true);
236+
TimelineStream stream("testStream", "testStream", false, true);
237237

238238
// Create a test event.
239239
TimelineEvent event;
@@ -296,7 +296,7 @@ TEST_CASE(TimelineEventCallbackRecorderBasic) {
296296
}
297297

298298
// Create a test stream.
299-
TimelineStream stream("testStream", "testStream", true);
299+
TimelineStream stream("testStream", "testStream", false, true);
300300

301301
TimelineEvent* event = NULL;
302302

@@ -341,7 +341,7 @@ TEST_CASE(TimelineEventCallbackRecorderBasic) {
341341
}
342342

343343
TEST_CASE(TimelineRingRecorderJSONOrder) {
344-
TimelineStream stream("testStream", "testStream", true);
344+
TimelineStream stream("testStream", "testStream", false, true);
345345

346346
TimelineEventRingRecorder* recorder =
347347
new TimelineEventRingRecorder(TimelineEventBlock::kBlockSize * 2);

0 commit comments

Comments
 (0)