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