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
15 #include <sys/types.h>
20 #include <portals/types.h>
21 #include <linux/kp30.h>
22 #include <portals/ptlctl.h>
23 #include <linux/limits.h>
25 #include <linux/version.h>
27 static inline int ltrace_write_file(char* fname)
31 argv[0] = "debug_kernel";
35 fprintf(stderr, "[ptlctl] %s %s %s\n", argv[0], argv[1], argv[2]);
37 return jt_dbg_debug_kernel(3, argv);
40 static inline int ltrace_clear()
46 fprintf(stderr, "[ptlctl] %s\n", argv[0]);
48 return jt_dbg_clear_debug_buf(1, argv);
51 static inline int ltrace_mark(int indent_level, char* text)
54 char mark_buf[PATH_MAX];
56 snprintf(mark_buf, PATH_MAX, "====%d=%s", indent_level, text);
60 return jt_dbg_mark_debug_buf(2, argv);
63 static inline int ltrace_applymasks()
67 argv[1] = "applymasks";
69 fprintf(stderr, "[ptlctl] %s %s\n", argv[0], argv[1]);
71 return jt_dbg_list(2, argv);
75 static inline int ltrace_filter(char* subsys_or_mask)
79 argv[1] = subsys_or_mask;
80 return jt_dbg_filter(2, argv);
83 static inline int ltrace_show(char* subsys_or_mask)
87 argv[1] = subsys_or_mask;
88 return jt_dbg_show(2, argv);
91 static inline int ltrace_start()
94 dbg_initialize(0, NULL);
96 rc = register_ioc_dev(PORTALS_DEV_ID, PORTALS_DEV_PATH);
98 ltrace_filter("class");
99 ltrace_filter("socknal");
100 ltrace_filter("qswnal");
101 ltrace_filter("gmnal");
102 ltrace_filter("portals");
104 ltrace_show("all_types");
105 ltrace_filter("trace");
106 ltrace_filter("malloc");
107 ltrace_filter("net");
108 ltrace_filter("page");
109 ltrace_filter("other");
110 ltrace_filter("info");
117 static inline void ltrace_stop()
119 #ifdef PORTALS_DEV_ID
120 unregister_ioc_dev(PORTALS_DEV_ID);
124 static inline int not_uml()
127 * 0 when run under UML
129 * <0 when lookup failed
132 int rc = stat("/dev/ubd", &buf);
133 rc = ((rc<0) && (errno == ENOENT)) ? 1 : rc;
135 fprintf(stderr, "Cannot stat /dev/ubd: %s\n", strerror(errno));
136 rc = 1; /* Assume host */
141 #define LTRACE_MAX_NOB 256
142 static inline void ltrace_add_processnames(char* fname)
144 char cmdbuf[LTRACE_MAX_NOB];
148 int underuml = !not_uml();
150 gettimeofday(&tv, &tz);
152 nob = snprintf(cmdbuf, LTRACE_MAX_NOB, "ps --no-headers -eo \"");
154 /* Careful - these format strings need to match the CDEBUG
155 * formats in portals/linux/debug.c EXACTLY
157 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, "%02x:%06x:%d:%lu.%06lu ",
158 S_RPC >> 24, D_VFSTRACE, 0, tv.tv_sec, tv.tv_usec);
160 if (underuml && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))) {
161 nob += snprintf (cmdbuf+nob, LTRACE_MAX_NOB,
162 "(%s:%d:%s() %d | %d+%lu): ",
163 "lltrace.h", __LINE__, __FUNCTION__, 0, 0, 0L);
166 nob += snprintf (cmdbuf+nob, LTRACE_MAX_NOB,
167 "(%s:%d:%s() %d+%lu): ",
168 "lltrace.h", __LINE__, __FUNCTION__, 0, 0L);
171 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, " %%p %%c\" >> %s", fname);