Skip to content

Commit 04f7678

Browse files
eugeneoMylesBorins
authored andcommitted
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 cb94601 commit 04f7678

19 files changed

+843
-160
lines changed

node.gyp

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

src/inspector/node_protocol.pdl

+39
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
+27
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)