15dfecf96Smrg/* 25dfecf96Smrg * Copyright (c) 2001 by The XFree86 Project, Inc. 35dfecf96Smrg * 45dfecf96Smrg * Permission is hereby granted, free of charge, to any person obtaining a 55dfecf96Smrg * copy of this software and associated documentation files (the "Software"), 65dfecf96Smrg * to deal in the Software without restriction, including without limitation 75dfecf96Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 85dfecf96Smrg * and/or sell copies of the Software, and to permit persons to whom the 95dfecf96Smrg * Software is furnished to do so, subject to the following conditions: 105dfecf96Smrg * 115dfecf96Smrg * The above copyright notice and this permission notice shall be included in 125dfecf96Smrg * all copies or substantial portions of the Software. 135dfecf96Smrg * 145dfecf96Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 155dfecf96Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 165dfecf96Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 175dfecf96Smrg * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 185dfecf96Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 195dfecf96Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 205dfecf96Smrg * SOFTWARE. 215dfecf96Smrg * 225dfecf96Smrg * Except as contained in this notice, the name of the XFree86 Project shall 235dfecf96Smrg * not be used in advertising or otherwise to promote the sale, use or other 245dfecf96Smrg * dealings in this Software without prior written authorization from the 255dfecf96Smrg * XFree86 Project. 265dfecf96Smrg * 275dfecf96Smrg * Author: Paulo César Pereira de Andrade 285dfecf96Smrg */ 295dfecf96Smrg 305dfecf96Smrg/* $XFree86: xc/programs/xedit/lisp/time.c,v 1.9tsi Exp $ */ 315dfecf96Smrg 325dfecf96Smrg#include "lisp/time.h" 335dfecf96Smrg#include "lisp/bytecode.h" 345dfecf96Smrg 355dfecf96Smrg/* 365dfecf96Smrg * Implementation 375dfecf96Smrg*/ 385dfecf96SmrgLispObj * 395dfecf96SmrgLisp_Time(LispBuiltin *builtin) 405dfecf96Smrg/* 415dfecf96Smrg time form 425dfecf96Smrg */ 435dfecf96Smrg{ 445dfecf96Smrg struct itimerval real, virt, prof; 455dfecf96Smrg unsigned long count; 465dfecf96Smrg long sec, usec; 475dfecf96Smrg LispObj *result; 485dfecf96Smrg#define MONTH 60 * 60 * 31 495dfecf96Smrg 505dfecf96Smrg LispObj *form; 515dfecf96Smrg 525dfecf96Smrg form = ARGUMENT(0); 535dfecf96Smrg 545dfecf96Smrg real.it_value.tv_sec = 555dfecf96Smrg virt.it_value.tv_sec = 565dfecf96Smrg prof.it_value.tv_sec = 575dfecf96Smrg real.it_interval.tv_sec = 585dfecf96Smrg virt.it_interval.tv_sec = 595dfecf96Smrg prof.it_interval.tv_sec = MONTH; 605dfecf96Smrg real.it_value.tv_usec = 615dfecf96Smrg virt.it_value.tv_usec = 625dfecf96Smrg prof.it_value.tv_usec = 635dfecf96Smrg real.it_interval.tv_usec = 645dfecf96Smrg virt.it_interval.tv_usec = 655dfecf96Smrg prof.it_interval.tv_usec = 0; 665dfecf96Smrg 675dfecf96Smrg setitimer(ITIMER_REAL, &real, NULL); 685dfecf96Smrg setitimer(ITIMER_VIRTUAL, &virt, NULL); 695dfecf96Smrg setitimer(ITIMER_PROF, &prof, NULL); 705dfecf96Smrg 715dfecf96Smrg getitimer(ITIMER_REAL, &real); 725dfecf96Smrg getitimer(ITIMER_VIRTUAL, &virt); 735dfecf96Smrg getitimer(ITIMER_PROF, &prof); 745dfecf96Smrg 755dfecf96Smrg lisp__data.gc.gctime = 0; 765dfecf96Smrg lisp__data.gc.timebits = 1; 775dfecf96Smrg 785dfecf96Smrg count = lisp__data.gc.count; 795dfecf96Smrg 805dfecf96Smrg#if 0 815dfecf96Smrg form = CONS(form, NIL); 825dfecf96Smrg COD = CONS(form, COD); 835dfecf96Smrg result = LispExecuteBytecode(LispCompileForm(form)); 845dfecf96Smrg#else 855dfecf96Smrg result = EVAL(form); 865dfecf96Smrg#endif 875dfecf96Smrg 885dfecf96Smrg getitimer(ITIMER_REAL, &real); 895dfecf96Smrg getitimer(ITIMER_VIRTUAL, &virt); 905dfecf96Smrg getitimer(ITIMER_PROF, &prof); 915dfecf96Smrg 925dfecf96Smrg sec = real.it_interval.tv_sec - real.it_value.tv_sec; 935dfecf96Smrg usec = real.it_interval.tv_usec - real.it_value.tv_usec; 945dfecf96Smrg if (usec < 0) { 955dfecf96Smrg --sec; 965dfecf96Smrg usec += 1000000; 975dfecf96Smrg } 985dfecf96Smrg LispMessage("Real time : %g sec", sec + usec / 1000000.0); 995dfecf96Smrg 1005dfecf96Smrg sec = virt.it_interval.tv_sec - virt.it_value.tv_sec; 1015dfecf96Smrg usec = virt.it_interval.tv_usec - virt.it_value.tv_usec + 10000; 1025dfecf96Smrg if (usec < 0) { 1035dfecf96Smrg --sec; 1045dfecf96Smrg usec += 1000000; 1055dfecf96Smrg } 1065dfecf96Smrg LispMessage("Virtual time: %g sec", sec + usec / 1000000.0); 1075dfecf96Smrg 1085dfecf96Smrg sec = prof.it_interval.tv_sec - prof.it_value.tv_sec; 1095dfecf96Smrg usec = prof.it_interval.tv_usec - prof.it_value.tv_usec + 10000; 1105dfecf96Smrg if (usec < 0) { 1115dfecf96Smrg --sec; 1125dfecf96Smrg usec += 1000000; 1135dfecf96Smrg } 1145dfecf96Smrg LispMessage("Profile time: %g sec", sec + usec / 1000000.0); 1155dfecf96Smrg 1165dfecf96Smrg real.it_value.tv_sec = 1175dfecf96Smrg virt.it_value.tv_sec = 1185dfecf96Smrg prof.it_value.tv_sec = 1195dfecf96Smrg real.it_interval.tv_sec = 1205dfecf96Smrg virt.it_interval.tv_sec = 1215dfecf96Smrg prof.it_interval.tv_sec = 1225dfecf96Smrg real.it_value.tv_usec = 1235dfecf96Smrg virt.it_value.tv_usec = 1245dfecf96Smrg prof.it_value.tv_usec = 1255dfecf96Smrg real.it_interval.tv_usec = 1265dfecf96Smrg virt.it_interval.tv_usec = 1275dfecf96Smrg prof.it_interval.tv_usec = 0; 1285dfecf96Smrg 1295dfecf96Smrg setitimer(ITIMER_REAL, &real, NULL); 1305dfecf96Smrg setitimer(ITIMER_VIRTUAL, &virt, NULL); 1315dfecf96Smrg setitimer(ITIMER_PROF, &prof, NULL); 1325dfecf96Smrg 1335dfecf96Smrg LispMessage("GC: %ld times, %g sec", 1345dfecf96Smrg lisp__data.gc.count - count, lisp__data.gc.gctime / 1000000.0); 1355dfecf96Smrg lisp__data.gc.timebits = 0; 1365dfecf96Smrg 1375dfecf96Smrg return (result); 1385dfecf96Smrg} 139