InstrumentationContext.st
author Jan Vrany <jan.vrany@labware.com>
Thu, 27 Oct 2022 14:53:59 +0100
branchjv
changeset 4735 3b11fb3ede98
parent 4162 3a7f6aa12b81
permissions -rw-r--r--
Allow single underscore as method / block argument and temporaries This commit is a follow up for 38b221e.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2010 by eXept Software AG
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libcomp' }"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3919
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    14
"{ NameSpace: Smalltalk }"
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    15
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Object variableSubclass:#InstrumentationContext
2710
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
    17
	instanceVariableNames:'inInstrumentedCode enabled coverageOnly'
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
    18
	classVariableNames:'LastProcess LastInstrumentationContext
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    19
		GlobalInstrumentationContext'
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	category:'System-Compiler-Instrumentation'
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!InstrumentationContext class methodsFor:'documentation'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
copyright
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 COPYRIGHT (c) 2010 by eXept Software AG
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
              All Rights Reserved
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 This software is furnished under a license and may be used
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 only in accordance with the terms of that license and with the
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 be provided or otherwise made available to, or used by, any
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 other person.  No title to or ownership of the software is
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 hereby transferred.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    installed as a thread-local variable (instrumentationContext) by the
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    beActiveIn:aProcess method, instances of me keep some meta state while
2959
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    44
    instrumentation is ongoing.
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    45
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    46
    Especially, instrumentationInfo objects are only updated in processes with a context. 
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    47
    This has two advantages:
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    48
        - it blocks recursive calls, while inside instrumentation code
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    49
        - it blocks measurements from other processes 
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    50
          (so code coverage is only measured when executed during a test run, not if
9c8cf9e9915f comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents: 2945
diff changeset
    51
           executed by other processes)
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
    52
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
    53
    the main entries are run: and runForCoverage:
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
    54
    the code must have been recompiled with instrumentation before
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
    55
    (see InstrumentingCompiler - class protocol)
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
!InstrumentationContext class methodsFor:'instance creation'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
new
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    "return an initialized instance"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    ^ self basicNew initialize.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!InstrumentationContext class methodsFor:'instance access'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
current
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    70
    "the current context for this running thread.
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    71
     walks along the parent-process chain, up to a possible global context"
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    73
    ^ self forProcess:(Processor activeProcess)
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
     InstrumentationContext current
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "Created: / 08-08-2011 / 14:44:11 / cg"
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    80
!
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    81
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    82
forProcess:aProcess
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    83
    "the context for this thread.
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    84
     walks along the parent-process chain, up to a possible global context"
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    85
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    86
    |p context|
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    87
3919
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    88
    aProcess isDead ifTrue:[
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    89
        "do not keep dead processes from being garbage collected"
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    90
        aProcess == LastProcess ifTrue:[
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    91
            LastProcess := LastInstrumentationContext := nil.
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    92
        ].
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    93
        ^ GlobalInstrumentationContext.
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    94
    ].
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
    95
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
    96
    aProcess == LastProcess ifTrue:[
3547
541dafac7f54 class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 3453
diff changeset
    97
        ^ LastInstrumentationContext ? GlobalInstrumentationContext
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    98
    ].
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
    99
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   100
    "/ future (need a faster parentProcess query)
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   101
    p := aProcess.
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   102
    [p notNil] whileTrue:[
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   103
        context := p environmentAt:#instrumentationContext ifAbsent:nil.
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   104
        context notNil ifTrue:[
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   105
            aProcess environmentAt:#instrumentationContext put:context.
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   106
            context == 0 ifTrue:[
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   107
                context := nil.
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   108
            ].
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   109
            LastProcess := aProcess.
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   110
            LastInstrumentationContext := context.
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   111
            ^ context
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   112
        ].
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   113
        p := p parentProcess
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   114
    ].
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   115
    aProcess environmentAt:#instrumentationContext put:(GlobalInstrumentationContext ? 0).      "/ could be nil
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   116
    LastProcess := aProcess.
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   117
    LastInstrumentationContext := GlobalInstrumentationContext.
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   118
    ^ GlobalInstrumentationContext.
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   119
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   120
    "
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   121
     InstrumentationContext current
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   122
    "
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   123
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   124
    "Created: / 17-08-2011 / 11:29:51 / cg"
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   127
!InstrumentationContext class methodsFor:'queries'!
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   128
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   129
hasGlobalInstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   130
    ^ GlobalInstrumentationContext notNil
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   131
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   132
    "
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   133
     InstrumentationContext hasGlobalInstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   134
    "
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   135
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   136
    "Created: / 21-09-2011 / 19:15:51 / cg"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   137
