1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/lltrace.h
39 * cc -I../../portals/include -o fio fio.c -L../../portals/linux/utils -lptlctl
42 #ifndef __LIBCFS_LLTRACE_H__
43 #define __LIBCFS_LLTRACE_H__
45 #if defined(__linux__)
46 #include <libcfs/linux/lltrace.h>
47 #elif defined(__APPLE__)
48 #include <libcfs/darwin/lltrace.h>
49 #elif defined(__WINNT__)
50 #include <libcfs/winnt/lltrace.h>
52 #error Unsupported Operating System
55 static inline int ltrace_write_file(char* fname)
59 argv[0] = "debug_kernel";
63 fprintf(stderr, "[ptlctl] %s %s %s\n", argv[0], argv[1], argv[2]);
65 return jt_dbg_debug_kernel(3, argv);
68 static inline int ltrace_clear()
74 fprintf(stderr, "[ptlctl] %s\n", argv[0]);
76 return jt_dbg_clear_debug_buf(1, argv);
79 static inline int ltrace_mark(int indent_level, char* text)
82 char mark_buf[PATH_MAX];
84 snprintf(mark_buf, PATH_MAX, "====%d=%s", indent_level, text);
88 return jt_dbg_mark_debug_buf(2, argv);
91 static inline int ltrace_applymasks()
95 argv[1] = "applymasks";
97 fprintf(stderr, "[ptlctl] %s %s\n", argv[0], argv[1]);
99 return jt_dbg_list(2, argv);
103 static inline int ltrace_filter(char* subsys_or_mask)
107 argv[1] = subsys_or_mask;
108 return jt_dbg_filter(2, argv);
111 static inline int ltrace_show(char* subsys_or_mask)
115 argv[1] = subsys_or_mask;
116 return jt_dbg_show(2, argv);
119 static inline int ltrace_start()
122 dbg_initialize(0, NULL);
124 rc = register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
125 LNET_DEV_MAJOR, LNET_DEV_MINOR);
127 ltrace_filter("class");
128 ltrace_filter("nal");
129 ltrace_filter("portals");
131 ltrace_show("all_types");
132 ltrace_filter("trace");
133 ltrace_filter("malloc");
134 ltrace_filter("net");
135 ltrace_filter("page");
136 ltrace_filter("other");
137 ltrace_filter("info");
144 static inline void ltrace_stop()
147 unregister_ioc_dev(LNET_DEV_ID);
151 static inline int not_uml()
154 * 0 when run under UML
156 * <0 when lookup failed
159 int rc = stat("/dev/ubd", &buf);
160 rc = ((rc<0) && (errno == ENOENT)) ? 1 : rc;
162 fprintf(stderr, "Cannot stat /dev/ubd: %s\n", strerror(errno));
163 rc = 1; /* Assume host */
168 #define LTRACE_MAX_NOB 256
169 static inline void ltrace_add_processnames(char* fname)
171 char cmdbuf[LTRACE_MAX_NOB];
175 int underuml = !not_uml();
177 gettimeofday(&tv, &tz);
179 nob = snprintf(cmdbuf, LTRACE_MAX_NOB, "ps --no-headers -eo \"");
181 /* Careful - these format strings need to match the CDEBUG
182 * formats in portals/linux/debug.c EXACTLY
184 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, "%02x:%06x:%d:%lu.%06lu ",
185 S_RPC >> 24, D_VFSTRACE, 0, tv.tv_sec, tv.tv_usec);
187 if (underuml && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))) {
188 nob += snprintf (cmdbuf+nob, LTRACE_MAX_NOB,
189 "(%s:%d:%s() %d | %d+%lu): ",
190 "lltrace.h", __LINE__, __FUNCTION__, 0, 0, 0L);
193 nob += snprintf (cmdbuf+nob, LTRACE_MAX_NOB,
194 "(%s:%d:%s() %d+%lu): ",
195 "lltrace.h", __LINE__, __FUNCTION__, 0, 0L);
198 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, " %%p %%c\" >> %s", fname);