{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/9304","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/9304/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/9304/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/9304/events","html_url":"https://github.com/nodejs/node/pull/9304","id":185540273,"number":9304,"title":"Trace event support for Node.js","user":{"login":"matthewloring","id":1485909,"avatar_url":"https://avatars.githubusercontent.com/u/1485909?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewloring","html_url":"https://github.com/matthewloring","followers_url":"https://api.github.com/users/matthewloring/followers","following_url":"https://api.github.com/users/matthewloring/following{/other_user}","gists_url":"https://api.github.com/users/matthewloring/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewloring/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewloring/subscriptions","organizations_url":"https://api.github.com/users/matthewloring/orgs","repos_url":"https://api.github.com/users/matthewloring/repos","events_url":"https://api.github.com/users/matthewloring/events{/privacy}","received_events_url":"https://api.github.com/users/matthewloring/received_events","type":"User","site_admin":false},"labels":[{"id":155267502,"url":"https://api.github.com/repos/nodejs/node/labels/c++","name":"c++","color":"e11d21","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":57,"created_at":"2016-10-26T23:53:35Z","updated_at":"2016-12-06T22:13:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/9304","html_url":"https://github.com/nodejs/node/pull/9304","diff_url":"https://github.com/nodejs/node/pull/9304.diff","patch_url":"https://github.com/nodejs/node/pull/9304.patch"},"body":"<!--\r\nThank you for your pull request. Please review below requirements.\r\n\r\nBug fixes and new features should include tests and possibly benchmarks.\r\n\r\nContributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n##### Checklist\r\n\r\n<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->\r\n- [x] `make -j8 test` (UNIX), or `vcbuild test nosign` (Windows) passes\r\n- [ ] documentation is changed or added\r\n- [ ] commit message follows commit guidelines\r\n##### Affected core subsystem(s)\r\n\r\n<!-- Provide affected core subsystem(s) (like doc, cluster, crypto, etc). -->\r\n\r\nsrc\r\n##### Description of change\r\n\r\n<!-- Provide a description of the change below this comment. -->\r\n\r\nBackground: https://github.com/nodejs/diagnostics/issues/30, https://github.com/nodejs/diagnostics/issues/53\r\n\r\nThis PR adds support for trace-event tracing to Node.js. It provides a mechanism to centralize tracing information generated by V8, Node core, and userspace code. The PR contains a few components:\r\n- A trace writer responsible for serializing traces and cycling the output files so that no individual file becomes to large.\r\n- A buffer for aggregating traces to allow for batched flushes.\r\n- An agent which initializes the tracing controller and ensures that trace serialization is done on a separate thread.\r\n- A set of macros for generating trace events.\r\n## Generating Trace Events\r\n\r\nThis PR introduces macros for recording trace events. Synchronous operations can be traced by wrapping them with the appropriate macros:\r\n\r\n``` C++\r\nTRACE_EVENT_BEGIN0(\"MY_CATEGORY\", \"SomethingCostly\")\r\ndoSomethingCostly()\r\nTRACE_EVENT_END0(\"MY_CATEGORY\", \"SomethingCostly\")\r\n```\r\n\r\nAsynchronous operations can be traced using:\r\n\r\n``` C++\r\nvoid StartAsyncOperation(int operation_id, ...) {\r\n  TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(\"category\", \"operation\", operation_id);\r\n  ...\r\n}\r\nvoid EndAsyncOperation(int operation_id, ...) {\r\n  TRACE_EVENT_NESTABLE_ASYNC_END0(\"category\", \"operation\", operation_id);\r\n  ...\r\n}\r\n```\r\n\r\nAn example of async traces can be seen below. The example was generated by integrating the above macros into Async-Wrap.\r\n\r\nAdditional examples as well as a complete list of trace macros can be found in `src/tracing/trace_event.h`. This PR does not introduce any JS interface for generating events or tracing of Node core with the hope that the community can determine how the instrumentation of core should be approached and how this functionality can be exposed to end users.\r\n## Viewing Trace Events\r\n\r\nThe current trace serialization outputs traces in a format that can be visualized by navigating to [`chrome://tracing`](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) in Chrome and loading a trace output file.\r\n\r\n![w85xe3osv1u](https://cloud.githubusercontent.com/assets/1485909/19749159/92196192-9b9b-11e6-803b-8c6273b12365.png)\r\n\r\nWe can zoom in on this visualization to view VM events alongside the opening and closing of TCP connections:\r\n\r\n![dsksrjkirjkirjkk69xc63ny39g3a3zhbdtmw4aaaaaelftksuqmcc](https://cloud.githubusercontent.com/assets/1485909/19749162/964acc56-9b9b-11e6-8ea5-f5d301e2f6fa.png)\r\n# Usage\r\n\r\nTracing can be enabled by running:\r\n\r\n```\r\nnode --trace-events-enabled server.js\r\n```\r\n\r\nBy default, this will record all events in the `\"v8\"` and `\"node\"` categories. To trace other categories or ignore either of these categories, use the `--trace-event-categories` flag:\r\n\r\n```\r\nnode --trace-events-enabled --trace-event-categories v8,custom-category server.js\r\n```\r\n\r\nThis PR is the result of a lot of hard work by @misterpoe, @kjin, @lpy, @fmeawad, and @ofrobots.\r\n\r\nThanks for the review!\r\n\r\n/cc @nodejs/diagnostics \r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/265289774","html_url":"https://github.com/nodejs/node/pull/9304#issuecomment-265289774","issue_url":"https://api.github.com/repos/nodejs/node/issues/9304","id":265289774,"user":{"login":"jasongin","id":13093042,"avatar_url":"https://avatars.githubusercontent.com/u/13093042?v=3","gravatar_id":"","url":"https://api.github.com/users/jasongin","html_url":"https://github.com/jasongin","followers_url":"https://api.github.com/users/jasongin/followers","following_url":"https://api.github.com/users/jasongin/following{/other_user}","gists_url":"https://api.github.com/users/jasongin/gists{/gist_id}","starred_url":"https://api.github.com/users/jasongin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasongin/subscriptions","organizations_url":"https://api.github.com/users/jasongin/orgs","repos_url":"https://api.github.com/users/jasongin/repos","events_url":"https://api.github.com/users/jasongin/events{/privacy}","received_events_url":"https://api.github.com/users/jasongin/received_events","type":"User","site_admin":false},"created_at":"2016-12-06T22:13:01Z","updated_at":"2016-12-06T22:13:01Z","body":"I patched my fork here (https://github.com/jasongin/nodejs/commit/dcc50445a364664586164f42f9250732bd372982) and now multi-category events are working as expected. But I don't know that we want to diverge from the v8 copy of the code."}}
{"actor":{"display_login":"jasongin"}}