Skip to content
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

trace_events: add traced_value.cc/traced_value.h #21475

Closed
wants to merge 5 commits into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Jun 22, 2018

Port of the V8 internal v8::tracing::TracedValue that allows
structured data to be included in the trace event. The v8 class
is not exported in the public API so we cannot use it directly.

This is a simplified and slightly modified port. This commit only
adds the class, it does not add uses of it. Those will come in
separate PRs/commits.

This will be used to include more complex data structures within
various trace events.

/cc @ofrobots @eugeneo @nodejs/diagnostics @nodejs/trace-events

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@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. labels Jun 22, 2018
@jasnell
Copy link
Member Author

jasnell commented Jun 22, 2018

@jasnell
Copy link
Member Author

jasnell commented Jun 29, 2018

ping @nodejs/diagnostics

void WriteName(const char* name);

std::string data_;
bool first_item_;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not following how this is being used, and how its value is correct after a call sequence like BeginArray, BeginDictionary, EndDictionary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look within the WriteComma function for use (https://github.com/nodejs/node/pull/21475/files#diff-7e8d44b3c53ea475e1b34c59578ed6e8R169) ...

The original implementation in V8 has DCHECK statements that are only enabled in debug builds that check for proper state. I pulled those to keep things simple but could add them back in as regular CHECKs

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise LGTM, but it’s hard to give feedback about the API itself without knowing how this is going to end up being used ;)


namespace {

void EscapeAndAppendString(const char* value, std::string* result) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It would be nicer to return a std::string instead of making result an in/out parameter, tbh…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I adopted this directly from the v8 impl. If it's ok to diverge then I can change

std::ostringstream stream;
stream.imbue(std::locale("C")); // Ignore locale
stream << v;
return stream.str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does return std::to_string(v); do the trick here too, for the default case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, the challenge with std::to_string(v) is that it ignores any reasonable precision on the double and always prints six decimals, whereas the version used here will print with actual scientific notation (e.g. std::to_string(v) when v = 1.23e7, will print 12300000.000000 whereas the version used here will print 1.23e+07 as one would more reasonably expect.

void TracedValue::AppendAsTraceFormat(std::string* out) const {
*out += root_is_array_ ? '[' : '{';
*out += data_;
*out += root_is_array_ ? ']' : '}';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, seems like it might be nicer to make out a return value rather than an in/out parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the v8 trace event API and really isn't under our control, unfortunately.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test that verifies that it escape strings correctly? JSON a few special chars, as well as UTF-8.

Port of the V8 internal v8::tracing::TracedValue that allows
structured data to be included in the trace event. The v8 class
is not exported in the public API so we cannot use it directly.

This is a simplified and slightly modified port. This commit only
adds the class, it does not add uses of it. Those will come in
separate PRs/commits.
@jasnell
Copy link
Member Author

jasnell commented Jul 11, 2018

@mcollina ... Neither this nor the internal V8 version of TracedValue support proper escaping of UTF8 characters yet. I can update so that it does properly escape but that would mean further variance from the internal V8 version (which really shouldn't be a problem).

@jasnell
Copy link
Member Author

jasnell commented Jul 11, 2018

@mcollina @addaleax ... PTAL, I've updated the escaping to properly handle UTF8 characters, added the requested escaping test, and made a couple other minor improvements.

@jasnell
Copy link
Member Author

jasnell commented Jul 11, 2018

@jasnell
Copy link
Member Author

jasnell commented Jul 11, 2018

@addaleax ... to give you a better idea about how this is going to be used... here's an example

auto traced_value = TracedValue::Create();
traced_value->SetString("abc", "xyz");
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("cat", "name", 1, "data", traced_value);

Within the trace event log, the traced_value will be serialized as additional JSON payload as the value of the data argument. What this allows us to do is provide complex structured and nested data within the trace event as opposed to simple primitives. One example of this will be trace events for http and http2, which will optionally include detailed information about the session, the headers, etc.

@jasnell
Copy link
Member Author

jasnell commented Jul 12, 2018

Related failures in Windows and a couple others... trying again: https://ci.nodejs.org/job/node-test-pull-request/15819/

New run on Windows failed early for some reason... trying again on that platform: https://ci.nodejs.org/job/node-test-commit-windows-fanned/19232/

@jasnell
Copy link
Member Author

jasnell commented Jul 12, 2018

@nodejs/build ... Windows CI is failing with an odd one...


[git-rebase] $ /bin/sh -xe /tmp/jenkins6120436250089634014.sh
+ git checkout -B jenkins-node-test-commit-windows-fanned-19232
Switched to a new branch 'jenkins-node-test-commit-windows-fanned-19232'
+ grep -q ^147.75.70.237 /home/iojs/.ssh/known_hosts
+ git push binary_tmp@147.75.70.237:binary_tmp.git +jenkins-node-test-commit-windows-fanned-19232
ssh: connect to host 147.75.70.237 port 22: Connection timed out
fatal: Could not read from remote repository.

@Trott
Copy link
Member

Trott commented Jul 12, 2018

Unfortunately, for windows-fanned jobs, "Resume Build" does not work. (I don't know if this is something Build WG can fix or not.) So for that, you need to use Rebuild on the windows-fanned job itself instead.

Regardless, it looks like you've pushed two commits since the last full CI run (if GitHub's interface isn't misleading me somehow) so a full CI run is in order. EDIT: Indeed I am mistaken.

CI: https://ci.nodejs.org/job/node-test-pull-request/15821/

@Trott
Copy link
Member

Trott commented Jul 12, 2018

Hmm...lots of stuff failing very fast. Something odd is up...

@Trott
Copy link
Member

Trott commented Jul 12, 2018

Ah, the problem might be test-softlayer-ubuntu1604-x64-1 which builds for a few different tasks. I'll see if someone is around on #node-build who might know how to investigate/fix.

@jasnell
Copy link
Member Author

jasnell commented Jul 12, 2018

@Trott ... I was not using "Resume Build". When adding new commits, I always start a full CI run.

@jasnell
Copy link
Member Author

jasnell commented Jul 12, 2018

@jasnell
Copy link
Member Author

jasnell commented Jul 12, 2018

woo... green CI.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

jasnell added a commit that referenced this pull request Jul 12, 2018
Port of the V8 internal v8::tracing::TracedValue that allows
structured data to be included in the trace event. The v8 class
is not exported in the public API so we cannot use it directly.

This is a simplified and slightly modified port. This commit only
adds the class, it does not add uses of it. Those will come in
separate PRs/commits.

PR-URL: #21475
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@jasnell
Copy link
Member Author

jasnell commented Jul 12, 2018

Landed in d85449d

@jasnell jasnell closed this Jul 12, 2018
targos pushed a commit that referenced this pull request Jul 14, 2018
Port of the V8 internal v8::tracing::TracedValue that allows
structured data to be included in the trace event. The v8 class
is not exported in the public API so we cannot use it directly.

This is a simplified and slightly modified port. This commit only
adds the class, it does not add uses of it. Those will come in
separate PRs/commits.

PR-URL: #21475
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@targos targos mentioned this pull request Jul 17, 2018
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants