Skip to contentSkip to conversation

Allow one to filter on specific trace actions

PATCH New Alan D. Brunelle 1 participant 1 message Jul 21, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow one to filter on specific trace actions

Quoted 1 line

From 8dbad2d1af70f3dce95e3d38a5f8cb582a02a69e Mon Sep 17 00:00:00 2001

From: Alan D. Brunelle <[email protected]>
Date: Mon, 21 Jul 2008 14:41:54 -0400
Subject: [PATCH] Allow one to filter on specific trace actions

Added in new '-m' option to blktrace: Can now specify filter at a specific trace action.

Also: fixed up a missing NOTIFY in the mas_maps table. Updated doc - still need to do man page.

---
 act_mask.c       |   43 +++++++++++++++++++++++---
 blktrace.c       |   30 +++++++++++++++---
 blktrace.h       |    1 +
 blktrace_api.h   |    1 +
 doc/blktrace.tex |   90 +++++++++++++++++++++++++++++++++++------------------
 5 files changed, 124 insertions(+), 41 deletions(-)
act_mask.c +38 -5
index 40a4050..87faa62 100644
@@ -1,7 +1,9 @@
 #include <strings.h>
 #include "blktrace.h"
 
-#define DECLARE_MASK_MAP(mask)          { BLK_TC_##mask, #mask, "BLK_TC_"#mask }
+#define DECLARE_MASK_MAP(mask)	{ BLK_TC_##mask, #mask, "BLK_TC_"#mask }
+#define DECLARE_TRACE_MAP(mask)	{ __BLK_TA_##mask, #mask, "__BLK_TA_"#mask }
+
 #define COMPARE_MASK_MAP(mmp, str)                                      \
         (!strcasecmp((mmp)->short_form, (str)) ||                      \
          !strcasecmp((mmp)->long_form, (str)))
@@ -23,22 +25,53 @@ static struct mask_map mask_maps[] = {
 	DECLARE_MASK_MAP(COMPLETE),
 	DECLARE_MASK_MAP(FS),
 	DECLARE_MASK_MAP(PC),
+	DECLARE_MASK_MAP(NOTIFY),
 	DECLARE_MASK_MAP(AHEAD),
 	DECLARE_MASK_MAP(META),
 };
 
-int find_mask_map(char *string)
+static struct mask_map trace_maps[] = {
+	DECLARE_TRACE_MAP(QUEUE),
+	DECLARE_TRACE_MAP(BACKMERGE),
+	DECLARE_TRACE_MAP(FRONTMERGE),
+	DECLARE_TRACE_MAP(GETRQ),
+	DECLARE_TRACE_MAP(SLEEPRQ),
+	DECLARE_TRACE_MAP(REQUEUE),
+	DECLARE_TRACE_MAP(ISSUE),
+	DECLARE_TRACE_MAP(COMPLETE),
+	DECLARE_TRACE_MAP(PLUG),
+	DECLARE_TRACE_MAP(UNPLUG_IO),
+	DECLARE_TRACE_MAP(UNPLUG_TIMER),
+	DECLARE_TRACE_MAP(INSERT),
+	DECLARE_TRACE_MAP(SPLIT),
+	DECLARE_TRACE_MAP(BOUNCE),
+	DECLARE_TRACE_MAP(REMAP),
+};
+
+#define MAP_LEN(map) (sizeof(map) / sizeof((map)[0]))
+
+int find_mask(char *string, struct mask_map *maps, unsigned int map_len)
 {
 	unsigned int i;
 
-	for (i = 0; i < sizeof(mask_maps)/sizeof(mask_maps[0]); i++)
-		if (COMPARE_MASK_MAP(&mask_maps[i], string))
-			return mask_maps[i].mask;
+	for (i = 0; i < map_len; i++)
+		if (COMPARE_MASK_MAP(&maps[i], string))
+			return maps[i].mask;
 
 	return -1;
 }
 
+int find_mask_map(char *string)
+{
+	return find_mask(string, mask_maps, MAP_LEN(mask_maps));
+}
+
 int valid_act_opt(int x)
 {
 	return (1 <= x) && (x < (1 << BLK_TC_SHIFT));
 }
+
+int find_trace_map(char *string)
+{
+	return find_mask(string, trace_maps, MAP_LEN(trace_maps));
+}
blktrace.c +25 -5
index 8892a33..f9131fe 100644
@@ -60,7 +60,7 @@ static char blktrace_version[] = "0.99.3";
 
 #define DEBUGFS_TYPE	0x64626720
 
