4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * libcfs/include/libcfs/lltrace.h
37 * cc -I../../portals/include -o fio fio.c -L../../portals/linux/utils -lptlctl
40 #ifndef __LIBCFS_LLTRACE_H__
41 #define __LIBCFS_LLTRACE_H__
43 #if defined(__linux__)
44 #include <libcfs/linux/lltrace.h>
45 #elif defined(__APPLE__)
46 #include <libcfs/darwin/lltrace.h>
47 #elif defined(__WINNT__)
48 #include <libcfs/winnt/lltrace.h>
50 #error Unsupported Operating System
53 static inline int ltrace_write_file(char* fname)
57 argv[0] = "debug_kernel";
61 fprintf(stderr, "[ptlctl] %s %s %s\n", argv[0], argv[1], argv[2]);
63 return jt_dbg_debug_kernel(3, argv);
66 static inline int ltrace_clear()
72 fprintf(stderr, "[ptlctl] %s\n", argv[0]);
74 return jt_dbg_clear_debug_buf(1, argv);
77 static inline int ltrace_mark(int indent_level, char* text)
80 char mark_buf[PATH_MAX];
82 snprintf(mark_buf, PATH_MAX, "====%d=%s", indent_level, text);
86 return jt_dbg_mark_debug_buf(2, argv);
89 static inline int ltrace_applymasks()
93 argv[1] = "applymasks";
95 fprintf(stderr, "[ptlctl] %s %s\n", argv[0], argv[1]);
97 return jt_dbg_list(2, argv);
101 static inline int ltrace_filter(char* subsys_or_mask)
105 argv[1] = subsys_or_mask;
106 return jt_dbg_filter(2, argv);
109 static inline int ltrace_show(char* subsys_or_mask)
113 argv[1] = subsys_or_mask;
114 return jt_dbg_show(2, argv);
117 static inline int ltrace_start()
120 dbg_initialize(0, NULL);
122 rc = register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
123 LNET_DEV_MAJOR, LNET_DEV_MINOR);
125 ltrace_filter("class");
126 ltrace_filter("nal");
127 ltrace_filter("portals");
129 ltrace_show("all_types");
130 ltrace_filter("trace");
131 ltrace_filter("malloc");
132 ltrace_filter("net");
133 ltrace_filter("page");
134 ltrace_filter("other");
135 ltrace_filter("info");
142 static inline void ltrace_stop()
145 unregister_ioc_dev(LNET_DEV_ID);
149 static inline int not_uml()
152 * 0 when run under UML
154 * <0 when lookup failed
157 int rc = stat("/dev/ubd", &buf);
158 rc = ((rc<0) && (errno == ENOENT)) ? 1 : rc;
160 fprintf(stderr, "Cannot stat /dev/ubd: %s\n", strerror(errno));
161 rc = 1; /* Assume host */
166 #define LTRACE_MAX_NOB 256
167 static inline void ltrace_add_processnames(char* fname)
169 char cmdbuf[LTRACE_MAX_NOB];
173 int underuml = !not_uml();
175 gettimeofday(&tv, &tz);
177 nob = snprintf(cmdbuf, LTRACE_MAX_NOB, "ps --no-headers -eo \"");
179 /* Careful - these format strings need to match the CDEBUG
180 * formats in portals/linux/debug.c EXACTLY
182 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, "%02x:%06x:%d:%lu.%06lu ",
183 S_RPC >> 24, D_VFSTRACE, 0, tv.tv_sec, tv.tv_usec);
184 nob += snprintf (cmdbuf+nob, LTRACE_MAX_NOB, "(%s:%d:%s() %d+%lu): ",
185 "lltrace.h", __LINE__, __FUNCTION__, 0, 0L);
186 nob += snprintf(cmdbuf+nob, LTRACE_MAX_NOB, " %%p %%c\" >> %s", fname);