! !
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   138
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
!InstrumentationContext class methodsFor:'running'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
run:aBlock
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    "run aBlock with instrumentation enabled"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   144
    self new run:aBlock.
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    "
4162
3a7f6aa12b81 #OTHER by mawalch
mawalch
parents: 4008
diff changeset
   147
     Smalltalk loadPackage:'stx/goodies:regression'.
3a7f6aa12b81 #OTHER by mawalch
mawalch
parents: 4008
diff changeset
   148
     BTree withAllPrivateClasses
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
        do:[:cls | cls recompileUsingCompilerClass:InstrumentingCompiler].
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
     InstrumentationContext
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
        run:[ RegressionTests::BinaryTreeTester suite run ].
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
     (Tools::NewSystemBrowser open)
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
        switchToClass:BTree;
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
        showCoverageInformation value:true
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    "Created: / 08-08-2011 / 15:47:10 / cg"
4162
3a7f6aa12b81 #OTHER by mawalch
mawalch
parents: 4008
diff changeset
   158
    "Modified (comment): / 12-07-2017 / 16:09:12 / mawalch"
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   159
!
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   160
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   161
runForCoverage:aBlock
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   162
    "run aBlock with instrumentation enabled, but only for coverage (i.e. not counting)"
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   163
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   164
    self new runForCoverage:aBlock.
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   165
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   166
    "
4162
3a7f6aa12b81 #OTHER by mawalch
mawalch
parents: 4008
diff changeset
   167
     Smalltalk loadPackage:'stx/goodies:regression'.
3a7f6aa12b81 #OTHER by mawalch
mawalch
parents: 4008
diff changeset
   168
     BTree withAllPrivateClasses
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   169
        do:[:cls | cls recompileUsingCompilerClass:InstrumentingCompiler].
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   170
     InstrumentationContext
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   171
        run:[ RegressionTests::BinaryTreeTester suite run ].
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   172
     (Tools::NewSystemBrowser open)
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   173
        switchToClass:BTree;
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   174
        showCoverageInformation value:true
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   175
    "
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   176
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   177
    "Created: / 08-08-2011 / 15:47:10 / cg"
4162
3a7f6aa12b81 #OTHER by mawalch
mawalch
parents: 4008
diff changeset
   178
    "Modified (comment): / 12-07-2017 / 16:09:28 / mawalch"
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   181
!InstrumentationContext class methodsFor:'utilities'!
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   182
2942
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   183
flushAllPerProcessInstrumentationContexts
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   184
    Process allInstancesDo:[:eachProcess |
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   185
        eachProcess environmentAt:#instrumentationContext put:nil
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   186
    ].
3453
ffbbed0fe172 class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
   187
    LastProcess := nil.
2942
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   188
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   189
    "
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   190
     self flushAllPerProcessInstrumentationContexts
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   191
    "
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   192
!
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   193
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   194
globalInstrumentationContext
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   195
    ^ GlobalInstrumentationContext
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   196
!
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   197
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   198
setGlobalInstrumentationContext:aContextOrNil
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   199
    "setup for global instrumentation: instrumentation is performed for all processes"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   200
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   201
    GlobalInstrumentationContext := aContextOrNil.
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   202
    LastInstrumentationContext := LastProcess := nil.
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   203
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   204
    "Created: / 21-09-2011 / 19:07:00 / cg"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   205
