add base code for options handling
* Compile with: "g++ -o h2olog -I/usr/include/bcc/compat h2olog.cc -lbcc"
*/
+#include <inttypes.h>
#include <bcc/BPF.h>
#include <iostream>
@@ -21,25 +22,43 @@ int trace_quicly__accept(struct pt_regs *ctx) {
}
)";
+#define VERSION "0.1.0"
#define POLL_TIMEOUT 100
struct event_t {
uint64_t at;
};
+static void usage(void) {
+ printf("h2olog (%s)\n", VERSION);
+ printf("-p PID of the H2O server\n");
+ printf("-h Print this help and exit\n");
+ return;
+}
+
void handle_quic_event(void *cpu, void *data, int len) {
struct event_t *ev = (event_t*)data;
- std::cout << "time: " << ev->at << std::endl;
+ printf("time: %" PRIu64 "\n", ev->at);
}
int main(int argc, char **argv) {
- // Simplified for demonstration purpose.
pid_t pid = -1;
- if (argc < 2) {
- std::cerr << "h2olog <pid>" << std::endl;
- return 1;
+ int c;
+ while ((c = getopt(argc, argv, "hvp:t:s:dP:")) != -1) {
+ switch(c) {
+ case 'p':
+ pid = atoi(optarg);
+ break;
+ case 'h':
+ usage();
+ exit(EXIT_SUCCESS);
+ }
+ }
+
+ if (pid == -1) {
+ fprintf(stderr, "Error: -p option is missing\n");
+ exit(EXIT_FAILURE);
}
- pid = std::atoi(argv[1]);
ebpf::BPF *bpf = new ebpf::BPF();
ebpf::USDT u("", pid, "quicly", "accept", "trace_quicly__accept");
