eventlog.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.7 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 # include "incls/_precompiled.incl"
00025 # include "incls/_eventlog.cpp.incl"
00026 
00027 EventLog* eventLog;
00028 
00029 void eventlog_init() { eventLog = new EventLog; }
00030 
00031 static char* noEvent = "no event";
00032 
00033 void EventLog::init() {
00034   buf = next = NEW_C_HEAP_ARRAY( EL_Event, EventLogLength);
00035   bufEnd = buf + EventLogLength;
00036   for (EL_Event* e = buf; e < bufEnd; e++) e->name = noEvent;
00037 }
00038 
00039 EventLog::EventLog() {
00040   nesting = 0;
00041   init();
00042 }
00043 
00044 void EventLog::resize() {
00045   EL_Event* oldBuf = buf;
00046   EL_Event* oldEnd = bufEnd;
00047   EL_Event* oldNext = next;
00048   init();
00049   // copy events
00050   for (EL_Event* e = nextEvent(oldNext, oldBuf, oldEnd); e != oldNext;
00051        e = nextEvent(e, oldBuf, oldEnd), next = nextEvent(next, buf, bufEnd)) {
00052     *next = *e;
00053   }
00054   FreeHeap( oldBuf);
00055 }
00056 
00057 void EventLog::printPartial(int n) {
00058   EL_Event* e = next;
00059   // find starting point
00060   if (n >= EventLogLength) n = EventLogLength - 1;
00061   for (int i = 0; i < n; i++, e = prevEvent(e, buf, bufEnd)) ;
00062   
00063   // skip empty entries
00064   i = 0;
00065   for (; e != next && e->name == noEvent; i++, e = nextEvent(e, buf, bufEnd)) ;
00066 
00067   int indent = 0;
00068   for (; i < n && e != next; i++, e = nextEvent(e, buf, bufEnd)) {
00069     char* s;
00070     switch (e->status) {
00071      case starting: s = "[ "; break;
00072      case ending:   s = "] "; indent--; break;
00073      case atomic:   s = "- "; break;
00074     }
00075     lprintf("%*.s%s", 2*indent, " ", s);
00076     lprintf(e->name, e->args[0], e->args[1], e->args[2]);
00077     lprintf("\n");
00078     if (e->status == starting) indent++;
00079   }
00080   if (indent != nesting)
00081     lprintf("Actual event nesting is %ld greater than shown.\n",
00082            nesting - indent);
00083 }
00084 

Generated on Mon Oct 9 13:37:09 2006 for Strongtalk VM by  doxygen 1.4.7