xymon

Check-in [c1798f3557]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:dbgprintf macro optimization; logging tuning, print usecs; add logprintf stub git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7506 44351d6e-118b-4698-b696-ce33095ecaa4
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | origin/4.3.19
Files: files | file ages | folders
SHA3-256: c1798f35572bf64262e0e1720dd88012950fec2d5b127d41c0d52cc8cd95e163
User & Date: jccleaver@users.sf.net 2015-02-10 13:57:07
Context
2015-02-11
14:43
expand xymondboard filters to add'l boardfield types, including timestamp inequalities git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7507 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: a5414c4fe9 user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
2015-02-10
13:57
dbgprintf macro optimization; logging tuning, print usecs; add logprintf stub git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7506 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: c1798f3557 user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
2015-02-08
03:54
BSD client fixes, from Mark Felder git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7505 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: da5e523b57 user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/errormsg.c.

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
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84


85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*                                                                            */
/*----------------------------------------------------------------------------*/

static char rcsid[] = "$Id$";

#include <sys/types.h>
#include <string.h>

#include <time.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>

#include "libxymon.h"

char *errbuf = NULL;





int save_errbuf = 1;
static unsigned int errbufsize = 0;
static char *errappname = NULL;

int debug = 0;
static FILE *tracefd = NULL;
static FILE *debugfd = NULL;

void errprintf(const char *fmt, ...)
{
	char timestr[30];
	char msg[4096];
	va_list args;

	time_t now = getcurrenttime(NULL);

	MEMDEFINE(timestr);
	MEMDEFINE(msg);

	strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&now));
	fprintf(stderr, "%s ", timestr);
	if (errappname) fprintf(stderr, "%s ", errappname);

	va_start(args, fmt);
	vsnprintf(msg, sizeof(msg), fmt, args);
	va_end(args);

	fprintf(stderr, "%s", msg);
................................................................................
		else if ((strlen(errbuf) + strlen(msg)) > errbufsize) {
			errbufsize += 8192;
			errbuf = (char *) realloc(errbuf, errbufsize);
		}

		strcat(errbuf, msg);
	}

	MEMUNDEFINE(timestr);
	MEMUNDEFINE(msg);
}


void dbgprintf(const char *fmt, ...)
{
	if (debug) {
		va_list args;
		char timestr[30];
		time_t now = getcurrenttime(NULL);




		MEMDEFINE(timestr);


		if (!debugfd) debugfd = stdout;

		strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S",
			 localtime(&now));
		fprintf(debugfd, "%lu %s ", (unsigned long)getpid(), timestr);

		va_start(args, fmt);
		vfprintf(debugfd, fmt, args);
		va_end(args);
		fflush(debugfd);

		MEMUNDEFINE(timestr);
	}
}

void flush_errbuf(void)
{
	if (errbuf) xfree(errbuf);
	errbuf = NULL;
}







>











>
>
>
>
>










|
|
|
|
|
|
|
|
<
<
<







 







<
<
<



|

<
|
<
<
>

>
>
|
>
|
<

|
<
<

|
|
|
|
<
<
<







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
..
68
69
70
71
72
73
74



75
76
77
78
79

80


81
82
83
84
85
86
87

88
89


90
91
92
93
94



95
96
97
98
99
100
101
/*                                                                            */
/*----------------------------------------------------------------------------*/

static char rcsid[] = "$Id$";

#include <sys/types.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>

#include "libxymon.h"

char *errbuf = NULL;
static char msg[4096];
static char timestr[20];
static size_t timesize = sizeof(timestr);
static struct timeval now;
static time_t then = 0;
int save_errbuf = 1;
static unsigned int errbufsize = 0;
static char *errappname = NULL;

int debug = 0;
static FILE *tracefd = NULL;
static FILE *debugfd = NULL;

void errprintf(const char *fmt, ...)
{
	va_list args;
	gettimeofday(&now, NULL);

	if (now.tv_sec != then) {
		strftime(timestr, timesize, "%Y-%m-%d %H:%M:%S", localtime(&now.tv_sec));
		then = now.tv_sec;
	}
	fprintf(stderr, "%s.%06d ", timestr, (int) now.tv_usec);



	if (errappname) fprintf(stderr, "%s ", errappname);

	va_start(args, fmt);
	vsnprintf(msg, sizeof(msg), fmt, args);
	va_end(args);

	fprintf(stderr, "%s", msg);
................................................................................
		else if ((strlen(errbuf) + strlen(msg)) > errbufsize) {
			errbufsize += 8192;
			errbuf = (char *) realloc(errbuf, errbufsize);
		}

		strcat(errbuf, msg);
	}



}


