Changeset 4752 for trunk/j/src/org/armedbear
- Timestamp:
- 11/14/03 17:55:35 (19 years ago)
- Location:
- trunk/j/src/org/armedbear/lisp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Profiler.java
r4708 r4752 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: Profiler.java,v 1. 1 2003-11-12 21:28:11piso Exp $5 * $Id: Profiler.java,v 1.2 2003-11-14 17:55:17 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 24 24 public class Profiler extends Lisp 25 25 { 26 private static int sleep = 1; 27 26 28 public static final void sample(LispThread thread) 27 29 { … … 33 35 public void run() 34 36 { 35 try { 36 int sleep = Fixnum.getValue(_GRANULARITY_.getSymbolValue()); 37 while (profiling) { 38 sampleNow = true; 39 try { 40 Thread.sleep(sleep); 41 } 42 catch (InterruptedException e) { 43 Debug.trace(e); 44 } 37 while (profiling) { 38 sampleNow = true; 39 try { 40 Thread.sleep(sleep); 45 41 } 46 }47 catch (ConditionThrowable t) {48 Debug.trace(t);42 catch (InterruptedException e) { 43 Debug.trace(e); 44 } 49 45 } 50 46 } 51 47 }; 52 48 53 // ### start-profiler 54 public static final Primitive0 START_PROFILER = 55 new Primitive0("start-profiler", PACKAGE_PROF, true) 49 // ### %start-profiler 50 // %start-profiler type granularity 51 public static final Primitive2 _START_PROFILER = 52 new Primitive2("%start-profiler", PACKAGE_PROF, false) 56 53 { 57 public LispObject execute() throws ConditionThrowable 54 public LispObject execute(LispObject first, LispObject second) 55 throws ConditionThrowable 58 56 { 59 57 CharacterOutputStream out = getStandardOutput(); 60 58 out.freshLine(); 61 59 if (profiling) { 62 out.writeLine("; Profil ing already enabled.");60 out.writeLine("; Profiler already started."); 63 61 } else { 62 if (first == Keyword.TIME) 63 sampling = true; 64 else if (first == Keyword.COUNT_ONLY) 65 sampling = false; 66 else 67 throw new ConditionThrowable(new LispError( 68 "%START-PROFILER: argument must be either :TIME or :COUNT-ONLY")); 64 69 Package[] packages = Packages.getAllPackages(); 65 70 for (int i = 0; i < packages.length; i++) { … … 73 78 } 74 79 } 75 sampling = true; // FIXME76 80 if (sampling) { 81 sleep = Fixnum.getValue(second); 77 82 if (!debug) { 78 83 debug = true; … … 86 91 new Thread(profilerRunnable).start(); 87 92 } 88 out.writeLine("; Profil ingstarted.");93 out.writeLine("; Profiler started."); 89 94 profiling = true; 90 95 } … … 103 108 if (profiling) { 104 109 profiling = false; 105 out.writeLine("; Profil ingstopped.");110 out.writeLine("; Profiler stopped."); 106 111 } else 107 out.writeLine("; Profil ing not enabled.");112 out.writeLine("; Profiler was not started."); 108 113 out.flushOutput(); 109 114 return LispThread.currentThread().nothing(); -
trunk/j/src/org/armedbear/lisp/profiler.lisp
r4707 r4752 2 2 ;;; 3 3 ;;; Copyright (C) 2003 Peter Graves 4 ;;; $Id: profiler.lisp,v 1. 7 2003-11-12 21:26:59piso Exp $4 ;;; $Id: profiler.lisp,v 1.8 2003-11-14 17:55:35 piso Exp $ 5 5 ;;; 6 6 ;;; This program is free software; you can redistribute it and/or … … 20 20 (in-package "PROFILER") 21 21 22 ;; SHOW-CALL-COUNTS and PROFILE are exported in Lisp.java. 22 (defparameter *type* nil) 23 24 (defparameter *granularity* 1 "Sampling interval (in milliseconds).") 23 25 24 26 ;; Returns list of all symbols with non-zero call counts. … … 45 47 (setf syms (sort syms #'< 46 48 :key #'(lambda (x) (sys::%call-count (fdefinition x))))) 47 (let* ((last-sym (car (last syms))) 48 (max-count (if last-sym 49 (sys::%call-count (fdefinition last-sym)) 50 nil))) 51 (when (zerop max-count) 52 (setf max-count nil)) 49 (let ((max-count nil)) 50 (when (eq *type* :time) 51 (let* ((last-sym (car (last syms)))) 52 (setf max-count (if last-sym 53 (sys::%call-count (fdefinition last-sym)) 54 nil)) 55 (when (eql max-count 0) 56 (setf max-count nil)))) 53 57 (dolist (sym syms) 54 58 (show-call-count-for-symbol sym max-count)))) 55 59 (values)) 56 60 57 (defmacro profile (&rest forms) 58 `(progn (start-profiler) ,@forms (stop-profiler))) 61 (defun start-profiler (&key type) 62 "Starts the profiler. 63 :TYPE may be either :TIME (statistical sampling) or :COUNT-ONLY (exact call 64 counts)." 65 (format t "start-profiler type = ~S~%" type) 66 (unless type 67 (setf type :time)) 68 (unless (memq type '(:time :count-only)) 69 (error ":TYPE must be :TIME or :COUNT-ONLY")) 70 (setf *type* type) 71 (%start-profiler type *granularity*)) 72 73 (defmacro with-profiling ((&key type) &body body) 74 `(unwind-protect (progn (start-profiler :type ,type) ,@body) 75 (stop-profiler)))
Note: See TracChangeset
for help on using the changeset viewer.