1 /************************* toolbox/loging.c ************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Not documented, see loging.h.
9 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
11 Last Change: 1996/10/03
13 *******************************************************************************/
17 #include <sys/resource.h>
22 /***************************************************************************
24 ***************************************************************************/
26 char logtext[MAXLOGTEXT]; /* Needs to be filled with desired text before */
35 void log_init(char *fname)
39 logfile = fopen(fname, "w");
46 /*********************** Function: dolog ************************************
48 Writes the contents of logtext to both the protocol file (if opened) and to
51 **************************************************************************/
56 fprintf (logfile, "%s\n",logtext);
60 printf ("LOG: %s\n",logtext);
65 /********************* Function: log_text ********************************/
67 void log_text (char *text)
69 sprintf (logtext, "%s",text);
74 /********************* Function: log_cputime ****************************/
85 sprintf (logtext, "Total CPU usage: %d seconds and %d milliseconds",
92 /************************** Function: error *******************************
94 Like dolog(), but terminates the program immediately.
96 **************************************************************************/
101 fprintf (logfile, "ERROR: %s\n", logtext);
103 printf ("ERROR: %s\n",logtext);
108 /************************ Function: panic (txt) ****************************
110 Like error(), takes the text to output as an argument
112 ***************************************************************************/
114 void panic(char *txt)
116 sprintf (logtext, "%s", txt);
121 /********************** Function: getcputime ********************************
123 Returns the used CPU time in microseconds
125 ****************************************************************************/
127 long int getcputime()
132 getrusage (RUSAGE_SELF, &ru);
133 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
134 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
135 return sec*1000000 + usec;