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