InstrumentingCompiler.st
changeset 2368 e48d46439c08
parent 2359 b70f2c9dddcf
child 2370 a801cc4df234
equal deleted inserted replaced
2367:0ac586956983 2368:e48d46439c08
    34 	poolDictionaries:''
    34 	poolDictionaries:''
    35 	privateIn:InstrumentingCompiler::MethodInvocationInfo
    35 	privateIn:InstrumentingCompiler::MethodInvocationInfo
    36 !
    36 !
    37 
    37 
    38 Object subclass:#MethodInvocationInfoPerSendingMethod
    38 Object subclass:#MethodInvocationInfoPerSendingMethod
    39 	instanceVariableNames:'countPerSendersClass'
    39 	instanceVariableNames:'countPerSendersClass invokedViaPerform'
    40 	classVariableNames:''
    40 	classVariableNames:''
    41 	poolDictionaries:''
    41 	poolDictionaries:''
    42 	privateIn:InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass
    42 	privateIn:InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass
    43 !
    43 !
    44 
    44 
   330     ^ infoPerReceiverClass notEmptyOrNil
   330     ^ infoPerReceiverClass notEmptyOrNil
   331 
   331 
   332     "Created: / 27-04-2010 / 13:43:15 / cg"
   332     "Created: / 27-04-2010 / 13:43:15 / cg"
   333 !
   333 !
   334 
   334 
       
   335 invokedViaPerform
       
   336     ^ infoPerReceiverClass contains:[:someInfo | someInfo invokedViaPerform].
       
   337 
       
   338     "Created: / 27-04-2010 / 18:21:56 / cg"
       
   339 !
       
   340 
   335 invokingMethods
   341 invokingMethods
   336     |setOfMethods|
   342     |setOfMethods|
   337 
   343 
   338     setOfMethods := IdentitySet new.
   344     setOfMethods := IdentitySet new.
   339     self invokingMethodsDo:[:m | setOfMethods add:m].
   345     self invokingMethodsDo:[:m | setOfMethods add:m].
   401 
   407 
   402 callingMethodsDo:aBlock
   408 callingMethodsDo:aBlock
   403     infoPerSendingMethod keysAndValuesDo:[:m :eachInfo |
   409     infoPerSendingMethod keysAndValuesDo:[:m :eachInfo |
   404         aBlock value:m
   410         aBlock value:m
   405     ]
   411     ]
       
   412 !
       
   413 
       
   414 invokedViaPerform
       
   415     ^ infoPerSendingMethod contains:[:someInfo | someInfo invokedViaPerform].
       
   416 
       
   417     "Created: / 27-04-2010 / 18:21:36 / cg"
   406 !
   418 !
   407 
   419 
   408 invokingMethodsDo:aBlock
   420 invokingMethodsDo:aBlock
   409     infoPerSendingMethod isNil ifTrue:[ ^ self].
   421     infoPerSendingMethod isNil ifTrue:[ ^ self].
   410     ^ infoPerSendingMethod keysDo:aBlock.
   422     ^ infoPerSendingMethod keysDo:aBlock.
   458 !InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'instrumentation calls'!
   470 !InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'instrumentation calls'!
   459 
   471 
   460 entry:aContext
   472 entry:aContext
   461     "invoked by instrumented compiled code, upon method entry"
   473     "invoked by instrumented compiled code, upon method entry"
   462 
   474 
   463     |sender sendingMethod infoPerMethod|
   475     |sender sendingMethod infoPerMethod viaPerform|
   464 
   476 
   465     sender := aContext sender methodHome.
   477     sender := aContext sender methodHome.
   466     sendingMethod := sender method.
   478     sendingMethod := sender method.
       
   479     viaPerform := false.
   467 
   480 
   468     (sendingMethod mclass == Object 
   481     (sendingMethod mclass == Object 
   469     and:[ sendingMethod selector startsWith:'perform:'] ) ifTrue:[
   482     and:[ sendingMethod selector startsWith:'perform:'] ) ifTrue:[
   470         Transcript showCR:('%1 [info]: skipping #perform' bindWith:self class nameWithoutPrefix).
   483         "/ Transcript showCR:('%1 [info]: skipping #perform' bindWith:self class nameWithoutPrefix).
   471         sender := sender sender methodHome.
   484         sender := sender sender methodHome.
   472         sendingMethod := sender method.
   485         sendingMethod := sender method.
       
   486         viaPerform := true.
   473     ].
   487     ].
   474 
   488 
   475     infoPerSendingMethod isNil ifTrue:[
   489     infoPerSendingMethod isNil ifTrue:[
   476         infoPerSendingMethod := IdentityDictionary new.
   490         infoPerSendingMethod := IdentityDictionary new.
   477     ].
   491     ].
   478     infoPerMethod := infoPerSendingMethod 
   492     infoPerMethod := infoPerSendingMethod 
   479                         at:sendingMethod 
   493                         at:sendingMethod 
   480                         ifAbsentPut:[ MethodInvocationInfoPerSendingMethod new ].
   494                         ifAbsentPut:[ MethodInvocationInfoPerSendingMethod new ].
   481     infoPerMethod entry:aContext
   495 
   482 
   496     infoPerMethod entry:aContext viaPerform:viaPerform
   483     "Modified: / 27-04-2010 / 12:13:08 / cg"
   497 
       
   498     "Modified: / 27-04-2010 / 18:19:04 / cg"
   484 ! !
   499 ! !
   485 
   500 
   486 !InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'accessing'!
   501 !InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'accessing'!
       
   502 
       
   503 invokedViaPerform
       
   504     ^ invokedViaPerform ? false
       
   505 
       
   506     "Created: / 27-04-2010 / 18:20:05 / cg"
       
   507 !
   487 
   508 
   488 numberOfInvocations
   509 numberOfInvocations
   489     countPerSendersClass isNil ifTrue:[ ^ 0].
   510     countPerSendersClass isNil ifTrue:[ ^ 0].
   490     ^ countPerSendersClass inject:0 into:[:sumSoFar :count | sumSoFar + count] 
   511     ^ countPerSendersClass inject:0 into:[:sumSoFar :count | sumSoFar + count] 
   491 ! !
   512 ! !
   492 
   513 
   493 !InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'instrumentation calls'!
   514 !InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'instrumentation calls'!
   494 
   515 
   495 entry:aContext
   516 entry:aContext viaPerform:viaPerformBoolean
   496     "invoked by instrumented compiled code, upon method entry"
   517     "invoked by instrumented compiled code, upon method entry"
   497 
   518 
   498     |sendersClass count|
   519     |sendersClass count|
   499 
   520 
   500     sendersClass := aContext sender receiver class.
   521     sendersClass := aContext sender receiver class.
   501 
   522 
   502     countPerSendersClass isNil ifTrue:[
   523     countPerSendersClass isNil ifTrue:[
   503         countPerSendersClass := IdentityDictionary new.
   524         countPerSendersClass := IdentityDictionary new.
   504     ].
   525     ].
   505     count := countPerSendersClass at:sendersClass ifAbsentPut:0.
   526     count := countPerSendersClass at:sendersClass ifAbsentPut:0.
   506     countPerSendersClass at:sendersClass put:(count + 1)
   527     countPerSendersClass at:sendersClass put:(count + 1).
       
   528     viaPerformBoolean ifTrue:[ invokedViaPerform := true ].
       
   529 
       
   530     "Created: / 27-04-2010 / 18:17:27 / cg"
   507 ! !
   531 ! !
   508 
   532 
   509 !InstrumentingCompiler class methodsFor:'documentation'!
   533 !InstrumentingCompiler class methodsFor:'documentation'!
   510 
   534 
   511 version_CVS
   535 version_CVS
   512     ^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.2 2010-04-27 12:54:19 cg Exp $'
   536     ^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.3 2010-04-27 17:04:32 cg Exp $'
   513 ! !
   537 ! !