1    	/*
2    	 * Copyright (c) 2011 Red Hat, Inc.
3    	 *
4    	 * All rights reserved.
5    	 *
6    	 * Author: Steven Dake <sdake@redhat.com>
7    	 *
8    	 * libqb is free software: you can redistribute it and/or modify
9    	 * it under the terms of the GNU Lesser General Public License as published by
10   	 * the Free Software Foundation, either version 2.1 of the License, or
11   	 * (at your option) any later version.
12   	 *
13   	 * libqb 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 Lesser General Public License for more details.
17   	 *
18   	 * You should have received a copy of the GNU Lesser General Public License
19   	 * along with libqb.  If not, see <http://www.gnu.org/licenses/>.
20   	 */
21   	#include "os_base.h"
22   	
23   	#include <qb/qbdefs.h>
24   	#include <qb/qbutil.h>
25   	#include <qb/qblog.h>
26   	
27   	#define ITERATIONS 50000
28   	static qb_util_stopwatch_t *sw;
29   	
30   	extern void log_dict_words(void);
31   	
32   	static void
33   	bm_finish (const char *operation)
34   	{
35   		qb_util_stopwatch_stop(sw);
36   	
(1) Event cond_true: Condition "strlen(operation) > 22", taking true branch.
37   		if (strlen (operation) > 22) {
38   			printf ("%s\t\t", operation);
(2) Event if_fallthrough: Falling through to end of if statement.
39   		} else {
40   			printf ("%s\t\t\t", operation);
(3) Event if_end: End of if statement.
41   		}
(4) Event zero_return: Function call "qb_util_stopwatch_sec_elapsed_get(sw)" returns 0.0. [details]
(5) Event divide_by_zero: In expression "50000f / qb_util_stopwatch_sec_elapsed_get(sw)", division by expression "qb_util_stopwatch_sec_elapsed_get(sw)" which may be zero results in either +infinity, -infinity, or NaN.
42   		printf("%9.3f operations/sec\n",
43   		       ((float)ITERATIONS) /  qb_util_stopwatch_sec_elapsed_get(sw));
44   	}
45   	
46   	int
47   	main(void)
48   	{
49   		int i;
50   	
51   		sw =  qb_util_stopwatch_create();
52   		qb_log_init("simple-log", LOG_USER, LOG_INFO);
53   		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_THREADED, QB_TRUE);
54   	
55   		qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD,
56   		QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
57   		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, 128000);
58   		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_THREADED, QB_FALSE);
59   		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE);
60   	
61   		printf ("heating up cache with qb_log functionality\n");
62   		for (i = 0; i < ITERATIONS; i++) {
63   			qb_log(LOG_DEBUG, "hello");
64   		}
65   		qb_util_stopwatch_start(sw);
66   		for (i = 0; i < ITERATIONS; i++) {
67   			qb_log(LOG_DEBUG, "RecordA");
68   		}
69   		bm_finish ("qb_log 1 arguments:");
70   		qb_util_stopwatch_start(sw);
71   		for (i = 0; i < ITERATIONS; i++) {
72   			qb_log(LOG_DEBUG, "%s%s", "RecordA", "RecordB");
73   		}
74   		bm_finish ("qb_log 2 args(str):");
75   		qb_util_stopwatch_start(sw);
76   		for (i = 0; i < ITERATIONS; i++) {
77   			qb_log(LOG_DEBUG, "%s%s%s", "RecordA", "RecordB", "RecordC");
78   		}
79   		bm_finish ("qb_log 3 args(str):");
80   		qb_util_stopwatch_start(sw);
81   		for (i = 0; i < ITERATIONS; i++) {
82   			qb_log(LOG_DEBUG, "%i %u %p", -534, 4508, &i);
83   		}
84   		bm_finish ("qb_log 3 args(int):");
85   	#if defined(HAVE_DICT_WORDS) && defined(HAVE_SLOW_TESTS)
86   		qb_util_stopwatch_start(sw);
87   		log_dict_words();
88   		bm_finish ("qb_log /usr/share/dict/words:");
89   	#endif /* HAVE_DICT_WORDS */
90   	
91   		/* this will close the ringbuffer
92   		 */
93   		qb_log_fini();
94   	
95   		return 0;
96   	}
97