1/* 2 * Copyright (c) 2001 by The XFree86 Project, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 * 22 * Except as contained in this notice, the name of the XFree86 Project shall 23 * not be used in advertising or otherwise to promote the sale, use or other 24 * dealings in this Software without prior written authorization from the 25 * XFree86 Project. 26 * 27 * Author: Paulo César Pereira de Andrade 28 */ 29 30/* $XFree86: xc/programs/xedit/lisp/time.c,v 1.9tsi Exp $ */ 31 32#include "lisp/time.h" 33#include "lisp/bytecode.h" 34 35/* 36 * Implementation 37*/ 38LispObj * 39Lisp_Time(LispBuiltin *builtin) 40/* 41 time form 42 */ 43{ 44 struct itimerval real, virt, prof; 45 unsigned long count; 46 long sec, usec; 47 LispObj *result; 48#define MONTH 60 * 60 * 31 49 50 LispObj *form; 51 52 form = ARGUMENT(0); 53 54 real.it_value.tv_sec = 55 virt.it_value.tv_sec = 56 prof.it_value.tv_sec = 57 real.it_interval.tv_sec = 58 virt.it_interval.tv_sec = 59 prof.it_interval.tv_sec = MONTH; 60 real.it_value.tv_usec = 61 virt.it_value.tv_usec = 62 prof.it_value.tv_usec = 63 real.it_interval.tv_usec = 64 virt.it_interval.tv_usec = 65 prof.it_interval.tv_usec = 0; 66 67 setitimer(ITIMER_REAL, &real, NULL); 68 setitimer(ITIMER_VIRTUAL, &virt, NULL); 69 setitimer(ITIMER_PROF, &prof, NULL); 70 71 getitimer(ITIMER_REAL, &real); 72 getitimer(ITIMER_VIRTUAL, &virt); 73 getitimer(ITIMER_PROF, &prof); 74 75 lisp__data.gc.gctime = 0; 76 lisp__data.gc.timebits = 1; 77 78 count = lisp__data.gc.count; 79 80#if 0 81 form = CONS(form, NIL); 82 COD = CONS(form, COD); 83 result = LispExecuteBytecode(LispCompileForm(form)); 84#else 85 result = EVAL(form); 86#endif 87 88 getitimer(ITIMER_REAL, &real); 89 getitimer(ITIMER_VIRTUAL, &virt); 90 getitimer(ITIMER_PROF, &prof); 91 92 sec = real.it_interval.tv_sec - real.it_value.tv_sec; 93 usec = real.it_interval.tv_usec - real.it_value.tv_usec; 94 if (usec < 0) { 95 --sec; 96 usec += 1000000; 97 } 98 LispMessage("Real time : %g sec", sec + usec / 1000000.0); 99 100 sec = virt.it_interval.tv_sec - virt.it_value.tv_sec; 101 usec = virt.it_interval.tv_usec - virt.it_value.tv_usec + 10000; 102 if (usec < 0) { 103 --sec; 104 usec += 1000000; 105 } 106 LispMessage("Virtual time: %g sec", sec + usec / 1000000.0); 107 108 sec = prof.it_interval.tv_sec - prof.it_value.tv_sec; 109 usec = prof.it_interval.tv_usec - prof.it_value.tv_usec + 10000; 110 if (usec < 0) { 111 --sec; 112 usec += 1000000; 113 } 114 LispMessage("Profile time: %g sec", sec + usec / 1000000.0); 115 116 real.it_value.tv_sec = 117 virt.it_value.tv_sec = 118 prof.it_value.tv_sec = 119 real.it_interval.tv_sec = 120 virt.it_interval.tv_sec = 121 prof.it_interval.tv_sec = 122 real.it_value.tv_usec = 123 virt.it_value.tv_usec = 124 prof.it_value.tv_usec = 125 real.it_interval.tv_usec = 126 virt.it_interval.tv_usec = 127 prof.it_interval.tv_usec = 0; 128 129 setitimer(ITIMER_REAL, &real, NULL); 130 setitimer(ITIMER_VIRTUAL, &virt, NULL); 131 setitimer(ITIMER_PROF, &prof, NULL); 132 133 LispMessage("GC: %ld times, %g sec", 134 lisp__data.gc.count - count, lisp__data.gc.gctime / 1000000.0); 135 lisp__data.gc.timebits = 0; 136 137 return (result); 138} 139