1 /* toolbox/logging.c - contains logging 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: logging.c 1086 2004-05-26 21:22:05Z twisti $
38 #include <sys/resource.h>
41 #include "toolbox/logging.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 /* log_message_method **********************************************************
175 outputs log text like this:
177 LOG: Loading class: java.lang.Object
179 *******************************************************************************/
181 void log_message_class(char *msg, classinfo *c)
183 char logtext[MAXLOGTEXT];
185 sprintf(logtext, msg);
186 utf_sprint_classname(logtext + strlen(logtext), c->name);
192 /* log_message_method **********************************************************
194 outputs log text like this:
196 LOG: Compiling: java.lang.Object.clone()Ljava.lang.Object;
198 *******************************************************************************/
200 void log_message_method(char *msg, methodinfo *m)
202 char logtext[MAXLOGTEXT];
204 sprintf(logtext, msg);
205 utf_sprint_classname(logtext + strlen(logtext), m->class->name);
206 strcpy(logtext + strlen(logtext), ".");
207 utf_sprint(logtext + strlen(logtext), m->name);
208 utf_sprint_classname(logtext + strlen(logtext), m->descriptor);
214 /************************** Function: error *******************************
216 Like dolog(), but terminates the program immediately.
218 **************************************************************************/
220 void error(char *txt, ...)
222 char logtext[MAXLOGTEXT];
226 vsprintf(logtext, txt, ap);
230 fprintf(logfile, "ERROR: %s\n", logtext);
233 fprintf(stderr, "ERROR: %s\n", logtext);
239 /************************ Function: panic (txt) ****************************
241 Like error(), takes the text to output as an argument
243 ***************************************************************************/
245 void panic(char *txt)
251 /********************** Function: getcputime ********************************
253 Returns the used CPU time in microseconds
255 ****************************************************************************/
262 getrusage(RUSAGE_SELF, &ru);
263 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
264 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
266 return sec * 1000000 + usec;
271 * These are local overrides for various environment variables in Emacs.
272 * Please do not remove this and leave it at the end of the file, where
273 * Emacs will automagically detect them.
274 * ---------------------------------------------------------------------
277 * indent-tabs-mode: t