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