TraceBuffer.st
author Patrik Svestka <patrik.svestka@gmail.com>
Wed, 17 Feb 2021 15:24:09 +0100
branchjv
changeset 4568 524471ef6575
parent 4384 e28fcaaf93c7
permissions -rw-r--r--
Changing the encoding style header for fileOutAs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4384
e28fcaaf93c7 Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents: 3128
diff changeset
     1
"{ Encoding: utf8 }"
e28fcaaf93c7 Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents: 3128
diff changeset
     2
2299
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2010 by Claus Gittinger
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic3' }"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Array variableSubclass:#TraceBuffer
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'accessLock writeIndex'
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'System-Debugging-Support'
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
2308
7d80e5d07115 category of:
Stefan Vogel <sv@exept.de>
parents: 2299
diff changeset
    23
!TraceBuffer class methodsFor:'documentation'!
2299
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
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2010 by Claus Gittinger
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
    "Created: / 30-11-2010 / 16:21:33 / cg"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    simple round robin tracebuffer for system debugging.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    "Created: / 30-11-2010 / 16:21:57 / cg"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
!
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
examples
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|
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    buffer := self new:100.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    buffer dumpLast:5 on:Transcript.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    buffer trace:1.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    buffer trace:2.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    buffer trace:3.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    buffer dumpLast:5 on:Transcript.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    buffer trace:4.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    buffer trace:5.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    buffer dumpLast:5 on:Transcript.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    buffer trace:6.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    buffer trace:7.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    buffer trace:8.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    buffer dumpLast:5 on:Transcript.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    "Created: / 30-11-2010 / 16:11:55 / cg"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
! !
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
2308
7d80e5d07115 category of:
Stefan Vogel <sv@exept.de>
parents: 2299
diff changeset
    71
!TraceBuffer class methodsFor:'instance creation'!
7d80e5d07115 category of:
Stefan Vogel <sv@exept.de>
parents: 2299
diff changeset
    72
7d80e5d07115 category of:
Stefan Vogel <sv@exept.de>
parents: 2299
diff changeset
    73
new:n
7d80e5d07115 category of:
Stefan Vogel <sv@exept.de>
parents: 2299
diff changeset
    74
    "return an initialized instance"
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
    ^ (self basicNew:n*2) initialize.
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
    "Created: / 30-11-2010 / 16:13:25 / cg"
7d80e5d07115 category of:
Stefan Vogel <sv@exept.de>
parents: 2299
diff changeset
    79
! !
7d80e5d07115 category of:
Stefan Vogel <sv@exept.de>
parents: 2299
diff changeset
    80
2299
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
!TraceBuffer methodsFor:'dumping'!
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
dumpLast:n on:aStream
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    |count idx entry time|
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    count := 0.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    idx := writeIndex.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    aStream showCR:'-----------------'.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    [
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
        [ count <= n ] whileTrue:[
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
            idx == 0 ifTrue:[
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
                idx := self size.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
                idx == 0 ifTrue:[ ^ self ].
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
            ].
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
            time := self at:idx.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
            entry := self at:idx-1.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
            entry isNil ifTrue:[^ self ].
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
            aStream show:time; show:' '; showCR:entry.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
            idx := idx - 2.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
            count := count + 1.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
        ].
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    ] ensure:[
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
        aStream showCR:'-----------------'.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    ]
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    "Created: / 30-11-2010 / 16:10:00 / cg"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
! !
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
!TraceBuffer methodsFor:'initialization'!
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
initialize  
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    writeIndex := 0.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    accessLock := Semaphore forMutualExclusion.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    "Created: / 30-11-2010 / 16:06:47 / cg"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
! !
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
!TraceBuffer methodsFor:'tracing'!
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
trace:something
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    accessLock critical:[
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
        writeIndex == self size ifTrue:[
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
            writeIndex := 0.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
        ].
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
        self at:writeIndex+1 put:something.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
        self at:writeIndex+2 put:(OperatingSystem getMicrosecondTime).
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
        writeIndex := writeIndex + 2.
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    ].
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    "Created: / 30-11-2010 / 16:07:52 / cg"
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
! !
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
!TraceBuffer class methodsFor:'documentation'!
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
6f8b7077a78d initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
version_CVS
4384
e28fcaaf93c7 Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents: 3128
diff changeset
   137
    ^ '§Header: /cvs/stx/stx/libbasic3/TraceBuffer.st,v 1.2 2010/12/03 09:08:31 stefan Exp §'
3012
4f40b8304d54 Added InvalidChange
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3011
diff changeset
   138
!
4f40b8304d54 Added InvalidChange
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3011
diff changeset
   139
3121
19723298dd2c Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3042
diff changeset
   140
version_HG
19723298dd2c Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3042
diff changeset
   141
19723298dd2c Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3042
diff changeset
   142
    ^ '$Changeset: <not expanded> $'
19723298dd2c Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3042
diff changeset
   143
!
19723298dd2c Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3042
diff changeset
   144
3012
4f40b8304d54 Added InvalidChange
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3011
diff changeset
   145
version_SVN
4384
e28fcaaf93c7 Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents: 3128
diff changeset
   146
    ^ '§Id: TraceBuffer.st 1909 2012-03-31 00:14:49Z vranyj1 §'
3012
4f40b8304d54 Added InvalidChange
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3011
diff changeset
   147
! !
3121
19723298dd2c Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3042
diff changeset
   148