2299
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2010 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic3' }"
|
|
13 |
|
|
14 |
Array variableSubclass:#TraceBuffer
|
|
15 |
instanceVariableNames:'accessLock writeIndex'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'System-Debugging-Support'
|
|
19 |
!
|
|
20 |
|
2308
|
21 |
!TraceBuffer class methodsFor:'documentation'!
|
2299
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2010 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
|
|
36 |
"Created: / 30-11-2010 / 16:21:33 / cg"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
simple round robin tracebuffer for system debugging.
|
|
42 |
"
|
|
43 |
|
|
44 |
"Created: / 30-11-2010 / 16:21:57 / cg"
|
|
45 |
!
|
|
46 |
|
|
47 |
examples
|
|
48 |
"
|
|
49 |
|buffer|
|
|
50 |
|
|
51 |
buffer := self new:100.
|
|
52 |
buffer dumpLast:5 on:Transcript.
|
|
53 |
buffer trace:1.
|
|
54 |
buffer trace:2.
|
|
55 |
buffer trace:3.
|
|
56 |
buffer dumpLast:5 on:Transcript.
|
|
57 |
buffer trace:4.
|
|
58 |
buffer trace:5.
|
|
59 |
buffer dumpLast:5 on:Transcript.
|
|
60 |
buffer trace:6.
|
|
61 |
buffer trace:7.
|
|
62 |
buffer trace:8.
|
|
63 |
buffer dumpLast:5 on:Transcript.
|
|
64 |
"
|
|
65 |
|
|
66 |
"Created: / 30-11-2010 / 16:11:55 / cg"
|
|
67 |
! !
|
|
68 |
|
2308
|
69 |
!TraceBuffer class methodsFor:'instance creation'!
|
|
70 |
|
|
71 |
new:n
|
|
72 |
"return an initialized instance"
|
|
73 |
|
|
74 |
^ (self basicNew:n*2) initialize.
|
|
75 |
|
|
76 |
"Created: / 30-11-2010 / 16:13:25 / cg"
|
|
77 |
! !
|
|
78 |
|
2299
|
79 |
!TraceBuffer methodsFor:'dumping'!
|
|
80 |
|
|
81 |
dumpLast:n on:aStream
|
|
82 |
|count idx entry time|
|
|
83 |
|
|
84 |
count := 0.
|
|
85 |
idx := writeIndex.
|
|
86 |
|
|
87 |
aStream showCR:'-----------------'.
|
|
88 |
[
|
|
89 |
[ count <= n ] whileTrue:[
|
|
90 |
idx == 0 ifTrue:[
|
|
91 |
idx := self size.
|
|
92 |
idx == 0 ifTrue:[ ^ self ].
|
|
93 |
].
|
|
94 |
time := self at:idx.
|
|
95 |
entry := self at:idx-1.
|
|
96 |
entry isNil ifTrue:[^ self ].
|
|
97 |
aStream show:time; show:' '; showCR:entry.
|
|
98 |
idx := idx - 2.
|
|
99 |
count := count + 1.
|
|
100 |
].
|
|
101 |
] ensure:[
|
|
102 |
aStream showCR:'-----------------'.
|
|
103 |
]
|
|
104 |
|
|
105 |
"Created: / 30-11-2010 / 16:10:00 / cg"
|
|
106 |
! !
|
|
107 |
|
|
108 |
!TraceBuffer methodsFor:'initialization'!
|
|
109 |
|
|
110 |
initialize
|
|
111 |
writeIndex := 0.
|
|
112 |
accessLock := Semaphore forMutualExclusion.
|
|
113 |
|
|
114 |
"Created: / 30-11-2010 / 16:06:47 / cg"
|
|
115 |
! !
|
|
116 |
|
|
117 |
!TraceBuffer methodsFor:'tracing'!
|
|
118 |
|
|
119 |
trace:something
|
|
120 |
accessLock critical:[
|
|
121 |
writeIndex == self size ifTrue:[
|
|
122 |
writeIndex := 0.
|
|
123 |
].
|
|
124 |
self at:writeIndex+1 put:something.
|
|
125 |
self at:writeIndex+2 put:(OperatingSystem getMicrosecondTime).
|
|
126 |
writeIndex := writeIndex + 2.
|
|
127 |
].
|
|
128 |
|
|
129 |
"Created: / 30-11-2010 / 16:07:52 / cg"
|
|
130 |
! !
|
|
131 |
|
|
132 |
!TraceBuffer class methodsFor:'documentation'!
|
|
133 |
|
|
134 |
version_CVS
|
2308
|
135 |
^ '$Header: /cvs/stx/stx/libbasic3/TraceBuffer.st,v 1.2 2010-12-03 09:08:31 stefan Exp $'
|
2299
|
136 |
! !
|