refactor gen-bpf.py to have main() function
@@ -28,12 +28,6 @@ from collections import OrderedDict
from pathlib import Path
from pprint import pprint
-try:
- (_, d_files_dir, output_file) = sys.argv
-except:
- print("usage: %s h2o_path d_files_dir output_file" % sys.argv[0])
- sys.exit(1)
-
block_fields = {
"quicly:crypto_decrypt": set(["decrypted"]),
"quicly:receive": set(["bytes"]),
@@ -242,17 +236,23 @@ int %s(struct pt_regs *ctx) {
return c
+def prepare_context(d_files_dir):
+ st_map = parse_c_struct(Path(Path(__file__).parent.parent, "data-types.h"))
context = {
"id": 0,
"probe_metadata": OrderedDict(),
- "st_map": parse_c_struct(Path(Path(__file__).parent.parent, "data-types.h")),
+ "st_map": st_map,
}
-
parse_d(context, Path(d_files_dir, "quicly-probes.d"),
block_probes=quicly_block_probes)
parse_d(context, Path(d_files_dir, "h2o-probes.d"),
allow_probes=h2o_allow_probes)
+ return context
+
+
+def generate_cplusplus(context, output_file):
+
probe_metadata = context["probe_metadata"]
event_t_decl = r"""
@@ -306,9 +306,7 @@ usdt_def += """
}
"""
-
handle_event_func = r"""
-
static
void quic_handle_event(void *context, void *data, int data_len) {
h2o_tracer_t *tracer = static_cast<h2o_tracer_t*>(context);
@@ -415,3 +413,18 @@ void init_quic_tracer(h2o_tracer_t * tracer) {
}
""" % (bpf, usdt_def, event_t_decl, handle_event_func))
+
+
+def main():
+ try:
+ (_, d_files_dir, output_file) = sys.argv
+ except:
+ print("usage: %s h2o_path d_files_dir output_file" % sys.argv[0])
+ sys.exit(1)
+
+ context = prepare_context(d_files_dir)
+ generate_cplusplus(context, output_file)
+
+
+if __name__ == "__main__":
+ main()
