2 * $Id: debug.c,v 0.0.0.1 2003/08/21
4 * DEBUG: section 1 Debug
6 * -------------------------------------------------------------------
8 * Open Real-Time Ethernet
10 * Copyright (C) 2001-2006
11 * Department of Control Engineering FEE CTU Prague, Czech Republic
12 * http://dce.felk.cvut.cz
13 * http://www.ocera.org
15 * Author: Petr Smolik petr@smoliku.cz
17 * Project Responsible: Zdenek Hanzalek
18 * --------------------------------------------------------------------
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
34 /* global debug variables */
36 int debugLevels[MAX_DEBUG_SECTIONS];
37 int mem_check_counter = 0;
38 NtpTime zNtpTime, iNtpTime;
39 SequenceNumber noneSN;
41 /*********************************************************************/
42 /* forvard declarations */
44 db_print_output(const char *format);
46 /*********************************************************************/
49 #ifndef CONFIG_ORTE_RT
50 FILE *debug_log = NULL; /* NULL */
53 /*********************************************************************/
63 clock_gettime(CLOCK_REALTIME, &time);
64 sprintf(buf, "%li.%03li", time.tv_sec, time.tv_nsec/1000000);
74 gettimeofday(&time, NULL);
75 sprintf(buf, "%li.%03li", time.tv_sec, time.tv_usec/1000);
78 #endif /* CONFIG_ORTE_RT */
81 db_print(const char *format, ...)
87 sprintf(f, "%s | ", debug_log_time());
88 vsprintf(f+strlen(f), format, ap);
94 db_print_output(const char *format)
96 #ifndef CONFIG_ORTE_RT
97 if (debug_log == NULL)
99 fprintf(debug_log, "%s", format);
107 debug_arg(const char *arg)
109 int32_t s = 0, l = 0, i;
111 if (!strncmp(arg, "ALL", 3)) {
116 while (*arg && *arg++ != '.') ;
127 for (i = 0; i < MAX_DEBUG_SECTIONS; i++)
132 debug_options(const char *options)
138 p = (char *)MALLOC(strlen(options)+1);
140 memcpy(p, options, strlen(options) + 1);
142 for (s = strtok(p, ":"); s; s = strtok(NULL, ":"))
149 debug_open_log(const char *logfile)
151 #ifndef CONFIG_ORTE_RT
152 if (logfile == NULL) {
156 if (debug_log && debug_log != stderr)
158 debug_log = fopen(logfile, "a+");
160 fprintf(stderr, "WARNING: Cannot write log file: %s\n", logfile);
162 fprintf(stderr, " messages will be sent to 'stderr'.\n");
170 db_init(const char *logfile, const char *options)
174 for (i = 0; i < MAX_DEBUG_SECTIONS; i++)
176 debug_options(options);
177 debug_open_log(logfile);
180 #ifdef ENABLE_MEM_CHECK
182 mem_check_malloc(size_t size)
186 if ((ptr = malloc(size))) {
188 debug(1, 9) ("mem check: inc %d\n", mem_check_counter);
194 mem_check_free(void *ptr)
197 // LOG_FATAL(KERN_CRIT "ul_mem_check_free : triing to free NULL ptr\n");
200 debug(1, 9) ("mem check: dec %d\n", mem_check_counter);
204 #endif /* ENABLE_MEM_CHECK */