-#define S_OPTS	"d:a:A:r:o:kw:Vb:n:D:lh:p:sI:"
+#define S_OPTS	"d:a:A:r:o:kw:Vb:n:D:lh:p:sI:m:"
 static struct option l_opts[] = {
 	{
 		.name = "dev",
@@ -247,6 +247,7 @@ static char *debugfs_path;
 static char *output_name;
 static char *output_dir;
 static int cat_mask = ~0U;
+static u32 trace_mask = ~0U;
 static int kill_running_trace;
 static unsigned long buf_size = BUF_SIZE;
 static unsigned long buf_nr = BUF_NR;
@@ -398,6 +399,7 @@ static int start_trace(struct device_information *dip)
 	buts.buf_size = dip->buf_size;
 	buts.buf_nr = dip->buf_nr;
 	buts.cat_mask = cat_mask;
+	buts.trace_mask = trace_mask;
 
 	if (ioctl(dip->fd, BLKTRACESETUP, &buts) < 0) {
 		perror("BLKTRACESETUP");
@@ -1756,7 +1758,8 @@ static int net_setup_client(void)
 
 static char usage_str[] = \
 	"-d <dev> [ -r debugfs path ] [ -o <output> ] [-k ] [ -w time ]\n" \
-	"[ -a action ] [ -A action mask ] [ -I  <devs file> ] [ -v ]\n\n" \
+	"[ -a action ] [ -A action mask ] [ -I  <devs file> ]\n" \
+	"[ -m trace ] [ -M trace mask ][ -v ]\n\n" \
 	"\t-d Use specified device. May also be given last after options\n" \
 	"\t-r Path to mounted debugfs, defaults to /sys/kernel/debug\n" \
 	"\t-o File(s) to send output to\n" \
@@ -1772,6 +1775,8 @@ static char usage_str[] = \
 	"\t-p Network port to use (default 8462)\n" \
 	"\t-s Make the network client NOT use sendfile() to transfer data\n" \
 	"\t-I Add devices found in <devs file>\n" \
+	"\t-m Only capture specified traces. See documentation\n" \
+	"\t-M Give traces mask as a single value. See documentation\n" \
 	"\t-V Print program version info\n\n";
 
 static void show_usage(char *program)
@@ -1786,6 +1791,7 @@ int main(int argc, char *argv[])
 	int i, c;
 	int stop_watch = 0;
 	int cat_mask_tmp = 0;
+	int trace_mask_tmp = 0;
 
 	while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) >= 0) {
 		switch (c) {
@@ -1800,7 +1806,7 @@ int main(int argc, char *argv[])
 			break;
 
 		case 'A':
-			if ((sscanf(optarg, "%x", &i) != 1) || 
+			if ((sscanf(optarg, "%x", &i) != 1) ||
 							!valid_act_opt(i)) {
 				fprintf(stderr,
 					"Invalid set action mask %s/0x%x\n",
@@ -1810,6 +1816,17 @@ int main(int argc, char *argv[])
 			cat_mask_tmp = i;
 			break;
 
+		case 'm':
+			i = find_trace_map(optarg);
+			if (i < 0) {
+				fprintf(stderr,
+					"Invalid trace action mask %s\n",
+					optarg);
+				return 1;
+			}
+			trace_mask_tmp |= (1 << i);
+			break;
+
 		case 'd':
 			if (resize_devices(optarg) != 0)
 				return 1;
@@ -1820,8 +1837,8 @@ int main(int argc, char *argv[])
 			FILE *ifp = fopen(optarg, "r");
 
 			if (!ifp) {
-				fprintf(stderr, 
-				        "Invalid file for devices %s\n", 
+				fprintf(stderr,
+				        "Invalid file for devices %s\n",
 					optarg);
 				return 1;
 			}
@@ -1920,6 +1937,9 @@ int main(int argc, char *argv[])
 	if (cat_mask_tmp != 0)
 		cat_mask = cat_mask_tmp;
 
+	if (trace_mask_tmp != 0)
+		trace_mask = trace_mask_tmp;
+
 	if (!debugfs_path)
 		debugfs_path = default_debugfs_path;
 
blktrace.h +1 -0
index 816ce61..b26686d 100644
@@ -140,6 +140,7 @@ extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
 			unsigned long long, int, unsigned char *);
 extern int valid_act_opt(int);
 extern int find_mask_map(char *);
+extern int find_trace_map(char *);
 extern char *find_process_name(pid_t);
 
 #endif
blktrace_api.h +1 -0
index 2b76d76..8490fdc 100644
@@ -115,6 +115,7 @@ struct blk_io_trace_remap {
 struct blk_user_trace_setup {
 	char name[32];			/* output */
 	__u16 cat_mask;			/* input */
+	__u32 trace_mask;			/* input */
 	__u32 buf_size;			/* input */
 	__u32 buf_nr;			/* input */
 	__u64 start_lba;
doc/blktrace.tex +59 -31

201 lines not on this page · raw message

Signature · 1 line
1.5.4.3