Skip to content

Commit

Permalink
inspector: add a "NodeTracing" domain support
Browse files Browse the repository at this point in the history
This change adds a new inspector domain for receiving Node tracing
data.
  1. Node.js now can extend Inspector protocol with new domains with
     the API defined in the src/inspector/node_protocol.pdl.
  2. Plumbing code will be generated at the build time. /json/protocol
     HTTP endpoint returns both V8 and Node.js inspector protocol.
  3. "NodeTracing" domain was introduced. It is based on the Chrome
     "Tracing" domain.

PR-URL: #20608
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
eugeneo committed May 17, 2018
1 parent 5248401 commit 47bdc71
Show file tree
Hide file tree
Showing 19 changed files with 843 additions and 160 deletions.
213 changes: 165 additions & 48 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,24 @@
'src/inspector_js_api.cc',
'src/inspector_socket.cc',
'src/inspector_socket_server.cc',
'src/inspector/tracing_agent.cc',
'src/inspector/node_string.cc',
'src/inspector_agent.h',
'src/inspector_io.h',
'src/inspector_socket.h',
'src/inspector_socket_server.h',
'src/inspector/node_string.h',
'src/inspector/tracing_agent.h',
'<@(node_inspector_generated_sources)'
],
'dependencies': [
'node_protocol_generated_sources#host',
'v8_inspector_compress_protocol_json#host',
],
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)/include', # for inspector
'<(SHARED_INTERMEDIATE_DIR)',
'<(SHARED_INTERMEDIATE_DIR)/src', # for inspector
],
}, {
'defines': [ 'HAVE_INSPECTOR=0' ]
Expand Down Expand Up @@ -677,54 +684,6 @@
} ]
]
},
{
'target_name': 'v8_inspector_compress_protocol_json',
'type': 'none',
'toolsets': ['host'],
'conditions': [
[ 'v8_enable_inspector==1', {
'copies': [
{
'destination': '<(SHARED_INTERMEDIATE_DIR)',
'files': ['deps/v8/src/inspector/js_protocol.pdl']
}
],
'actions': [
{
'action_name': 'v8_inspector_convert_protocol_to_json',
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.pdl',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
],
'action': [
'python',
'deps/v8/third_party/inspector_protocol/ConvertProtocolToJSON.py',
'<@(_inputs)',
'<@(_outputs)',
],
},
{
'action_name': 'v8_inspector_compress_protocol_json',
'process_outputs_as_sources': 1,
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/v8_inspector_protocol_json.h',
],
'action': [
'python',
'tools/compress_json.py',
'<@(_inputs)',
'<@(_outputs)',
],
},
],
}],
],
},
{
'target_name': 'node_js2c',
'type': 'none',
Expand Down Expand Up @@ -1044,5 +1003,163 @@
},
]
}], # end aix section
[ 'v8_enable_inspector==1', {
'variables': {
'protocol_path': 'deps/v8/third_party/inspector_protocol',
'node_inspector_path': 'src/inspector',
'node_inspector_generated_sources': [
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Forward.h',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.h',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.h',
],
'node_protocol_files': [
'<(protocol_path)/lib/Allocator_h.template',
'<(protocol_path)/lib/Array_h.template',
'<(protocol_path)/lib/Collections_h.template',
'<(protocol_path)/lib/DispatcherBase_cpp.template',
'<(protocol_path)/lib/DispatcherBase_h.template',
'<(protocol_path)/lib/ErrorSupport_cpp.template',
'<(protocol_path)/lib/ErrorSupport_h.template',
'<(protocol_path)/lib/Forward_h.template',
'<(protocol_path)/lib/FrontendChannel_h.template',
'<(protocol_path)/lib/Maybe_h.template',
'<(protocol_path)/lib/Object_cpp.template',
'<(protocol_path)/lib/Object_h.template',
'<(protocol_path)/lib/Parser_cpp.template',
'<(protocol_path)/lib/Parser_h.template',
'<(protocol_path)/lib/Protocol_cpp.template',
'<(protocol_path)/lib/ValueConversions_h.template',
'<(protocol_path)/lib/Values_cpp.template',
'<(protocol_path)/lib/Values_h.template',
'<(protocol_path)/templates/Exported_h.template',
'<(protocol_path)/templates/Imported_h.template',
'<(protocol_path)/templates/TypeBuilder_cpp.template',
'<(protocol_path)/templates/TypeBuilder_h.template',
'<(protocol_path)/CodeGenerator.py',
]
},
'targets': [
{
'target_name': 'prepare_protocol_json',
'type': 'none',
'toolsets': ['host'],
'copies': [
{
'files': [
'<(node_inspector_path)/node_protocol_config.json',
'<(node_inspector_path)/node_protocol.pdl'
],
'destination': '<(SHARED_INTERMEDIATE_DIR)',
}
],
'actions': [
{
'action_name': 'convert_node_protocol_to_json',
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.pdl',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.json',
],
'action': [
'python',
'deps/v8/third_party/inspector_protocol/ConvertProtocolToJSON.py',
'<@(_inputs)',
'<@(_outputs)',
],
},
]
},
{
'target_name': 'node_protocol_generated_sources',
'type': 'none',
'toolsets': ['host'],
'dependencies': ['prepare_protocol_json'],
'actions': [
{
'action_name': 'node_protocol_generated_sources',
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json',
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.json',
'<@(node_protocol_files)',
],
'outputs': [
'<@(node_inspector_generated_sources)',
],
'action': [
'python',
'<(protocol_path)/CodeGenerator.py',
'--jinja_dir', '<@(protocol_path)/..',
'--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/',
'--config', '<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json',
],
'message': 'Generating node protocol sources from protocol json',
},
]
},
{
'target_name': 'v8_inspector_compress_protocol_json',
'type': 'none',
'toolsets': ['host'],
'copies': [
{
'destination': '<(SHARED_INTERMEDIATE_DIR)',
'files': ['deps/v8/src/inspector/js_protocol.pdl']
}
],
'actions': [
{
'action_name': 'v8_inspector_convert_protocol_to_json',
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.pdl',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
],
'action': [
'python',
'deps/v8/third_party/inspector_protocol/ConvertProtocolToJSON.py',
'<@(_inputs)',
'<@(_outputs)',
],
},
{
'action_name': 'concatenate_protocols',
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.json',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/concatenated_protocol.json',
],
'action': [
'python',
'deps/v8/third_party/inspector_protocol/ConcatenateProtocols.py',
'<@(_inputs)',
'<@(_outputs)',
],
},
{
'action_name': 'v8_inspector_compress_protocol_json',
'process_outputs_as_sources': 1,
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/concatenated_protocol.json',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/v8_inspector_protocol_json.h',
],
'action': [
'python',
'tools/compress_json.py',
'<@(_inputs)',
'<@(_outputs)',
],
},
],
},
]
}]
], # end conditions block
}
39 changes: 39 additions & 0 deletions src/inspector/node_protocol.pdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Please notify @nodejs/v8-inspector and @nodejs/trace-events before modifying this file
version
major 1
minor 0

experimental domain NodeTracing
type TraceConfig extends object
properties
# Controls how the trace buffer stores data.
optional enum recordMode
recordUntilFull
recordContinuously
recordAsMuchAsPossible
# Included category filters.
array of string includedCategories

# Gets supported tracing categories.
command getCategories
returns
# A list of supported tracing categories.
array of string categories

# Start trace events collection.
command start
parameters
TraceConfig traceConfig

# Stop trace events collection. Remaining collected events will be sent as a sequence of
# dataCollected events followed by tracingComplete event.
command stop

# Contains an bucket of collected trace events.
event dataCollected
parameters
array of object value

# Signals that tracing is stopped and there is no trace buffers pending flush, all data were
# delivered via dataCollected events.
event tracingComplete
27 changes: 27 additions & 0 deletions src/inspector/node_protocol_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"protocol": {
"path": "node_protocol.json",
"package": "src/node/inspector/protocol",
"output": "node/inspector/protocol",
"namespace": ["node", "inspector", "protocol"],
"options": [
{
"domain": "NodeTracing"
}
]
},
"exported": {
"package": "include/inspector",
"output": "../../include/inspector",
"string_header": "v8-inspector.h",
"string_in": "StringView",
"string_out": "std::unique_ptr<StringBuffer>",
"to_string_out": "StringBufferImpl::adopt(%s)",
"export_macro": "V8_EXPORT"
},
"lib": {
"package": "src/node/inspector/protocol",
"output": "node/inspector/protocol",
"string_header": "inspector/node_string.h"
}
}
Loading

0 comments on commit 47bdc71

Please sign in to comment.