1 /* toolbox/loging.c - contains loging functions
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Reinhard Grafl
30 $Id: loging.c 750 2003-12-13 22:17:44Z twisti $
38 #include <sys/resource.h>
44 /***************************************************************************
46 ***************************************************************************/
52 void log_init(char *fname)
56 logfile = fopen(fname, "w");
62 /*********************** Function: dolog ************************************
64 Writes logtext to the protocol file (if opened) or to stdout.
66 **************************************************************************/
68 void dolog(char *txt, ...)
70 char logtext[MAXLOGTEXT];
74 vsprintf(logtext, txt, ap);
78 fprintf(logfile, "%s\n",logtext);
82 fprintf(stdout,"LOG: %s\n",logtext);
88 /******************** Function: dolog_plain *******************************
90 Writes logtext to the protocol file (if opened) or to stdout.
92 **************************************************************************/
94 void dolog_plain(char *txt, ...)
96 char logtext[MAXLOGTEXT];
100 vsprintf(logtext, txt, ap);
104 fprintf(logfile, "%s",logtext);
108 fprintf(stdout,"%s",logtext);
114 /********************* Function: log_text ********************************/
116 void log_text(char *text)
122 /******************** Function: log_plain *******************************/
124 void log_plain(char *text)
126 dolog_plain("%s", text);
130 /****************** Function: get_logfile *******************************/
134 return (logfile) ? logfile : stdout;
138 /****************** Function: log_flush *********************************/
142 fflush(get_logfile());
146 /********************* Function: log_nl *********************************/
151 fflush(get_logfile());
155 /********************* Function: log_cputime ****************************/
161 char logtext[MAXLOGTEXT];
167 sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
173 /************************** Function: error *******************************
175 Like dolog(), but terminates the program immediately.
177 **************************************************************************/
179 void error(char *txt, ...)
181 char logtext[MAXLOGTEXT];
185 vsprintf(logtext, txt, ap);
189 fprintf(logfile, "ERROR: %s\n", logtext);
192 fprintf(stderr, "ERROR: %s\n", logtext);
197 /************************ Function: panic (txt) ****************************
199 Like error(), takes the text to output as an argument
201 ***************************************************************************/
203 void panic(char *txt)
209 /********************** Function: getcputime ********************************
211 Returns the used CPU time in microseconds
213 ****************************************************************************/
220 getrusage(RUSAGE_SELF, &ru);
221 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
222 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
224 return sec * 1000000 + usec;
229 * These are local overrides for various environment variables in Emacs.
230 * Please do not remove this and leave it at the end of the file, where
231 * Emacs will automagically detect them.
232 * ---------------------------------------------------------------------
235 * indent-tabs-mode: t