Skip to content

Commit 47bdc71

Browse files
committed
inspector: add a "NodeTracing" domain support
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 <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 5248401 commit 47bdc71

19 files changed

+843
-160
lines changed

node.gyp

Lines changed: 165 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -455,17 +455,24 @@
455455
'src/inspector_js_api.cc',
456456
'src/inspector_socket.cc',
457457
'src/inspector_socket_server.cc',
458+
'src/inspector/tracing_agent.cc',
459+
'src/inspector/node_string.cc',
458460
'src/inspector_agent.h',
459461
'src/inspector_io.h',
460462
'src/inspector_socket.h',
461463
'src/inspector_socket_server.h',
464+
'src/inspector/node_string.h',
465+
'src/inspector/tracing_agent.h',
466+
'<@(node_inspector_generated_sources)'
462467
],
463468
'dependencies': [
469+
'node_protocol_generated_sources#host',
464470
'v8_inspector_compress_protocol_json#host',
465471
],
466472
'include_dirs': [
467473
'<(SHARED_INTERMEDIATE_DIR)/include', # for inspector
468474
'<(SHARED_INTERMEDIATE_DIR)',
475+
'<(SHARED_INTERMEDIATE_DIR)/src', # for inspector
469476
],
470477
}, {
471478
'defines': [ 'HAVE_INSPECTOR=0' ]
@@ -677,54 +684,6 @@
677684
} ]
678685
]
679686
},
680-
{
681-
'target_name': 'v8_inspector_compress_protocol_json',
682-
'type': 'none',
683-
'toolsets': ['host'],
684-
'conditions': [
685-
[ 'v8_enable_inspector==1', {
686-
'copies': [
687-
{
688-
'destination': '<(SHARED_INTERMEDIATE_DIR)',
689-
'files': ['deps/v8/src/inspector/js_protocol.pdl']
690-
}
691-
],
692-
'actions': [
693-
{
694-
'action_name': 'v8_inspector_convert_protocol_to_json',
695-
'inputs': [
696-
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.pdl',
697-
],
698-
'outputs': [
699-
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
700-
],
701-
'action': [
702-
'python',
703-
'deps/v8/third_party/inspector_protocol/ConvertProtocolToJSON.py',
704-
'<@(_inputs)',
705-
'<@(_outputs)',
706-
],
707-
},
708-
{
709-
'action_name': 'v8_inspector_compress_protocol_json',
710-
'process_outputs_as_sources': 1,
711-
'inputs': [
712-
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
713-
],
714-
'outputs': [
715-
'<(SHARED_INTERMEDIATE_DIR)/v8_inspector_protocol_json.h',
716-
],
717-
'action': [
718-
'python',
719-
'tools/compress_json.py',
720-
'<@(_inputs)',
721-
'<@(_outputs)',
722-
],
723-
},
724-
],
725-
}],
726-
],
727-
},
728687
{
729688
'target_name': 'node_js2c',
730689
'type': 'none',
@@ -1044,5 +1003,163 @@
10441003
},
10451004
]
10461005
}], # end aix section
1006+
[ 'v8_enable_inspector==1', {
1007+
'variables': {
1008+
'protocol_path': 'deps/v8/third_party/inspector_protocol',
1009+
'node_inspector_path': 'src/inspector',
1010+
'node_inspector_generated_sources': [
1011+
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Forward.h',
1012+
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.cpp',
1013+
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.h',
1014+
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.cpp',
1015+
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.h',
1016+
],
1017+
'node_protocol_files': [
1018+
'<(protocol_path)/lib/Allocator_h.template',
1019+
'<(protocol_path)/lib/Array_h.template',
1020+
'<(protocol_path)/lib/Collections_h.template',
1021+
'<(protocol_path)/lib/DispatcherBase_cpp.template',
1022+
'<(protocol_path)/lib/DispatcherBase_h.template',
1023+
'<(protocol_path)/lib/ErrorSupport_cpp.template',
1024+
'<(protocol_path)/lib/ErrorSupport_h.template',
1025+
'<(protocol_path)/lib/Forward_h.template',
1026+
'<(protocol_path)/lib/FrontendChannel_h.template',
1027+
'<(protocol_path)/lib/Maybe_h.template',
1028+
'<(protocol_path)/lib/Object_cpp.template',
1029+
'<(protocol_path)/lib/Object_h.template',
1030+
'<(protocol_path)/lib/Parser_cpp.template',
1031+
'<(protocol_path)/lib/Parser_h.template',
1032+
'<(protocol_path)/lib/Protocol_cpp.template',
1033+
'<(protocol_path)/lib/ValueConversions_h.template',
1034+
'<(protocol_path)/lib/Values_cpp.template',
1035+
'<(protocol_path)/lib/Values_h.template',
1036+
'<(protocol_path)/templates/Exported_h.template',
1037+
'<(protocol_path)/templates/Imported_h.template',
1038+
'<(protocol_path)/templates/TypeBuilder_cpp.template',
1039+
'<(protocol_path)/templates/TypeBuilder_h.template',
1040+
'<(protocol_path)/CodeGenerator.py',
1041+
]
1042+
},
1043+
'targets': [
1044+
{
1045+
'target_name': 'prepare_protocol_json',
1046+
'type': 'none',
1047+
'toolsets': ['host'],
1048+
'copies': [
1049+
{
1050+
'files': [
1051+
'<(node_inspector_path)/node_protocol_config.json',
1052+
'<(node_inspector_path)/node_protocol.pdl'
1053+
],
1054+
'destination': '<(SHARED_INTERMEDIATE_DIR)',
1055+
}
1056+
],
1057+
'actions': [
1058+
{
1059+
'action_name': 'convert_node_protocol_to_json',
1060+
'inputs': [
1061+
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.pdl',
1062+
],
1063+
'outputs': [
1064+
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.json',
1065+
],
1066+
'action': [
1067+
'python',
1068+
'deps/v8/third_party/inspector_protocol/ConvertProtocolToJSON.py',
1069+
'<@(_inputs)',
1070+
'<@(_outputs)',
1071+
],
1072+
},
1073+
]
1074+
},
1075+
{
1076+
'target_name': 'node_protocol_generated_sources',
1077+
'type': 'none',
1078+
'toolsets': ['host'],
1079+
'dependencies': ['prepare_protocol_json'],
1080+
'actions': [
1081+
{
1082+
'action_name': 'node_protocol_generated_sources',
1083+
'inputs': [
1084+
'<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json',
1085+
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.json',
1086+
'<@(node_protocol_files)',
1087+
],
1088+
'outputs': [
1089+
'<@(node_inspector_generated_sources)',
1090+
],
1091+
'action': [
1092+
'python',
1093+
'<(protocol_path)/CodeGenerator.py',
1094+
'--jinja_dir', '<@(protocol_path)/..',
1095+
'--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/',
1096+
'--config', '<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json',
1097+
],
1098+
'message': 'Generating node protocol sources from protocol json',
1099+
},
1100+
]
1101+
},
1102+
{
1103+
'target_name': 'v8_inspector_compress_protocol_json',
1104+
'type': 'none',
1105+
'toolsets': ['host'],
1106+
'copies': [
1107+
{
1108+
'destination': '<(SHARED_INTERMEDIATE_DIR)',
1109+
'files': ['deps/v8/src/inspector/js_protocol.pdl']
1110+
}
1111+
],
1112+
'actions': [
1113+
{
1114+
'action_name': 'v8_inspector_convert_protocol_to_json',
1115+
'inputs': [
1116+
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.pdl',
1117+
],
1118+
'outputs': [
1119+
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
1120+
],
1121+
'action': [
1122+
'python',
1123+
'deps/v8/third_party/inspector_protocol/ConvertProtocolToJSON.py',
1124+
'<@(_inputs)',
1125+
'<@(_outputs)',
1126+
],
1127+
},
1128+
{
1129+
'action_name': 'concatenate_protocols',
1130+
'inputs': [
1131+
'<(SHARED_INTERMEDIATE_DIR)/js_protocol.json',
1132+
'<(SHARED_INTERMEDIATE_DIR)/node_protocol.json',
1133+
],
1134+
'outputs': [
1135+
'<(SHARED_INTERMEDIATE_DIR)/concatenated_protocol.json',
1136+
],
1137+
'action': [
1138+
'python',
1139+
'deps/v8/third_party/inspector_protocol/ConcatenateProtocols.py',
1140+
'<@(_inputs)',
1141+
'<@(_outputs)',
1142+
],
1143+
},
1144+
{
1145+
'action_name': 'v8_inspector_compress_protocol_json',
1146+
'process_outputs_as_sources': 1,
1147+
'inputs': [
1148+
'<(SHARED_INTERMEDIATE_DIR)/concatenated_protocol.json',
1149+
],
1150+
'outputs': [
1151+
'<(SHARED_INTERMEDIATE_DIR)/v8_inspector_protocol_json.h',
1152+
],
1153+
'action': [
1154+
'python',
1155+
'tools/compress_json.py',
1156+
'<@(_inputs)',
1157+
'<@(_outputs)',
1158+
],
1159+
},
1160+
],
1161+
},
1162+
]
1163+
}]
10471164
], # end conditions block
10481165
}

