Skip to content

src: internalize v8::ConvertableToTraceFormat in traces #57866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Apr 13, 2025

v8::ConvertableToTraceFormat is only available in legacy V8 tracing
API and no longer supported in perfetto. This internalize
node::tracing::TracedValue and v8::ConvertableToTraceFormat by
defining specialized trace argument classes.

Using the new format in traces be like:

MyArgs traced_value(...);
TRACE_EVENT1("my_category", "event_name", "my_args", CastTracedValue(traced_value));

The newly defined structured trace argument classes can be easily
converted to perfetto::TracedValue by perfetto traced value protocol.
For example, when adding perfetto support, CastTracedValue will be a
no-op and these classes can add a new conversion method like:

class Foo {
  void WriteIntoTrace(TracedValue context) const {
    auto dict = std::move(context).WriteDictionary();
    dict->Add("key", 42);
    dict->Add("foo", "bar");
    dict->Add("member", member_);
  }
};

Refs: nodejs/diagnostics#654
Refs: https://github.com/google/perfetto/blob/9ddf987d48cdfd9129987a3af1e85052c377756f/include/perfetto/tracing/traced_value.h#L46

`v8::ConvertableToTraceFormat` is only available in legacy V8 tracing
API and no longer supported in perfetto. This internalize
`node::tracing::TracedValue` and `v8::ConvertableToTraceFormat` by
defining specialized trace argument classes.

The newly defined structured trace argument classes can be easily
converted to `perfetto::TracedValue` by perfetto traced value protocol.
For example, when adding perfetto support, `CastTracedValue` will be a
no-op and these classes can add a new conversion method like:

```cpp
class Foo {
  void WriteIntoTrace(TracedValue context) const {
    auto dict = std::move(context).WriteDictionary();
    dict->Add("key", 42);
    dict->Add("foo", "bar");
    dict->Add("member", member_);
  }
};
```
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 13, 2025
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 13, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 13, 2025
@nodejs-github-bot

This comment was marked as outdated.

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants