[sheepdog] [PATCH v2 2/7] logger: add a helper to get the thread name
Liu Yuan
namei.unix at gmail.com
Thu Aug 30 11:38:59 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
This patch prepare for trace patch set.
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
include/logger.h | 1 +
lib/logger.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/include/logger.h b/include/logger.h
index 580c5de..019d0d8 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -26,6 +26,7 @@ extern void dump_logmsg(void *);
extern void log_write(int prio, const char *func, int line, const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
extern void set_thread_name(const char *name, int idx);
+extern void get_thread_name(char *name);
/*
+ * sheep log priorities, comliant with syslog spec
diff --git a/lib/logger.c b/lib/logger.c
index 154cb6b..380d65c 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -571,3 +571,13 @@ notrace void set_thread_name(const char *name, int idx)
worker_name = name;
worker_idx = idx;
}
+
+notrace void get_thread_name(char *name)
+{
+ if (worker_name && worker_idx)
+ sprintf(name, "%s %d", worker_name, worker_idx);
+ else if (worker_name)
+ sprintf(name, "%s", worker_name);
+ else
+ sprintf(name, "%s", "main");
+}
--
1.7.10.2
More information about the sheepdog
mailing list