2 * $Id: debug.c,v 0.0.0.1 2003/08/21
4 * DEBUG: section 1 Debug
5 * AUTHOR: Petr Smolik petr.smolik@wo.cz
7 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
8 * --------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 /* global debug variables */
26 int debugLevels[MAX_DEBUG_SECTIONS];
27 int mem_check_counter=0;
28 NtpTime zNtpTime,iNtpTime;
29 SequenceNumber noneSN;
31 /*********************************************************************/
32 /* forvard declarations */
34 db_print_output(const char *format);
36 /*********************************************************************/
39 #ifndef CONFIG_ORTE_RT
40 FILE *debug_log=NULL; /* NULL */
43 /*********************************************************************/
48 debug_log_time(void) {
52 clock_gettime(CLOCK_REALTIME, &time);
53 sprintf(buf, "%li.%03li", time.tv_sec,time.tv_nsec/1000000);
58 debug_log_time(void) {
62 gettimeofday(&time,NULL);
63 sprintf(buf, "%li.%03li", time.tv_sec,time.tv_usec/1000);
66 #endif /* CONFIG_ORTE_RT */
69 db_print(const char *format,...) {
74 sprintf(f, "%s | ",debug_log_time());
75 vsprintf(f+strlen(f),format,ap);
81 db_print_output(const char *format) {
82 #ifndef CONFIG_ORTE_RT
83 if (debug_log == NULL) return;
84 fprintf(debug_log, format);
92 debug_arg(const char *arg) {
95 if (!strncmp(arg, "ALL", 3)) {
100 while (*arg && *arg++ != '.');
109 for (i = 0; i < MAX_DEBUG_SECTIONS; i++)
114 debug_options(const char *options) {
119 p = strdup((char *)options);
120 for (s = strtok(p, ":"); s; s = strtok(NULL, ":"))
127 debug_open_log(const char *logfile) {
128 #ifndef CONFIG_ORTE_RT
129 if (logfile == NULL) {
133 if (debug_log && debug_log != stderr)
135 debug_log = fopen(logfile, "a+");
137 fprintf(stderr, "WARNING: Cannot write log file: %s\n", logfile);
139 fprintf(stderr, " messages will be sent to 'stderr'.\n");
147 db_init(const char *logfile, const char *options) {
150 for (i = 0; i < MAX_DEBUG_SECTIONS; i++)
152 debug_options(options);
153 debug_open_log(logfile);
156 #ifdef ENABLE_MEM_CHECK
157 void *mem_check_malloc(size_t size) {
160 if ((ptr=malloc(size))) {
162 debug(1,9) ("mem check: inc %d\n",mem_check_counter);
167 void mem_check_free(void *ptr) {
169 // LOG_FATAL(KERN_CRIT "ul_mem_check_free : triing to free NULL ptr\n");
172 debug(1,9) ("mem check: dec %d\n",mem_check_counter);
176 #endif /* ENABLE_MEM_CHECK */