void real_dbgprintf(const char *fmt, ...)
{

	va_list args;


	gettimeofday(&now, NULL);

	if (!debugfd) debugfd = stdout;
	if (now.tv_sec != then) {
		strftime(timestr, timesize, "%Y-%m-%d %H:%M:%S", localtime(&now.tv_sec));
		then = now.tv_sec;
	}


	fprintf(debugfd, "%lu %s.%06d ", (unsigned long)getpid(), timestr, (int) now.tv_usec);



	va_start(args, fmt);
	vfprintf(debugfd, fmt, args);
	va_end(args);
	fflush(debugfd);



}

void flush_errbuf(void)
{
	if (errbuf) xfree(errbuf);
	errbuf = NULL;
}

Changes to lib/errormsg.h.

14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>

extern char *errbuf;
extern int save_errbuf;
extern int debug;

extern void errprintf(const char *fmt, ...);
extern void dbgprintf(const char *fmt, ...);


extern void flush_errbuf(void);
extern void set_debugfile(char *fn, int appendtofile);

extern void starttrace(const char *fn);
extern void stoptrace(void);
extern void traceprintf(const char *fmt, ...);

extern void redirect_cgilog(char *cginame);
extern void reopen_file(char *fn, char *mode, FILE *fd);

#endif








|
>
>












14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>

extern char *errbuf;
extern int save_errbuf;
extern int debug;

extern void errprintf(const char *fmt, ...);
extern void real_dbgprintf(const char *fmt, ...);
#define dbgprintf(...) { if (debug) real_dbgprintf(__VA_ARGS__); }
#define logprintf(...) printf(__VA_ARGS__);
extern void flush_errbuf(void);
extern void set_debugfile(char *fn, int appendtofile);

extern void starttrace(const char *fn);
extern void stoptrace(void);
extern void traceprintf(const char *fmt, ...);

extern void redirect_cgilog(char *cginame);
extern void reopen_file(char *fn, char *mode, FILE *fd);

#endif

Changes to xymond/xymond_client.c.

1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
				/* We'll use the secondary key */
				cmdofs = (p - psstr);
			}
		}
	}
	if (eol) *eol = '\n';

	if (debug) {
		if (cmdofs >= 0) dbgprintf("Host %s: Found ps command line at offset %d\n", hostname, cmdofs);
		else dbgprintf("Host %s: None of the headings found\n", hostname);
	}

	pchecks = clear_process_counts(hinfo, clientclass);

	if (pchecks == 0) {
		/* Nothing to check */
		sprintf(msgline, "&%s No process checks defined\n", colorname(noreportcolor));
		addtobuffer(monmsg, msgline);







<
|
|
<







1050
1051
1052
1053
1054
1055
1056

1057
1058

1059
1060
1061
1062
1063
1064
1065
				/* We'll use the secondary key */
				cmdofs = (p - psstr);
			}
		}
	}
	if (eol) *eol = '\n';


	if (cmdofs >= 0) { dbgprintf("Host %s: Found ps command line at offset %d\n", hostname, cmdofs); }
	else { dbgprintf("Host %s: None of the headings found\n", hostname); }


	pchecks = clear_process_counts(hinfo, clientclass);

	if (pchecks == 0) {
		/* Nothing to check */
		sprintf(msgline, "&%s No process checks defined\n", colorname(noreportcolor));
		addtobuffer(monmsg, msgline);

Changes to xymond/xymond_filestore.c.

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
	if (wanted == NULL) return 1;

	ckey = (char *)malloc(strlen(key) + 3);
	sprintf(ckey, ",%s,", key);
	p = strstr(wanted, ckey);
	xfree(ckey);

	if (p) dbgprintf("wantedtest: Found '%s' at '%s'\n", key, p);
	else dbgprintf("wantedtest: '%s' not found\n", key);

	return (p != NULL);
}

int main(int argc, char *argv[])
{
	char *filedir = NULL;
................................................................................
		return 1;
	}

	/* For picking up lost children */
	setup_signalhandler("xymond_filestore");
	signal(SIGPIPE, SIG_DFL);

	if (onlytests) dbgprintf("Storing tests '%s' only\n", onlytests);
	else dbgprintf("Storing all tests\n");

	while (running) {
		char *metadata[20] = { NULL, };
		char *statusdata = "";
		char *p;
		int metacount;
		char *hostname, *testname;







|
<







 







|
<







169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
...
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
	if (wanted == NULL) return 1;

	ckey = (char *)malloc(strlen(key) + 3);
	sprintf(ckey, ",%s,", key);
	p = strstr(wanted, ckey);
	xfree(ckey);

	dbgprintf("wantedtest: Found '%s' at '%s'\n", key, (p ? p : "<not found>"));


	return (p != NULL);
}

int main(int argc, char *argv[])
{
	char *filedir = NULL;
................................................................................
		return 1;
	}

	/* For picking up lost children */
	setup_signalhandler("xymond_filestore");
	signal(SIGPIPE, SIG_DFL);

	dbgprintf("Storing tests: %s\n", (onlytests ? onlytests : "<all>"));


	while (running) {
		char *metadata[20] = { NULL, };
		char *statusdata = "";
		char *p;
		int metacount;
		char *hostname, *testname;