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 689 2003-12-05 18:03:47Z stefan $
38 #include <sys/resource.h>
44 /***************************************************************************
46 ***************************************************************************/
52 void log_init(char *fname)
56 logfile = fopen(fname, "w");
62 /*********************** Function: dolog ************************************
64 Writes the contents of logtext to both the protocol file (if opened) and to
67 **************************************************************************/
69 void dolog(char *txt, ...)
71 char logtext[MAXLOGTEXT];
75 vsprintf(logtext, txt, ap);
79 fprintf(logfile, "%s\n",logtext);
83 fprintf(stdout,"LOG: %s\n",logtext);
89 /********************* Function: log_text ********************************/
91 void log_text(char *text)
97 /********************* Function: log_cputime ****************************/
103 char logtext[MAXLOGTEXT];
109 sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
115 /************************** Function: error *******************************
117 Like dolog(), but terminates the program immediately.
119 **************************************************************************/
121 void error(char *txt, ...)
123 char logtext[MAXLOGTEXT];
127 vsprintf(logtext, txt, ap);
131 fprintf(logfile, "ERROR: %s\n", logtext);
134 fprintf(stderr, "ERROR: %s\n", logtext);
139 /************************ Function: panic (txt) ****************************
141 Like error(), takes the text to output as an argument
143 ***************************************************************************/
145 void panic(char *txt)
151 /********************** Function: getcputime ********************************
153 Returns the used CPU time in microseconds
155 ****************************************************************************/
157 long int getcputime()
162 getrusage(RUSAGE_SELF, &ru);
163 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
164 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
165 return sec * 1000000 + usec;
170 * These are local overrides for various environment variables in Emacs.
171 * Please do not remove this and leave it at the end of the file, where
172 * Emacs will automagically detect them.
173 * ---------------------------------------------------------------------
176 * indent-tabs-mode: t