+#ifdef FIO_INC_DEBUG
+struct debug_level debug_levels[] = {
+ { .name = "process", .shift = FD_PROCESS, },
+ { .name = "file", .shift = FD_FILE, },
+ { .name = "io", .shift = FD_IO, },
+ { .name = "mem", .shift = FD_MEM, },
+ { .name = "blktrace", .shift = FD_BLKTRACE },
+ { .name = "verify", .shift = FD_VERIFY },
+ { .name = "random", .shift = FD_RANDOM },
+ { .name = "parse", .shift = FD_PARSE },
+ { .name = "diskutil", .shift = FD_DISKUTIL },
+ { .name = "job", .shift = FD_JOB },
+ { },
+};
+
+static int set_debug(const char *string)
+{
+ struct debug_level *dl;
+ char *p = (char *) string;
+ char *opt;
+ int i;
+
+ if (!strcmp(string, "?") || !strcmp(string, "help")) {
+ int i;
+
+ log_info("fio: dumping debug options:");
+ for (i = 0; debug_levels[i].name; i++) {
+ dl = &debug_levels[i];
+ log_info("%s,", dl->name);
+ }
+ log_info("all\n");
+ return 1;
+ }
+
+ while ((opt = strsep(&p, ",")) != NULL) {
+ int found = 0;
+
+ if (!strncmp(opt, "all", 3)) {
+ log_info("fio: set all debug options\n");
+ fio_debug = ~0UL;
+ continue;
+ }
+
+ for (i = 0; debug_levels[i].name; i++) {
+ dl = &debug_levels[i];
+ found = !strncmp(opt, dl->name, strlen(dl->name));
+ if (!found)
+ continue;
+
+ if (dl->shift == FD_JOB) {
+ opt = strchr(opt, ':');
+ if (!opt) {
+ log_err("fio: missing job number\n");
+ break;
+ }
+ opt++;
+ fio_debug_jobno = atoi(opt);
+ log_info("fio: set debug jobno %d\n",
+ fio_debug_jobno);
+ } else {
+ log_info("fio: set debug option %s\n", opt);
+ fio_debug |= (1UL << dl->shift);
+ }
+ break;
+ }
+
+ if (!found)
+ log_err("fio: debug mask %s not found\n", opt);
+ }
+ return 0;
+}
+#else
+static void set_debug(const char *string)
+{
+ log_err("fio: debug tracing not included in build\n");
+ return 1;
+}
+#endif
+