t/btrace2fio: cap depth if we don't see completion traces

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/t/btrace2fio.c b/t/btrace2fio.c
index 32dda92..bf67ed0 100644
--- a/t/btrace2fio.c
+++ b/t/btrace2fio.c
@@ -19,6 +19,7 @@
 static unsigned int ios_threshold = 10;
 static unsigned int rate_threshold;
 static unsigned int set_rate;
+static unsigned int max_depth = 256;
 static int output_ascii = 1;
 static char *filename;
 
@@ -45,6 +46,9 @@
 
 	int inflight;
 	unsigned int depth;
+	int depth_disabled;
+	int complete_seen;
+
 	uint64_t first_ttime[DDIR_RWDIR_CNT];
 	uint64_t last_ttime[DDIR_RWDIR_CNT];
 	uint64_t kb[DDIR_RWDIR_CNT];
@@ -125,7 +129,13 @@
 	i = calloc(1, sizeof(*i));
 	i->p = p;
 	o->inflight++;
-	o->depth = max((int) o->depth, o->inflight);
+	if (!o->depth_disabled) {
+		o->depth = max((int) o->depth, o->inflight);
+		if (o->depth >= max_depth && !o->complete_seen) {
+			o->depth_disabled = 1;
+			o->depth = max_depth;
+		}
+	}
 	i->end_sector = sector + (len >> 9);
 	__inflight_add(i);
 }
@@ -383,6 +393,7 @@
 		i = inflight_find(t->sector + (t->bytes >> 9));
 		if (i) {
 			i->p->o.kb[t_to_rwdir(t)] += (t->bytes >> 10);
+			i->p->o.complete_seen = 1;
 			inflight_remove(i);
 		}
 	}
@@ -810,6 +821,7 @@
 {
 	unsigned long ios[DDIR_RWDIR_CNT];
 	struct flist_head *e, *tmp;
+	int depth_disabled = 0;
 	int ret = 0;
 
 	flist_for_each_safe(e, tmp, &pid_list) {
@@ -821,8 +833,12 @@
 			continue;
 		}
 		p->o.start_delay = (o_first_ttime(&p->o) / 1000ULL) - first_ttime;
+		depth_disabled += p->o.depth_disabled;
 	}
 
+	if (depth_disabled)
+		log_err("fio: missing completion traces, depths capped at %u\n", max_depth);
+
 	memset(ios, 0, sizeof(ios));
 
 	flist_sort(NULL, &pid_list, entry_cmp);
@@ -851,6 +867,7 @@
 	log_err("\t-d\tUse this file/device for replay\n");
 	log_err("\t-r\tIgnore jobs with less than this KB/sec rate\n");
 	log_err("\t-R\tSet rate in fio job\n");
+	log_err("\t-D\tCap queue depth at this value (def=%u)\n", max_depth);
 	return 1;
 }
 
@@ -906,7 +923,7 @@
 	if (argc < 2)
 		return usage(argv);
 
-	while ((c = getopt(argc, argv, "t:n:fd:r:R")) != -1) {
+	while ((c = getopt(argc, argv, "t:n:fd:r:RD:")) != -1) {
 		switch (c) {
 		case 'R':
 			set_rate = 1;
@@ -926,6 +943,9 @@
 		case 'd':
 			filename = strdup(optarg);
 			break;
+		case 'D':
+			max_depth = atoi(optarg);
+			break;
 		case '?':
 		default:
 			return usage(argv);