-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Conversation
ping @nodejs/diagnostics |
void WriteName(const char* name); | ||
|
||
std::string data_; | ||
bool first_item_; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 CHECK
s
There was a problem hiding this 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 ;)
src/tracing/traced_value.cc
Outdated
|
||
namespace { | ||
|
||
void EscapeAndAppendString(const char* value, std::string* result) { |
There was a problem hiding this comment.
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…
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll double check
There was a problem hiding this comment.
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_ ? ']' : '}'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
98665ce
to
509a715
Compare
@mcollina ... Neither this nor the internal V8 version of |
@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 |
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/ |
@nodejs/build ... Windows CI is failing with an odd one...
|
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.
|
Hmm...lots of stuff failing very fast. Something odd is up... |
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. |
@Trott ... I was not using "Resume Build". When adding new commits, I always start a full CI run. |
woo... green CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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>
Landed in d85449d |
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>
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), orvcbuild test
(Windows) passes