[sheepdog] [PATCH 4/6] lib: add tracepoints related to work queue
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Fri Jan 9 08:37:17 CET 2015
Cc: Gu Ping <guping610 at qq.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
lib/Makefile.am | 8 +++++
lib/tracepoint/work_tp.c | 13 +++++++
lib/tracepoint/work_tp.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++
lib/work.c | 10 ++++++
4 files changed, 124 insertions(+)
create mode 100644 lib/tracepoint/work_tp.c
create mode 100644 lib/tracepoint/work_tp.h
diff --git a/lib/Makefile.am b/lib/Makefile.am
index a43076e..bb68430 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -35,6 +35,14 @@ if BUILD_TRACE
AM_CPPFLAGS += -DENABLE_TRACE
endif
+# for LTTng ust tracepoints
+AM_CPPFLAGS = -I$(top_srcdir)/lib/tracepoint
+noinst_HEADERS = tracepoint/work_tp.h
+
+if BUILD_LTTNG_UST
+libsheepdog_a_SOURCES += tracepoint/work_tp.c
+endif
+
# support for GNU Flymake
check-syntax:
$(COMPILE) -fsyntax-only $(CHK_SOURCES)
diff --git a/lib/tracepoint/work_tp.c b/lib/tracepoint/work_tp.c
new file mode 100644
index 0000000..7df6020
--- /dev/null
+++ b/lib/tracepoint/work_tp.c
@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "work_tp.h"
diff --git a/lib/tracepoint/work_tp.h b/lib/tracepoint/work_tp.h
new file mode 100644
index 0000000..4f4608a
--- /dev/null
+++ b/lib/tracepoint/work_tp.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef ENABLE_LTTNG_UST
+
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER work
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./work_tp.h"
+
+#if !defined(WORK_TRACEPOINT_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define WORK_TRACEPOINT_H
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(
+ work,
+ queue_work,
+ TP_ARGS(void *, wi, void *, work),
+ TP_FIELDS(
+ ctf_integer_hex(void *, worker_info_ptr, wi)
+ ctf_integer_hex(void *, work_ptr, work)
+ )
+ )
+
+TRACEPOINT_EVENT(
+ work,
+ do_work,
+ TP_ARGS(void *, wi, void *, work),
+ TP_FIELDS(
+ ctf_integer_hex(void *, worker_info_ptr, wi)
+ ctf_integer_hex(void *, work_ptr, work)
+ )
+ )
+
+TRACEPOINT_EVENT(
+ work,
+ request_done,
+ TP_ARGS(void *, wi, void *, work),
+ TP_FIELDS(
+ ctf_integer_hex(void *, worker_info_ptr, wi)
+ ctf_integer_hex(void *, work_ptr, work)
+ )
+ )
+
+TRACEPOINT_EVENT(
+ work,
+ create_queue,
+ TP_ARGS(const char *, name, void *, wi, int, control),
+ TP_FIELDS(
+ ctf_string(queue_name, name)
+ ctf_integer_hex(void *, worker_info_ptr, wi)
+ ctf_integer(int, thread_control_policy, control)
+ )
+ )
+
+TRACEPOINT_EVENT(
+ work,
+ exit_for_shrink,
+ TP_ARGS(void *, wi),
+ TP_FIELDS(
+ ctf_integer_hex(void *, worker_info_ptr, wi)
+ )
+ )
+
+TRACEPOINT_EVENT(
+ work,
+ grow_queue,
+ TP_ARGS(void *, wi, int, nr_threads),
+ TP_FIELDS(
+ ctf_integer_hex(void *, worker_info_ptr, wi)
+ ctf_integer(int, next_nr_threads, nr_threads)
+ )
+ )
+
+#endif /* WORK_TRACEPOINT_H */
+
+#include <lttng/tracepoint-event.h>
+
+#else /* ENABLE_LTTNG_UST */
+
+#include "lttng_disable.h"
+
+#endif
diff --git a/lib/work.c b/lib/work.c
index 7938d42..f10ddaa 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -33,6 +33,9 @@
#include "work.h"
#include "event.h"
+#define TRACEPOINT_DEFINE
+#include "work_tp.h"
+
/*
* The protection period from shrinking work queue. This is necessary
* to avoid many calls of pthread_create. Without it, threads are
@@ -263,6 +266,8 @@ void queue_work(struct work_queue *q, struct work *work)
{
struct wq_info *wi = container_of(q, struct wq_info, q);
+ tracepoint(work, queue_work, wi, work);
+
uatomic_inc(&wi->nr_queued_work);
sd_mutex_lock(&wi->pending_lock);
@@ -296,6 +301,8 @@ static void worker_thread_request_done(int fd, int events, void *data)
work = list_first_entry(&list, struct work, w_list);
list_del(&work->w_list);
+ tracepoint(work, request_done, wi, work);
+
work->done(work);
uatomic_dec(&wi->nr_queued_work);
}
@@ -336,6 +343,8 @@ retest:
list_del(&work->w_list);
sd_mutex_unlock(&wi->pending_lock);
+ tracepoint(work, do_work, wi, work);
+
if (work->fn)
work->fn(work);
@@ -409,6 +418,7 @@ struct work_queue *create_work_queue(const char *name,
list_add(&wi->list, &wq_info_list);
+ tracepoint(work, create_queue, wi->name, wi, tc);
return &wi->q;
destroy_threads:
sd_destroy_cond(&wi->pending_cond);
--
1.9.1
More information about the sheepdog
mailing list