Whamcloud - gitweb
Land from b_hd_pid to HEAD
[fs/lustre-release.git] / lnet / ulnds / debug.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002 Cluster File Systems, Inc.
5  *   Author: Phil Schwan <phil@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <stdio.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <stdarg.h>
27 #include <sys/time.h>
28
29 int smp_processor_id = 1;
30 char debug_file_path[1024] = "/tmp/lustre-log";
31 char debug_file_name[1024];
32 FILE *debug_file_fd;
33
34 int portals_do_debug_dumplog(void *arg)
35 {
36         printf("Look in %s\n", debug_file_name);
37         return 0;
38 }
39
40
41 void portals_debug_print(void)
42 {
43         return;
44 }
45
46
47 void portals_debug_dumplog(void)
48 {
49         printf("Look in %s\n", debug_file_name);
50         return;
51 }
52
53
54 int portals_debug_init(unsigned long bufsize)
55
56         debug_file_fd = stdout;
57         return 0;
58 }
59
60 int portals_debug_cleanup(void)
61 {
62         return 0; //close(portals_debug_fd);
63 }
64
65 int portals_debug_clear_buffer(void)
66 {
67         return 0;
68 }
69
70 int portals_debug_mark_buffer(char *text)
71 {
72
73         fprintf(debug_file_fd, "*******************************************************************************\n");
74         fprintf(debug_file_fd, "DEBUG MARKER: %s\n", text);
75         fprintf(debug_file_fd, "*******************************************************************************\n");
76
77         return 0;
78 }
79
80 int portals_debug_copy_to_user(char *buf, unsigned long len)
81 {
82         return 0;
83 }
84
85 /* FIXME: I'm not very smart; someone smarter should make this better. */
86 void
87 portals_debug_msg (int subsys, int mask, char *file, const char *fn, 
88                    const int line, const char *format, ...)
89 {
90         va_list       ap;
91         unsigned long flags;
92         struct timeval tv;
93         int nob;
94
95
96         /* NB since we pass a non-zero sized buffer (at least) on the first
97          * print, we can be assured that by the end of all the snprinting,
98          * we _do_ have a terminated buffer, even if our message got truncated.
99          */
100
101         gettimeofday(&tv, NULL);
102
103         nob += fprintf(debug_file_fd,
104                               "%02x:%06x:%d:%lu.%06lu ",
105                               subsys >> 24, mask, smp_processor_id,
106                               tv.tv_sec, tv.tv_usec);
107
108         nob += fprintf(debug_file_fd,
109                             "(%s:%d:%s() %d+%ld): ",
110                             file, line, fn, 0,
111                             8192 - ((unsigned long)&flags & 8191UL));
112
113         va_start (ap, format);
114         nob += fprintf(debug_file_fd, format, ap);
115         va_end (ap);
116
117
118 }
119