Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions misc/gen-bpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ def generate_cplusplus(context, output_file):
handle_event_func = r"""
static
void quic_handle_event(h2o_tracer_t *tracer, const void *data, int data_len) {
FILE *out = tracer->out;
int64_t time_nanosec = now_nanosec();

FILE *out = tracer->out;
const quic_event_t *event = static_cast<const quic_event_t*>(data);

// output JSON
Expand All @@ -333,6 +334,7 @@ def generate_cplusplus(context, output_file):
handle_event_func += " case %s: { // %s\n" % (
metadata['id'], fully_specified_probe_name)
handle_event_func += ' json_write_pair_n(out, STR_LIT("type"), "%s");\n' % probe_name.replace("_", "-")
handle_event_func += ' json_write_pair_c(out, STR_LIT("time-nanosec"), time_nanosec);\n'

for field_name, field_type in flat_args_map.items():
if block_field_set and field_name in block_field_set:
Expand All @@ -357,7 +359,7 @@ def generate_cplusplus(context, output_file):
if probe_name != "h3_accept":
handle_event_func += ' json_write_pair_c(out, STR_LIT("conn"), event->%s.master_id);\n' % (
probe_name)
handle_event_func += ' json_write_pair_c(out, STR_LIT("time"), time_milliseconds());\n'
handle_event_func += ' json_write_pair_c(out, STR_LIT("time"), time_nanosec / 1000000L);\n'

handle_event_func += " break;\n"
handle_event_func += " }\n"
Expand All @@ -377,7 +379,7 @@ def generate_cplusplus(context, output_file):
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "h2olog.h"
#include "data-types.h"
#include "json.h"
Expand All @@ -390,19 +392,25 @@ def generate_cplusplus(context, output_file):
%s
)";

static uint64_t time_milliseconds()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (int64_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
static int64_t now_nanosec() {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
return (static_cast<int64_t>(now.tv_sec) * 1000000000L) + static_cast<int64_t>(now.tv_nsec);
}

%s
%s
%s

static void quic_handle_lost(h2o_tracer_t *tracer, uint64_t lost) {
fprintf(tracer->out, "{\"type\":\"h2olog-event-lost\",\"time\":%%" PRIu64 ",\"lost\":%%" PRIu64 "}\n", time_milliseconds(), lost);
int64_t time_nanosec = now_nanosec();
int64_t time_millisec = time_nanosec / 1000000L;
fprintf(tracer->out, "{"
"\"type\":\"h2olog-event-lost\","
"\"time\":%%" PRId64 ","
"\"time-nanosec\":%%" PRId64 ","
"\"lost\":%%" PRIu64
"}\n", time_millisec, time_nanosec, lost);
}

static const char *quic_bpf_ext() {
Expand Down