[vm/timeline] Include callback data into Dart_TimelineRecorderEvent.

This simplifies embedders which otherwise need to maintain
special mappings to find their isolate specific data structures.

TEST=vm/cc/DartAPI_SetTimelineRecorderCallback

Change-Id: If819437cad2e1bf3fe5ba50fe67d01e8bd992064
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304962
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
This commit is contained in:
Vyacheslav Egorov
2023-05-25 10:19:48 +00:00
committed by Commit Queue
parent 192d601521
commit f86f41226d
5 changed files with 37 additions and 4 deletions
+7 -1
View File
@@ -389,7 +389,7 @@ typedef struct {
const char* value;
} Dart_TimelineRecorderEvent_Argument;
#define DART_TIMELINE_RECORDER_CURRENT_VERSION (0x00000001)
#define DART_TIMELINE_RECORDER_CURRENT_VERSION (0x00000002)
typedef struct {
/* Set to DART_TIMELINE_RECORDER_CURRENT_VERSION */
@@ -416,6 +416,12 @@ typedef struct {
* isolate group. */
Dart_IsolateGroupId isolate_group;
/* The callback data associated with the isolate if any. */
void* isolate_data;
/* The callback data associated with the isolate group if any. */
void* isolate_group_data;
/* The name / label of the event. */
const char* label;
+6
View File
@@ -679,6 +679,10 @@ void TimelineEvent::Init(EventType event_type, const char* label) {
auto isolate_group = thread != nullptr ? thread->isolate_group() : nullptr;
isolate_id_ = (isolate != nullptr) ? isolate->main_port() : ILLEGAL_PORT;
isolate_group_id_ = (isolate_group != nullptr) ? isolate_group->id() : 0;
isolate_data_ =
(isolate != nullptr) ? isolate->init_callback_data() : nullptr;
isolate_group_data_ =
(isolate_group != nullptr) ? isolate_group->embedder_data() : nullptr;
label_ = label;
arguments_.Free();
set_event_type(event_type);
@@ -1929,6 +1933,8 @@ void TimelineEventEmbedderCallbackRecorder::OnEvent(TimelineEvent* event) {
recorder_event.timestamp1_or_async_id = event->timestamp1();
recorder_event.isolate = event->isolate_id();
recorder_event.isolate_group = event->isolate_group_id();
recorder_event.isolate_data = event->isolate_data();
recorder_event.isolate_group_data = event->isolate_group_data();
recorder_event.label = event->label();
recorder_event.stream = event->stream()->name();
recorder_event.argument_count = event->GetNumArguments();
+6
View File
@@ -474,6 +474,10 @@ class TimelineEvent {
uint64_t isolate_group_id() const { return isolate_group_id_; }
void* isolate_data() const { return isolate_data_; }
void* isolate_group_data() const { return isolate_group_data_; }
const char* label() const { return label_; }
// Does this duration end before |micros| ?
@@ -597,6 +601,8 @@ class TimelineEvent {
ThreadId thread_;
Dart_Port isolate_id_;
uint64_t isolate_group_id_;
void* isolate_data_;
void* isolate_group_data_;
TimelineEvent* next_;
friend class TimelineEventRecorder;
+14 -1
View File
@@ -448,6 +448,8 @@ static Dart_Port expected_isolate;
static Dart_IsolateGroupId expected_isolate_group;
static bool saw_begin;
static bool saw_end;
static void* expected_isolate_data;
static void* expected_isolate_group_data;
static void TestTimelineRecorderCallback(Dart_TimelineRecorderEvent* event) {
EXPECT_EQ(DART_TIMELINE_RECORDER_CURRENT_VERSION, event->version);
@@ -458,6 +460,8 @@ static void TestTimelineRecorderCallback(Dart_TimelineRecorderEvent* event) {
EXPECT_NE(0, event->timestamp0);
EXPECT_EQ(expected_isolate, event->isolate);
EXPECT_EQ(expected_isolate_group, event->isolate_group);
EXPECT_EQ(expected_isolate_data, event->isolate_data);
EXPECT_EQ(expected_isolate_group_data, event->isolate_group_data);
EXPECT_STREQ("Dart", event->stream);
EXPECT_EQ(1, event->argument_count);
EXPECT_STREQ("Dart Arguments", event->arguments[0].name);
@@ -470,6 +474,8 @@ static void TestTimelineRecorderCallback(Dart_TimelineRecorderEvent* event) {
EXPECT_NE(0, event->timestamp0);
EXPECT_EQ(expected_isolate, event->isolate);
EXPECT_EQ(expected_isolate_group, event->isolate_group);
EXPECT_EQ(expected_isolate_data, event->isolate_data);
EXPECT_EQ(expected_isolate_group_data, event->isolate_group_data);
EXPECT_STREQ("Dart", event->stream);
EXPECT_EQ(1, event->argument_count);
EXPECT_STREQ("Dart Arguments", event->arguments[0].name);
@@ -498,9 +504,13 @@ UNIT_TEST_CASE(DartAPI_SetTimelineRecorderCallback) {
params.cleanup_group = TesterState::group_cleanup_callback;
params.start_kernel_isolate = true;
int64_t isolate_data = 0;
EXPECT(Dart_Initialize(&params) == nullptr);
{
TestIsolateScope scope;
// Note: run_vm_tests will create and attach an instance of
// bin::IsolateGroupData to the newly created isolate group.
TestIsolateScope scope(/*isolate_group_data=*/nullptr, &isolate_data);
const char* kScriptChars =
"import 'dart:developer';\n"
"main() {\n"
@@ -514,6 +524,9 @@ UNIT_TEST_CASE(DartAPI_SetTimelineRecorderCallback) {
EXPECT_NE(ILLEGAL_PORT, expected_isolate);
expected_isolate_group = Dart_CurrentIsolateGroupId();
EXPECT_NE(ILLEGAL_PORT, expected_isolate_group);
expected_isolate_data = &isolate_data;
EXPECT_EQ(expected_isolate_data, Dart_CurrentIsolateData());
expected_isolate_group_data = Dart_CurrentIsolateGroupData();
saw_begin = false;
saw_end = false;
+4 -2
View File
@@ -464,8 +464,10 @@ class RawTestCase : TestCaseBase {
class TestIsolateScope {
public:
TestIsolateScope() {
isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate());
TestIsolateScope(void* isolate_group_data = nullptr,
void* isolate_data = nullptr) {
isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate(
/*name=*/nullptr, isolate_group_data, isolate_data));
Dart_EnterScope(); // Create a Dart API scope for unit tests.
}
~TestIsolateScope() {