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 684 2003-12-02 16:50:17Z twisti $
37 #include <sys/resource.h>
43 /***************************************************************************
45 ***************************************************************************/
47 char logtext[MAXLOGTEXT]; /* Needs to be filled with desired text before */
55 void log_init(char *fname)
59 logfile = fopen(fname, "w");
65 /*********************** Function: dolog ************************************
67 Writes the contents of logtext to both the protocol file (if opened) and to
70 **************************************************************************/
75 fprintf(logfile, "%s\n",logtext);
79 fprintf(stdout,"LOG: %s\n",logtext);
85 /********************* Function: log_text ********************************/
87 void log_text(char *text)
89 sprintf(logtext, "%s",text);
94 /********************* Function: log_cputime ****************************/
105 sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
111 /************************** Function: error *******************************
113 Like dolog(), but terminates the program immediately.
115 **************************************************************************/
120 fprintf(logfile, "ERROR: %s\n", logtext);
123 printf("ERROR: %s\n",logtext);
128 /************************ Function: panic (txt) ****************************
130 Like error(), takes the text to output as an argument
132 ***************************************************************************/
134 void panic(char *txt)
136 sprintf(logtext, "%s", txt);
141 /********************** Function: getcputime ********************************
143 Returns the used CPU time in microseconds
145 ****************************************************************************/
147 long int getcputime()
152 getrusage(RUSAGE_SELF, &ru);
153 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
154 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
155 return sec * 1000000 + usec;
160 * These are local overrides for various environment variables in Emacs.
161 * Please do not remove this and leave it at the end of the file, where
162 * Emacs will automagically detect them.
163 * ---------------------------------------------------------------------
166 * indent-tabs-mode: t