h2olog: encapsulate http tracing code
In order to make space for adding QUIC tracing.
@@ -95,20 +95,8 @@ def handle_resp_line(cpu, data, size):
line = b["txbuf"].event(data)
print("%u %u TxStatus %d" % (line.conn_id, line.req_id, line.http_status))
-try:
- h2o_pid = 0
- opts, args = getopt.getopt(sys.argv[1:], 'p:')
- for opt, arg in opts:
- if opt == "-p":
- h2o_pid = arg
-except getopt.error as msg:
- print(msg)
- sys.exit(2)
-
-if h2o_pid == 0:
- sys.exit("USAGE: h2olog -p PID")
-
-u = USDT(pid=int(h2o_pid))
+def trace_http(pid):
+ u = USDT(pid=int(pid))
u.enable_probe(probe="receive_request", fn_name="trace_receive_req")
u.enable_probe(probe="receive_request_header", fn_name="trace_receive_req_header")
u.enable_probe(probe="send_response", fn_name="trace_send_resp")
@@ -122,3 +110,18 @@ while 1:
b.perf_buffer_poll()
except KeyboardInterrupt:
exit()
+
+try:
+ h2o_pid = 0
+ opts, args = getopt.getopt(sys.argv[1:], 'p:')
+ for opt, arg in opts:
+ if opt == "-p":
+ h2o_pid = arg
+except getopt.error as msg:
+ print(msg)
+ sys.exit(2)
+
+if h2o_pid == 0:
+ sys.exit("USAGE: h2olog -p PID")
+
+trace_http(h2o_pid)
