forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace.c
71 lines (59 loc) · 2.09 KB
/
trace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Copyright 2015 Bloomberg Finance L.P.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <time.h>
#include <pthread.h>
#include "locks_wrap.h"
#include "net.h"
#include "net_int.h"
#include "logmsg.h"
enum {
NETTRCF_SUPPRESS = 1 /* suppress this trace if if distress mode */
};
static pthread_mutex_t trace_lock = PTHREAD_MUTEX_INITIALIZER;
static void host_node_vprintf(loglvl lvl, host_node_type *host_node_ptr,
int flags, const char *fmt, va_list ap)
{
struct netinfo_struct *netinfo_ptr = host_node_ptr->netinfo_ptr;
/* While my net changes bed in, I want to see all trace even if in
* "distress" mode. Later perhaps we can redirect this to ctrace. */
/*
if((flags & NETTRCF_SUPPRESS) && host_node_ptr->distress)
return;
*/
Pthread_mutex_lock(&trace_lock);
logmsg(lvl, "%08lx [%s %s%s fd %d] ", pthread_self(), netinfo_ptr->service,
host_node_ptr->host, host_node_ptr->subnet, host_node_ptr->fd);
logmsgv(lvl, fmt, ap);
Pthread_mutex_unlock(&trace_lock);
}
void host_node_printf(loglvl lvl, host_node_type *host_node_ptr, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
host_node_vprintf(lvl, host_node_ptr, NETTRCF_SUPPRESS, fmt, ap);
va_end(ap);
}
void host_node_errf(loglvl lvl, host_node_type *host_node_ptr, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
host_node_vprintf(lvl, host_node_ptr, 0, fmt, ap);
va_end(ap);
}