00001 #ifndef _PRINT_C_
00002 #define _PRINT_C_
00003
00004 #include <linux/config.h>
00005
00006 #include "io.c"
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define STP_PRINT_BUF_LEN 8000
00023
00024 static int _stp_pbuf_len[NR_CPUS];
00025
00026 #ifdef STP_NETLINK_ONLY
00027 #define STP_PRINT_BUF_START 0
00028 static char _stp_pbuf[NR_CPUS][STP_PRINT_BUF_LEN + 1];
00029
00030 void _stp_print_flush (void)
00031 {
00032 int cpu = smp_processor_id();
00033 char *buf = &_stp_pbuf[cpu][0];
00034 int len = _stp_pbuf_len[cpu];
00035
00036 if (len == 0)
00037 return;
00038
00039 if ( app.logging == 0) {
00040 _stp_pbuf_len[cpu] = 0;
00041 return;
00042 }
00043
00044
00045 if (buf[len - 1] != '\n') {
00046 buf[len++] = '\n';
00047 buf[len] = '\0';
00048 }
00049
00050 send_reply (STP_REALTIME_DATA, buf, len + 1, stpd_pid);
00051 _stp_pbuf_len[cpu] = 0;
00052 }
00053
00054 #else
00055
00056 #define TIMESTAMP_SIZE 19
00057 #define STP_PRINT_BUF_START (TIMESTAMP_SIZE + 1)
00058 static char _stp_pbuf[NR_CPUS][STP_PRINT_BUF_LEN + STP_PRINT_BUF_START + 1];
00059
00060
00061
00062
00063
00064
00065 void _stp_print_flush (void)
00066 {
00067 int cpu = smp_processor_id();
00068 char *buf = &_stp_pbuf[cpu][0];
00069 char *ptr = buf + STP_PRINT_BUF_START;
00070 struct timeval tv;
00071
00072 if (_stp_pbuf_len[cpu] == 0)
00073 return;
00074
00075
00076 if (ptr[_stp_pbuf_len[cpu]-1] != '\n') {
00077 ptr[_stp_pbuf_len[cpu]++] = '\n';
00078 ptr[_stp_pbuf_len[cpu]] = '\0';
00079 }
00080
00081 do_gettimeofday(&tv);
00082 scnprintf (buf, TIMESTAMP_SIZE+1, "[%li.%06li] ", tv.tv_sec, tv.tv_usec);
00083 buf[TIMESTAMP_SIZE] = ' ';
00084 relayapp_write(buf, _stp_pbuf_len[cpu] + TIMESTAMP_SIZE + 2);
00085 _stp_pbuf_len[cpu] = 0;
00086 }
00087 #endif
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 void _stp_printf (const char *fmt, ...)
00100 {
00101 int num;
00102 va_list args;
00103 int cpu = smp_processor_id();
00104 char *buf = &_stp_pbuf[cpu][STP_PRINT_BUF_START] + _stp_pbuf_len[cpu];
00105 va_start(args, fmt);
00106 num = vscnprintf(buf, STP_PRINT_BUF_LEN - _stp_pbuf_len[cpu], fmt, args);
00107 va_end(args);
00108 if (num > 0)
00109 _stp_pbuf_len[cpu] += num;
00110 }
00111
00112
00113
00114
00115
00116
00117 void _stp_vprintf (const char *fmt, va_list args)
00118 {
00119 int num;
00120 int cpu = smp_processor_id();
00121 char *buf = &_stp_pbuf[cpu][STP_PRINT_BUF_START] + _stp_pbuf_len[cpu];
00122 num = vscnprintf(buf, STP_PRINT_BUF_LEN -_stp_pbuf_len[cpu], fmt, args);
00123 if (num > 0)
00124 _stp_pbuf_len[cpu] += num;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 void _stp_print_cstr (const char *str)
00139 {
00140 int cpu = smp_processor_id();
00141 char *buf = &_stp_pbuf[cpu][STP_PRINT_BUF_START] + _stp_pbuf_len[cpu];
00142 int num = strlen (str);
00143 if (num > STP_PRINT_BUF_LEN - _stp_pbuf_len[cpu])
00144 num = STP_PRINT_BUF_LEN - _stp_pbuf_len[cpu];
00145 strncpy (buf, str, num+1);
00146 _stp_pbuf_len[cpu] += num;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156 char *_stp_print_clear (void)
00157 {
00158 int cpu = smp_processor_id();
00159 _stp_pbuf_len[cpu] = 0;
00160 return &_stp_pbuf[cpu][STP_PRINT_BUF_START];
00161 }
00162
00163 #include "string.c"
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 void _stp_print_string (String str)
00177 {
00178 if (str->len)
00179 _stp_print_cstr (str->buf);
00180 }
00181
00182
00183
00184
00185
00186
00187
00188 #define _stp_print(str) \
00189 ({ \
00190 if (__builtin_types_compatible_p (typeof (str), char[])) { \
00191 char *x = (char *)str; \
00192 _stp_print_cstr(x); \
00193 } else { \
00194 String x = (String)str; \
00195 _stp_print_string(x); \
00196 } \
00197 })
00198
00199
00200 #endif