X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Ftoolbox%2Flogging.c;h=3d10140b85a931e6997a16d7aa6e08492def1887;hb=ad92477479aeed17382996ab43a7ca0dfab2ba93;hp=017850a3e2e68412ff9d9b7aeaeec40248f9829b;hpb=9df2bcaa5c50904777635c1afb45527e71a9c2d2;p=cacao.git diff --git a/src/toolbox/logging.c b/src/toolbox/logging.c index 017850a3e..3d10140b8 100644 --- a/src/toolbox/logging.c +++ b/src/toolbox/logging.c @@ -1,10 +1,9 @@ -/* toolbox/logging.c - contains logging functions +/* src/toolbox/logging.c - contains logging functions - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 - Institut f. Computersprachen, TU Wien - R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst, - S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, - J. Wenninger + Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel, + C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, + E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, + J. Wenninger, Institut f. Computersprachen - TU Wien This file is part of CACAO. @@ -20,25 +19,39 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. - Contact: cacao@complang.tuwien.ac.at + Contact: cacao@cacaojvm.org Authors: Reinhard Grafl - $Id: logging.c 1067 2004-05-18 10:25:51Z stefan $ + Changes: Christian Thalinger + + $Id: logging.c 4357 2006-01-22 23:33:38Z twisti $ */ #include #include -#include -#include +#include +#include + +#include "config.h" +#include "vm/types.h" -#include "global.h" -#include "logging.h" +#include "mm/memory.h" +#include "toolbox/logging.h" +#include "toolbox/util.h" +#include "vm/global.h" +#include "vm/statistics.h" + +#if defined(USE_THREADS) +# if defined(NATIVE_THREADS) +# include "threads/native/threads.h" +# endif +#endif /*************************************************************************** @@ -48,8 +61,7 @@ FILE *logfile = NULL; - -void log_init(char *fname) +void log_init(const char *fname) { if (fname) { if (fname[0]) { @@ -59,27 +71,40 @@ void log_init(char *fname) } -/*********************** Function: dolog ************************************ +/* dolog *********************************************************************** -Writes logtext to the protocol file (if opened) or to stdout. + Writes logtext to the protocol file (if opened) or to stdout. -**************************************************************************/ +*******************************************************************************/ -void dolog(char *txt, ...) +void dolog(const char *text, ...) { - char logtext[MAXLOGTEXT]; va_list ap; - va_start(ap, txt); - vsprintf(logtext, txt, ap); - va_end(ap); - if (logfile) { - fprintf(logfile, "%s\n",logtext); +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + fprintf(logfile, "[%p] ", (void *) THREADOBJECT); +#endif + + va_start(ap, text); + vfprintf(logfile, text, ap); + va_end(ap); + fflush(logfile); } else { - fprintf(stdout,"LOG: %s\n",logtext); +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT); +#else + fputs("LOG: ", stdout); +#endif + + va_start(ap, text); + vfprintf(stdout, text, ap); + va_end(ap); + + fprintf(stdout, "\n"); + fflush(stdout); } } @@ -91,7 +116,7 @@ Writes logtext to the protocol file (if opened) or to stdout. **************************************************************************/ -void dolog_plain(char *txt, ...) +void dolog_plain(const char *txt, ...) { char logtext[MAXLOGTEXT]; va_list ap; @@ -101,11 +126,11 @@ void dolog_plain(char *txt, ...) va_end(ap); if (logfile) { - fprintf(logfile, "%s",logtext); + fprintf(logfile, "%s", logtext); fflush(logfile); } else { - fprintf(stdout,"%s",logtext); + fprintf(stdout,"%s", logtext); fflush(stdout); } } @@ -113,7 +138,7 @@ void dolog_plain(char *txt, ...) /********************* Function: log_text ********************************/ -void log_text(char *text) +void log_text(const char *text) { dolog("%s", text); } @@ -121,7 +146,7 @@ void log_text(char *text) /******************** Function: log_plain *******************************/ -void log_plain(char *text) +void log_plain(const char *text) { dolog_plain("%s", text); } @@ -129,7 +154,7 @@ void log_plain(char *text) /****************** Function: get_logfile *******************************/ -FILE *get_logfile() +FILE *get_logfile(void) { return (logfile) ? logfile : stdout; } @@ -137,7 +162,7 @@ FILE *get_logfile() /****************** Function: log_flush *********************************/ -void log_flush() +void log_flush(void) { fflush(get_logfile()); } @@ -145,83 +170,139 @@ void log_flush() /********************* Function: log_nl *********************************/ -void log_nl() +void log_nl(void) { log_plain("\n"); fflush(get_logfile()); } -/********************* Function: log_cputime ****************************/ +/* log_message_utf ************************************************************* + + Outputs log text like this: + + LOG: Creating class: java/lang/Object -void log_cputime() +*******************************************************************************/ + +void log_message_utf(const char *msg, utf *u) { - s8 t; - int sec, usec; - char logtext[MAXLOGTEXT]; + char *buf; + s4 len; + + len = strlen(msg) + utf_strlen(u) + strlen("0"); - t = getcputime(); - sec = t / 1000000; - usec = t % 1000000; + buf = MNEW(char, len); - sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds", - sec, usec / 1000); - log_text(logtext); + strcpy(buf, msg); + utf_strcat(buf, u); + + log_text(buf); + + MFREE(buf, char, len); } -/************************** Function: error ******************************* +/* log_message_class *********************************************************** -Like dolog(), but terminates the program immediately. + Outputs log text like this: -**************************************************************************/ + LOG: Loading class: java/lang/Object + +*******************************************************************************/ -void error(char *txt, ...) +void log_message_class(const char *msg, classinfo *c) { - char logtext[MAXLOGTEXT]; - va_list ap; + log_message_utf(msg, c->name); +} - va_start(ap, txt); - vsprintf(logtext, txt, ap); - va_end(ap); - if (logfile) { - fprintf(logfile, "ERROR: %s\n", logtext); - } +/* log_message_class_message_class ********************************************* + + Outputs log text like this: + + LOG: Initialize super class java/lang/Object from java/lang/VMThread + +*******************************************************************************/ + +void log_message_class_message_class(const char *msg1, classinfo *c1, + const char *msg2, classinfo *c2) +{ + char *buf; + s4 len; + + len = + strlen(msg1) + utf_strlen(c1->name) + + strlen(msg2) + utf_strlen(c2->name) + strlen("0"); + + buf = MNEW(char, len); + + strcpy(buf, msg1); + utf_strcat(buf, c1->name); + strcat(buf, msg2); + utf_strcat(buf, c2->name); + + log_text(buf); - fprintf(stderr, "ERROR: %s\n", logtext); - exit(10); + MFREE(buf, char, len); } -/************************ Function: panic (txt) **************************** +/* log_message_method ********************************************************** - Like error(), takes the text to output as an argument + Outputs log text like this: -***************************************************************************/ + LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object; + +*******************************************************************************/ -void panic(char *txt) +void log_message_method(const char *msg, methodinfo *m) { - error("%s", txt); + char *buf; + s4 len; + + len = strlen(msg) + utf_strlen(m->class->name) + strlen(".") + + utf_strlen(m->name) + utf_strlen(m->descriptor) + strlen("0"); + + buf = MNEW(char, len); + + strcpy(buf, msg); + utf_strcat_classname(buf, m->class->name); + strcat(buf, "."); + utf_strcat(buf, m->name); + utf_strcat(buf, m->descriptor); + + log_text(buf); + + MFREE(buf, char, len); } -/********************** Function: getcputime ******************************** +/* log_utf ********************************************************************* - Returns the used CPU time in microseconds - -****************************************************************************/ + Log utf symbol. -s8 getcputime() +*******************************************************************************/ + +void log_utf(utf *u) { - struct rusage ru; - int sec, usec; + char buf[MAXLOGTEXT]; + utf_sprint(buf, u); + dolog("%s", buf); +} + - getrusage(RUSAGE_SELF, &ru); - sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec; - usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec; +/* log_plain_utf *************************************************************** - return sec * 1000000 + usec; + Log utf symbol (without printing "LOG: " and newline). + +*******************************************************************************/ + +void log_plain_utf(utf *u) +{ + char buf[MAXLOGTEXT]; + utf_sprint(buf, u); + dolog_plain("%s", buf); }