forked from kennytilton/utils-kt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.lisp
executable file
·169 lines (132 loc) · 5.07 KB
/
debug.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
;; -*- mode: Lisp; Syntax: Common-Lisp; Package: utils-kt; -*-
;;;
#|
Utils-kt
Copyright (C) 1995, 2006 by Kenneth Tilton
This library is free software; you can redistribute it and/or
modify it under the terms of the Lisp Lesser GNU Public License
(http://opensource.franz.com/preamble.html), known as the LLGPL.
This library is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the Lisp Lesser GNU Public License for more details.
|#
(in-package :utils-kt)
(defvar *mpstart* (get-internal-real-time))
(export! mpt)
(defun mpt (&rest args)
;(error "mprint")
(when (eq :start (car args))
(setf *mpstart* (get-internal-real-time) ))
(print (list* (- (get-internal-real-time) *mpstart*) args)))
#+test
(mpt :one 2 "3")
(defvar *count* nil)
(defvar *counting* nil)
(defvar *dbg*)
(defvar *stop* nil)
(defun utils-kt-reset ()
(clock-off :ukt-reset)
(setf *count* nil
*stop* nil
*dbg* nil)
(print "----------UTILSRESET----------------------------------"))
;------------- counting ---------------------------
(defmacro with-counts ((onp &rest msg) &body body)
`(if ,onp
(let ((*counting* (cons t *counting*)))
(prog2
(count-clear nil ,@msg)
(progn ,@body)
(show-count t ,@msg)))
(progn ,@body)))
(defun count-of (key)
(cdr (assoc key *count* :key 'car)))
(defun count-clear (announce &rest msg)
(declare (ignorable msg))
(when announce (format t "~&count-clear > ~a" msg))
(setf *count* nil))
(defparameter *stopped* (lambda () *stop*))
(defun stop-check (&optional (where :unspecified))
(when (funcall *stopped*)
(break "utils-kt *stopped* at ~a" where)))
(defmacro count-it (&rest keys)
(declare (ignorable keys))
#+nahhh
`(progn)
`(when (car *counting*)
(call-count-it ,@keys)))
(export! count-it!)
(defmacro count-it! (&rest keys)
(declare (ignorable keys))
#+(and its-alive! (not debugging-alive!))
`(progn)
#-(and its-alive! (not debugging-alive!))
`(when (car *counting*)
(call-count-it ,@keys)))
(defun call-count-it (&rest keys)
(declare (ignorable keys))
#+nahh (when (find (car keys) '(:trcfailed :TGTNILEVAL))
(break "clean up time ~a" keys))
(let ((entry (assoc keys *count* :test #'equal)))
(if entry
(setf (cdr entry) (1+ (cdr entry)))
(push (cons keys 1) *count*))))
(defun show-count (clearp &rest msg &aux announced)
(let ((res (sort (copy-list *count*) (lambda (v1 v2)
(let ((v1$ (symbol-name (caar v1)))
(v2$ (symbol-name (caar v2))))
(if (string= v1$ v2$)
(< (cdr v1) (cdr v2))
(string< v1$ v2$))))))
)
(loop for entry in res
for occs = (cdr entry)
when (plusp occs)
sum occs into running
and do (unless announced
(setf announced t)
(format t "~&Counts after: clearp ~a, length ~d: ~s" clearp (length *count*) msg))
(format t "~&~4d ... ~2d ... ~(~{~a ~}~)" running occs (car entry))))
(when clearp (count-clear announced "show-count" )))
;-------------------- timex ---------------------------------
(export! timex)
(defmacro timex ((onp &rest trcargs) &body body)
`(if ,onp
(prog2
(format t "~&Starting timing run of ~{ ~a~}" (list ,@trcargs))
(time (progn ,@body))
(format t "~&Above timing was of ~{ ~a~}" (list ,@trcargs)))
(progn ,@body)))
#+save
(defun dbg-time-report (cpu-gc-user cpu-gc-sys cpu-tot-user cpu-tot-sys real-time conses other-bytes static-bytes)
(format t "~&cpu-gc-user ~a" cpu-gc-user)
(format t "~&cpu-gc-sys ~a" cpu-gc-sys)
(format t "~&cpu-tot-user ~a" cpu-tot-user)
(format t "~&cpu-tot-sys ~a" cpu-tot-sys)
(format t "~&<non-gc user cpu> ~a" (- cpu-tot-user cpu-gc-user))
(format t "~&<non-gc sys cpu> ~a" (- cpu-tot-sys cpu-gc-sys))
(format t "~&conses ~a" conses)
(format t "~&other-bytes ~a" other-bytes)
(format t "~&static-bytes ~a" static-bytes)
(excl::time-report cpu-gc-user cpu-gc-sys cpu-tot-user cpu-tot-sys real-time conses other-bytes static-bytes))
;---------------- Metrics -------------------
(defmacro with-metrics ((countp timep &rest trcargs) form-measured &body postlude)
`(with-counts (,countp ,@trcargs)
(timex (,timep ,@trcargs)
,form-measured)
,@postlude))
(defvar *clock*)
(export! clock clock-0 clock-off)
(defun clock-off (key)
(when (boundp '*clock*)
(print (list :clock-off key))
(makunbound '*clock*)))
(defun clock-0 (key &aux (now (get-internal-real-time)))
(setf *clock* (cons now now))
(print (list :clock-initialized-by key)))
(defun clock (&rest keys &aux (now (get-internal-real-time)))
(declare (ignorable keys now))
#-its-alive!
(when (boundp '*clock*)
(print (list* :delta (- now (cdr *clock*)) :tot-elap (- now (car *clock*)) :at keys))
(setf (cdr *clock*) now)))