Skip to content

Instantly share code, notes, and snippets.

@alq666
Created April 26, 2016 14:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alq666/632b815924393aca1f8c29dfa3b8701b to your computer and use it in GitHub Desktop.
Save alq666/632b815924393aca1f8c29dfa3b8701b to your computer and use it in GitHub Desktop.
From 504504f2f8c13f077f09e0906cd7e7d3ca405acc Mon Sep 17 00:00:00 2001
From: Vincent Bernat <vincent-5wNQGcxKXm8AvxtiuMwx3w@public.gmane.org>
Date: Wed, 7 May 2014 18:18:07 +0200
Subject: [PATCH] MINOR: dtrace: add dtrace support (WIP)
Both dtrace and systemtap are supported. Currently, only one tracepoint
is defined.
---
.gitignore | 1 +
Makefile | 18 +++++++++++++++++-
examples/haproxy.stp | 3 +++
include/common/debug.h | 8 ++++++++
src/frontend.c | 2 ++
src/probes.d | 21 +++++++++++++++++++++
6 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 examples/haproxy.stp
create mode 100644 src/probes.d
diff --git a/.gitignore b/.gitignore
index ec1545a7a3df..c13934c19835 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,4 @@ make-*
dlmalloc.c
00*.patch
*.service
+include/common/probes.h
diff --git a/Makefile b/Makefile
index f95ba03ac60f..617ab4447e69 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@
# USE_ZLIB : enable zlib library support.
# USE_CPU_AFFINITY : enable pinning processes to CPU on Linux. Automatic.
# USE_TFO : enable TCP fast open. Supported on Linux >= 3.7.
+# USE_DTRACE : enable DTrace/systemtap support
#
# Options can be forced by specifying "USE_xxx=1" or can be disabled by using
# "USE_xxx=" (empty string).
@@ -582,6 +583,12 @@ OPTIONS_CFLAGS += -DUSE_TFO
BUILD_OPTIONS += $(call ignore_implicit,USE_TFO)
endif
+# DTrace
+ifneq ($(USE_DTRACE),)
+DTRACE = dtrace
+OPTIONS_CFLAGS += -DUSE_DTRACE
+endif
+
# This one can be changed to look for ebtree files in an external directory
EBTREE_DIR := ebtree
@@ -655,6 +662,10 @@ EBTREE_OBJS = $(EBTREE_DIR)/ebtree.o \
ifneq ($(TRACE),)
OBJS += src/trace.o
endif
+ifneq ($(USE_DTRACE),)
+OBJS += src/probes.o
+$(OBJS): | include/common/probes.h
+endif
WRAPPER_OBJS = src/haproxy-systemd-wrapper.o
@@ -679,6 +690,11 @@ objsize: haproxy
src/trace.o: src/trace.c
$(CC) $(TRACE_COPTS) -c -o $@ $<
+include/common/probes.h: src/probes.d
+ $(DTRACE) -C -h -s $< -o $@
+src/probes.o: src/probes.d
+ $(DTRACE) -C -G -s $< -o $@
+
src/haproxy.o: src/haproxy.c
$(CC) $(COPTS) \
-DBUILD_TARGET='"$(strip $(TARGET))"' \
@@ -715,7 +731,7 @@ install-bin: haproxy haproxy-systemd-wrapper
install: install-bin install-man install-doc
clean:
- rm -f *.[oas] src/*.[oas] ebtree/*.[oas] haproxy test
+ rm -f *.[oas] src/*.[oas] ebtree/*.[oas] haproxy test include/common/probes.h
for dir in . src include/* doc ebtree; do rm -f $$dir/*~ $$dir/*.rej $$dir/core; done
rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION)$(SUBVERS).tar.gz
rm -f haproxy-$(VERSION) haproxy-$(VERSION)$(SUBVERS) nohup.out gmon.out
diff --git a/examples/haproxy.stp b/examples/haproxy.stp
new file mode 100644
index 000000000000..1ef59dbfe41b
--- /dev/null
+++ b/examples/haproxy.stp
@@ -0,0 +1,3 @@
+probe process("./haproxy").provider("haproxy").mark("frontend_accept") {
+ printf("Frontend %s accepted a connection\n", user_string($arg1));
+}
diff --git a/include/common/debug.h b/include/common/debug.h
index fe05a444a8df..a6cd01d61fd5 100644
--- a/include/common/debug.h
+++ b/include/common/debug.h
@@ -54,5 +54,13 @@
##args); \
} while (0)
+#ifdef USE_DTRACE
+# include "probes.h"
+# define DTRACE(probe) probe
+# define DTRACE_ENABLED(probe) probe ## _ENABLED()
+#else
+# define DTRACE(probe)
+# define DTRACE_ENABLED(probe) (0)
+#endif
#endif /* _COMMON_DEBUG_H */
diff --git a/src/frontend.c b/src/frontend.c
index f94c6ab2b231..e56bada5a47e 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -57,6 +57,8 @@ int frontend_accept(struct session *s)
struct connection *conn = __objt_conn(s->si[0].end);
int cfd = conn->t.sock.fd;
+ DTRACE(HAPROXY_FRONTEND_ACCEPT(s->fe->id));
+
tv_zero(&s->logs.tv_request);
s->logs.t_queue = -1;
s->logs.t_connect = -1;
diff --git a/src/probes.d b/src/probes.d
new file mode 100644
index 000000000000..15b140569b72
--- /dev/null
+++ b/src/probes.d
@@ -0,0 +1,21 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Functions used to parse typed argument lists
+ *
+ * Copyright 2014 Willy Tarreau <w@1wt.eu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+provider haproxy {
+
+ /**
+ * Fired when a frontend accepts a connection.
+ * @param frontend the name of the frontend
+ */
+ probe frontend_accept(const char *frontend);
+}
--
2.0.0.rc2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment