1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * cc -I../../portals/include -o fio fio.c -L../../portals/linux/utils -lptlctl
7 #ifndef __LIBCFS_LLTRACE_H__
8 #define __LIBCFS_LLTRACE_H__
10 #if defined(__linux__)
11 #include <libcfs/linux/lltrace.h>
12 #elif defined(__APPLE__)
13 #include <libcfs/darwin/lltrace.h>
15 #error Unsupported Operating System
18 static inline int ltrace_write_file(char* fname)
22 argv[0] = "debug_kernel";
26 fprintf(stderr, "[ptlctl] %s %s %s\n", argv[0], argv[1], argv[2]);
28 return jt_dbg_debug_kernel(3, argv);
31 static inline int ltrace_clear()
37 fprintf(stderr, "[ptlctl] %s\n", argv[0]);
39 return jt_dbg_clear_debug_buf(1, argv);
42 static inline int ltrace_mark(int indent_level, char* text)
45 char mark_buf[PATH_MAX];
47 snprintf(mark_buf, PATH_MAX, "====%d=%s", indent_level, text);
51 return jt_dbg_mark_debug_buf(2, argv);
54 static inline int ltrace_applymasks()
58 argv[1] = "applymasks";
60 fprintf(stderr, "[ptlctl] %s %s\n", argv[0], argv[1]);
62 return jt_dbg_list(2, argv);
66 static inline int ltrace_filter(char* subsys_or_mask)
70 argv[1] = subsys_or_mask;
71 return jt_dbg_filter(2, argv);
74 static inline int ltrace_show(char* subsys_or_mask)
78 argv[1] = subsys_or_mask;
79 return jt_dbg_show(2, argv);
82 static inline int ltrace_start()
85 dbg_initialize(0, NULL);
87 rc = register_ioc_dev(PORTALS_DEV_ID, PORTALS_DEV_PATH);
89 ltrace_filter("class");
91 ltrace_filter("portals");
93 ltrace_show("all_types");
94 ltrace_filter("trace");
95 ltrace_filter("malloc");
97 ltrace_filter("page");
98 ltrace_filter("other");
99 ltrace_filter("info");
106 static inline void ltrace_stop()
108 #ifdef PORTALS_DEV_ID
109 unregister_ioc_dev(PORTALS_DEV_ID);
113 static inline int not_uml()
116 * 0 when run under UML
118 * <0 when lookup failed
121 int rc = stat("/dev/ubd", &buf);
122 rc = ((rc<0) && (errno == ENOENT)) ? 1 : rc;
124 fprintf(stderr, "Cannot stat /dev/ubd: %s\n", strerror(errno));
125 rc = 1; /* Assume host */
130 #define LTRACE_MAX_NOB 256
131 static inline void ltrace_add_processnames(char* fname)
133 char cmdbuf[LTRACE_MAX_NOB];
137 int underuml = !not_uml();
139 gettimeofday(&tv, &tz);
141 nob = snprintf(cmdbuf, LTRACE_MAX_NOB, "ps --no-headers -eo \"");
143 /* Careful - these format strings need to match the CDEBUG
144 * formats in portals/linux/debug.c EXACTLY
146 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, "%02x:%06x:%d:%lu.%06lu ",
147 S_RPC >> 24, D_VFSTRACE, 0, tv.tv_sec, tv.tv_usec);
149 if (underuml && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))) {
150 nob += snprintf (cmdbuf+nob, LTRACE_MAX_NOB,
151 "(%s:%d:%s() %d | %d+%lu): ",
152 "lltrace.h", __LINE__, __FUNCTION__, 0, 0, 0L);
155 nob += snprintf (cmdbuf+nob, LTRACE_MAX_NOB,
156 "(%s:%d:%s() %d+%lu): ",
157 "lltrace.h", __LINE__, __FUNCTION__, 0, 0L);
160 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, " %%p %%c\" >> %s", fname);