00001
00010 #include <sys/time.h>
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <stdarg.h>
00014 #include <string.h>
00015 #include <misc/debug.h>
00016 #include <core/config.h>
00017 #include <core/tx.h>
00018
00019 void
00020 txc_debug_printmsg(char *file, int line, int fatal, const char *prefix,
00021 const char *strformat, ...)
00022 {
00023 char buf[512];
00024 va_list ap;
00025 int len;
00026 if (prefix) {
00027 len = sprintf(buf, "%s ", prefix);
00028 }
00029 if (file) {
00030 len += sprintf(&buf[len], "%s(%d)", file, line);
00031 }
00032 if (file || prefix) {
00033 len += sprintf(&buf[len], ": ");
00034 }
00035 va_start (ap, strformat);
00036 vsnprintf(&buf[len], sizeof (buf) - 1 - len, strformat, ap);
00037 va_end (ap);
00038 fprintf(TXC_DEBUG_OUT, "%s", buf);
00039 if (fatal) {
00040 exit(1);
00041 }
00042 }
00043
00044
00045 void
00046 txc_debug_printmsg_L(int debug_flag, const char *strformat, ...)
00047 {
00048 char msg[512];
00049 int len;
00050 va_list ap;
00051 struct timeval curtime;
00052 int xact_state;
00053 unsigned int tid;
00054 unsigned int tid_pthread;
00055
00056 if (!debug_flag) {
00057 return;
00058 }
00059
00060 xact_state = txc_tx_get_xactstate(txc_l_txd);
00061 tid = txc_tx_get_tid(txc_l_txd);
00062 tid_pthread = txc_tx_get_tid_pthread(txc_l_txd);
00063 gettimeofday(&curtime, NULL);
00064 len = sprintf(msg, "[TXC_DEBUG: T-%02u (%u) TS=%04u%06u TX=%d PC=%p] ",
00065 tid,
00066 tid_pthread,
00067 (unsigned int) curtime.tv_sec, (unsigned int) curtime.tv_usec,
00068 xact_state,
00069 __builtin_return_address(0));
00070 va_start (ap, strformat);
00071 vsnprintf(&msg[len], sizeof (msg) - 1 - len, strformat, ap);
00072 va_end (ap);
00073
00074 len = strlen(msg);
00075 msg[len] = '\0';
00076
00077 fprintf(TXC_DEBUG_OUT, "%s", msg);
00078 }