InstrumentationContext.st
author Stefan Vogel <sv@exept.de>
Mon, 12 Dec 2016 16:38:47 +0100
changeset 4080 08869106d07e
parent 4008 21b0132a3925
child 4162 3a7f6aa12b81
permissions -rw-r--r--
#BUGFIX by stefan class: Parser comment/format in: #checkSelector:for:inClass: changed: #selectorCheck:for:positions: avoid symbol creation better message if method selector is totally unknown
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
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
     Smalltalk loadPackage:'exept:regression'.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
     BTree withAllPrivateClasses 
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"
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   158
!
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
runForCoverage:aBlock
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   161
    "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
   162
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   163
    self new runForCoverage:aBlock.
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   164
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
     Smalltalk loadPackage:'exept:regression'.
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   167
     BTree withAllPrivateClasses 
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   168
        do:[:cls | cls recompileUsingCompilerClass:InstrumentingCompiler].
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   169
     InstrumentationContext
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   170
        run:[ RegressionTests::BinaryTreeTester suite run ].
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   171
     (Tools::NewSystemBrowser open)
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   172
        switchToClass:BTree;
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   173
        showCoverageInformation value:true
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   174
    "
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
    "Created: / 08-08-2011 / 15:47:10 / cg"
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   179
!InstrumentationContext class methodsFor:'utilities'!
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   180
2942
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   181
flushAllPerProcessInstrumentationContexts
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   182
    Process allInstancesDo:[:eachProcess |
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   183
        eachProcess environmentAt:#instrumentationContext put:nil
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   184
    ].
3453
ffbbed0fe172 class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
   185
    LastProcess := nil.
2942
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   186
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   187
    "
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   188
     self flushAllPerProcessInstrumentationContexts
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
!
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
globalInstrumentationContext
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   193
    ^ GlobalInstrumentationContext
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   194
!
2f6d164949bf fixes and tuning
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
   195
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   196
setGlobalInstrumentationContext:aContextOrNil
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   197
    "setup for global instrumentation: instrumentation is performed for all processes"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   198
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   199
    GlobalInstrumentationContext := aContextOrNil.
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   200
    LastInstrumentationContext := LastProcess := nil.
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   201
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   202
    "Created: / 21-09-2011 / 19:07:00 / cg"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   203
!
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   204
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   205
setInstrumentationContext:aContextOrNil in:aProcess
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   206
    "setup for process specific instrumentation: 
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   207
        instrumentation is aProcess"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   208
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   209
    "in order to keep the knowledge about which environment-variable is used
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   210
     at least local..."
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   211
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   212
    aProcess environmentAt:#instrumentationContext put:aContextOrNil.
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   213
    LastInstrumentationContext := LastProcess := nil.
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   214
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   215
    "Created: / 17-08-2011 / 11:53:19 / cg"
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
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
!InstrumentationContext methodsFor:'accessing'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
2710
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   220
coverageOnly
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   221
    "if on, only keep track of coverage (not counting);
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   222
     if off, we also count how often the code has been entered,
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   223
     and by which sender"
2710
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   224
2980
0202d500e04d class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2979
diff changeset
   225
    ^ coverageOnly ? false
2710
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   226
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   227
    "Created: / 23-08-2011 / 21:25:46 / cg"
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
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   230
coverageOnly:aBoolean
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   231
    "if on, only keep track of coverage (not counting);
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   232
     if off, we also count how often the code has been entered"
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   233
f2e7d18ca6c8 class definition
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   234
    coverageOnly := aBoolean.
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
    "Created: / 23-08-2011 / 21:25:37 / cg"
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
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
enabled
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
    ^ enabled
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
enabled:aBoolean
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    enabled := aBoolean.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    "Modified (format): / 08-08-2011 / 14:47:12 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
inInstrumentedCode
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    ^ inInstrumentedCode ? false
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    "Modified: / 07-08-2011 / 16:57:15 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
inInstrumentedCode:aBoolean
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
    inInstrumentedCode := aBoolean.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    "Modified (format): / 08-08-2011 / 19:43:19 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
!InstrumentationContext methodsFor:'initialization'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
initialize
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
    "Invoked when a new instance is created."
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    inInstrumentedCode := false.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    enabled := true.
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    "/ super initialize.   -- commented since inherited method does nothing
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    "Modified: / 08-08-2011 / 15:44:59 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
!InstrumentationContext methodsFor:'installing'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   276
beActiveEverywhere
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   277
    "become the current instrumentaion context for all processes."
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   278
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   279
    self class setGlobalInstrumentationContext:self. 
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   280
    LastInstrumentationContext := LastProcess := nil.
2706
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   281
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   282
    "
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   283
     InstrumentationContext new beActiveEverywhere
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   284
    "
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   285
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   286
    "Created: / 21-09-2011 / 19:08:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   287
!
Claus Gittinger <cg@exept.de>
parents: 2673
diff changeset
   288
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
beActiveIn:aProcess
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
    "become the current instrumentaion context for a process."
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
2672
ca4221b5143e changed: #beActiveIn:
Claus Gittinger <cg@exept.de>
parents: 2664
diff changeset
   292
    self class setInstrumentationContext:self in:aProcess.
2874
68b98f42a54f class definition
Claus Gittinger <cg@exept.de>
parents: 2710
diff changeset
   293
    LastInstrumentationContext := LastProcess := nil.
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
     InstrumentationContext new beActiveIn:(Processor activeProcess)
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
    "
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
    "Created: / 08-08-2011 / 14:46:09 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
!InstrumentationContext methodsFor:'queries'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
enabledAndNotInInstrumentedCode
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
    ^ enabled and:[ inInstrumentedCode not ]
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
    "Created: / 08-08-2011 / 15:44:30 / cg"
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
! !
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   310
!InstrumentationContext methodsFor:'running'!
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   311
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   312
run:aBlock
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   313
    "run aBlock with instrumentation enabled"
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   314
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   315
    |activeProcess|
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   316
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   317
    activeProcess := Processor activeProcess.
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   318
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   319
    [
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   320
        self beActiveIn:activeProcess.
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   321
        aBlock value
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   322
    ] ensure:[
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   323
        self class setInstrumentationContext:nil in:activeProcess
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   324
    ].
2664
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   325
c23a731f19c5 class definition
Claus Gittinger <cg@exept.de>
parents: 2657
diff changeset
   326
    "Modified: / 17-08-2011 / 11:53:54 / cg"
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   327
!
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   328
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   329
runForCoverage:aBlock
4008
21b0132a3925 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3919
diff changeset
   330
    "run aBlock with instrumentation enabled;
21b0132a3925 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3919
diff changeset
   331
     but only for coverage (i.e. not counting)"
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   332
2980
0202d500e04d class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2979
diff changeset
   333
    coverageOnly := true.
2979
e4ccf860e34a class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2959
diff changeset
   334
    self run:aBlock
2657
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   335
! !
158e4e722319 added: #run:
Claus Gittinger <cg@exept.de>
parents: 2629
diff changeset
   336
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
!InstrumentationContext class methodsFor:'documentation'!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
version
3919
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
   340
    ^ '$Header$'
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
!
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
version_CVS
3919
2ba8a72b1c20 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3547
diff changeset
   344
    ^ '$Header$'
2629
d3561a472a75 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
! !
3453
ffbbed0fe172 class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents: 2980
diff changeset
   346