src/inspector/node_protocol.pdl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Please notify @nodejs/v8-inspector and @nodejs/trace-events before modifying this file
2+
version
3+
major 1
4+
minor 0
5+
6+
experimental domain NodeTracing
7+
type TraceConfig extends object
8+
properties
9+
# Controls how the trace buffer stores data.
10+
optional enum recordMode
11+
recordUntilFull
12+
recordContinuously
13+
recordAsMuchAsPossible
14+
# Included category filters.
15+
array of string includedCategories
16+
17+
# Gets supported tracing categories.
18+
command getCategories
19+
returns
20+
# A list of supported tracing categories.
21+
array of string categories
22+
23+
# Start trace events collection.
24+
command start
25+
parameters
26+
TraceConfig traceConfig
27+
28+
# Stop trace events collection. Remaining collected events will be sent as a sequence of
29+
# dataCollected events followed by tracingComplete event.
30+
command stop
31+
32+
# Contains an bucket of collected trace events.
33+
event dataCollected
34+
parameters
35+
array of object value
36+
37+
# Signals that tracing is stopped and there is no trace buffers pending flush, all data were
38+
# delivered via dataCollected events.
39+
event tracingComplete
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"protocol": {
3+
"path": "node_protocol.json",
4+
"package": "src/node/inspector/protocol",
5+
"output": "node/inspector/protocol",
6+
"namespace": ["node", "inspector", "protocol"],
7+
"options": [
8+
{
9+
"domain": "NodeTracing"
10+
}
11+
]
12+
},
13+
"exported": {
14+
"package": "include/inspector",
15+
"output": "../../include/inspector",
16+
"string_header": "v8-inspector.h",
17+
"string_in": "StringView",
18+
"string_out": "std::unique_ptr<StringBuffer>",
19+
"to_string_out": "StringBufferImpl::adopt(%s)",
20+
"export_macro": "V8_EXPORT"
21+
},
22+
"lib": {
23+
"package": "src/node/inspector/protocol",
24+
"output": "node/inspector/protocol",
25+
"string_header": "inspector/node_string.h"
26+
}
27+
}

0 commit comments

Comments
 (0)