!
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   206
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   207
setInstrumentationContext:aContextOrNil in:aProcess
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   208
    "setup for process specific instrumentation: 
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   209
        instrumentation is aProcess"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   210
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   211
    "in order to keep the knowledge about which environment-variable is used
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   212
     at least local..."
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   213
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   214
    aProcess environmentAt:#instrumentationContext put:aContextOrNil.
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   215
    LastInstrumentationContext := LastProcess := nil.
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   216
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   217
    "Created: / 17-08-2011 / 11:53:19 / cg"
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   218
! !
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   219
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
!InstrumentationContext methodsFor:'accessing'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
2710
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   222
coverageOnly
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   223
    "if on, only keep track of coverage (not counting);
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   224
     if off, we also count how often the code has been entered,
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   225
     and by which sender"
2710
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   226
2980
0202d500e04d class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2979
diff changeset
   227
    ^ coverageOnly ? false
2710
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   228
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   229
    "Created: / 23-08-2011 / 21:25:46 / cg"
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   230
!
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   231
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   232
coverageOnly:aBoolean
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   233
    "if on, only keep track of coverage (not counting);
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   234
     if off, we also count how often the code has been entered"
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   235
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   236
    coverageOnly := aBoolean.
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   237
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   238
    "Created: / 23-08-2011 / 21:25:37 / cg"
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   239
!
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   240
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
enabled
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    ^ enabled
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
enabled:aBoolean
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    enabled := aBoolean.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    "Modified (format): / 08-08-2011 / 14:47:12 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
inInstrumentedCode
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    ^ inInstrumentedCode ? false
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    "Modified: / 07-08-2011 / 16:57:15 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
inInstrumentedCode:aBoolean
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    inInstrumentedCode := aBoolean.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    "Modified (format): / 08-08-2011 / 19:43:19 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
!InstrumentationContext methodsFor:'initialization'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
initialize
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    "Invoked when a new instance is created."
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
    inInstrumentedCode := false.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    enabled := true.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    "/ super initialize.   -- commented since inherited method does nothing
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    "Modified: / 08-08-2011 / 15:44:59 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
!InstrumentationContext methodsFor:'installing'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   278
beActiveEverywhere
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   279
    "become the current instrumentaion context for all processes."
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   280
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   281
    self class setGlobalInstrumentationContext:self. 
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   282
    LastInstrumentationContext := LastProcess := nil.
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   283
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   284
    "
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   285
     InstrumentationContext new beActiveEverywhere
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   286
    "
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   287
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   288
    "Created: / 21-09-2011 / 19:08:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   289
!
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   290
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
beActiveIn:aProcess
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
    "become the current instrumentaion context for a process."
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
2672
ca4221b5143e changed: #beActiveIn:
Claus Gittinger <cg@exept.de>
parents: 2664
diff changeset
   294
    self class setInstrumentationContext:self in:aProcess.
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   295
    LastInstrumentationContext := LastProcess := nil.
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
     InstrumentationContext new beActiveIn:(Processor activeProcess)
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
    "Created: / 08-08-2011 / 14:46:09 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
!InstrumentationContext methodsFor:'queries'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
enabledAndNotInInstrumentedCode
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
    ^ enabled and:[ inInstrumentedCode not ]
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
    "Created: / 08-08-2011 / 15:44:30 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   312
!InstrumentationContext methodsFor:'running'!
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   313
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   314
run:aBlock
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   315
    "run aBlock with instrumentation enabled"
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   316
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   317
    |activeProcess|
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   318
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   319
    activeProcess := Processor activeProcess.
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   320
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   321
    [
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   322
        self beActiveIn:activeProcess.
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   323
        aBlock value
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   324
    ] ensure:[
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   325
        self class setInstrumentationContext:nil in:activeProcess
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   326
    ].
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   327
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   328
    "Modified: / 17-08-2011 / 11:53:54 / cg"
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   329
!
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   330
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   331
runForCoverage:aBlock
4008
21b0132a3925 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3919
diff changeset
   332
    "run aBlock with instrumentation enabled;
21b0132a3925 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3919
diff changeset
   333
     but only for coverage (i.e. not counting)"
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   334
2980
0202d500e04d class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2979
diff changeset
   335
    coverageOnly := true.
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   336
    self run:aBlock
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   337
! !
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   338
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
!InstrumentationContext class methodsFor:'documentation'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
version
3919
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
   342
    ^ '$Header$'
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
version_CVS
3919
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
   346
    ^ '$Header$'
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
! !
3453
ffbbed0fe172 class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
   348