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=(char*)MALLOC(strlen(options)+1);
121 memcpy(p, options, strlen(options) + 1);
123 for (s = strtok(p, ":"); s; s = strtok(NULL, ":"))
130 debug_open_log(const char *logfile) {
131 #ifndef CONFIG_ORTE_RT
132 if (logfile == NULL) {
136 if (debug_log && debug_log != stderr)
138 debug_log = fopen(logfile, "a+");
140 fprintf(stderr, "WARNING: Cannot write log file: %s\n", logfile);
142 fprintf(stderr, " messages will be sent to 'stderr'.\n");
150 db_init(const char *logfile, const char *options) {
153 for (i = 0; i < MAX_DEBUG_SECTIONS; i++)
155 debug_options(options);
156 debug_open_log(logfile);
159 #ifdef ENABLE_MEM_CHECK
160 void *mem_check_malloc(size_t size) {
163 if ((ptr=malloc(size))) {
165 debug(1,9) ("mem check: inc %d\n",mem_check_counter);
170 void mem_check_free(void *ptr) {
172 // LOG_FATAL(KERN_CRIT "ul_mem_check_free : triing to free NULL ptr\n");
175 debug(1,9) ("mem check: dec %d\n",mem_check_counter);
179 #endif /* ENABLE_MEM_CHECK */