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 /*********************************************************************/
58 debug_log_time(void) {
62 clock_gettime(CLOCK_REALTIME, &time);
63 sprintf(buf, "%li.%03li", time.tv_sec,time.tv_nsec/1000000);
68 debug_log_time(void) {
72 gettimeofday(&time,NULL);
73 sprintf(buf, "%li.%03li", time.tv_sec,time.tv_usec/1000);
76 #endif /* CONFIG_ORTE_RT */
79 db_print(const char *format,...) {
84 sprintf(f, "%s | ",debug_log_time());
85 vsprintf(f+strlen(f),format,ap);
91 db_print_output(const char *format) {
92 #ifndef CONFIG_ORTE_RT
93 if (debug_log == NULL) return;
94 fprintf(debug_log, "%s", format);
102 debug_arg(const char *arg) {
105 if (!strncmp(arg, "ALL", 3)) {
110 while (*arg && *arg++ != '.');
119 for (i = 0; i < MAX_DEBUG_SECTIONS; i++)
124 debug_options(const char *options) {
129 p=(char*)MALLOC(strlen(options)+1);
131 memcpy(p, options, strlen(options) + 1);
133 for (s = strtok(p, ":"); s; s = strtok(NULL, ":"))
140 debug_open_log(const char *logfile) {
141 #ifndef CONFIG_ORTE_RT
142 if (logfile == NULL) {
146 if (debug_log && debug_log != stderr)
148 debug_log = fopen(logfile, "a+");
150 fprintf(stderr, "WARNING: Cannot write log file: %s\n", logfile);
152 fprintf(stderr, " messages will be sent to 'stderr'.\n");
160 db_init(const char *logfile, const char *options) {
163 for (i = 0; i < MAX_DEBUG_SECTIONS; i++)
165 debug_options(options);
166 debug_open_log(logfile);
169 #ifdef ENABLE_MEM_CHECK
170 void *mem_check_malloc(size_t size) {
173 if ((ptr=malloc(size))) {
175 debug(1,9) ("mem check: inc %d\n",mem_check_counter);
180 void mem_check_free(void *ptr) {
182 // LOG_FATAL(KERN_CRIT "ul_mem_check_free : triing to free NULL ptr\n");
185 debug(1,9) ("mem check: dec %d\n",mem_check_counter);
189 #endif /* ENABLE_MEM_CHECK */