MessageTracer.st
changeset 327 551f090d9107
parent 326 ae19c52d6096
child 352 ac12b5bc2754
equal deleted inserted replaced
326:ae19c52d6096 327:551f090d9107
   678 
   678 
   679     "Created: 15.12.1995 / 11:01:56 / cg"
   679     "Created: 15.12.1995 / 11:01:56 / cg"
   680     "Modified: 15.12.1995 / 15:45:15 / cg"
   680     "Modified: 15.12.1995 / 15:45:15 / cg"
   681 !
   681 !
   682 
   682 
       
   683 isCounting:aMethod
       
   684     "return true if aMethod is counted"
       
   685 
       
   686     MethodCounts isNil ifTrue:[^ false].
       
   687     (MethodCounts includesKey:aMethod) ifTrue:[^ true].
       
   688     aMethod isWrapped ifTrue:[
       
   689 	^ MethodCounts includesKey:aMethod originalMethod
       
   690     ].
       
   691     ^ false
       
   692 
       
   693     "Created: 15.12.1995 / 11:07:58 / cg"
       
   694     "Modified: 15.12.1995 / 15:42:10 / cg"
       
   695 !
       
   696 
       
   697 stopCountingMethod:aMethod
       
   698     "remove counting of aMethod"
       
   699 
       
   700     ^ self unwrapMethod:aMethod
       
   701 
       
   702     "Modified: 15.12.1995 / 15:43:53 / cg"
       
   703 ! !
       
   704 
       
   705 !MessageTracer class methodsFor:'method memory usage'!
       
   706 
       
   707 countMemoryUsageOfMethod:aMethod
       
   708     "arrange for aMethods memory usage to be counted.
       
   709      Use unwrapMethod to remove this."
       
   710 
       
   711     |lvl inside oldPriority oldScavengeCount oldNewUsed|
       
   712 
       
   713     MethodCounts isNil ifTrue:[
       
   714 	MethodCounts := IdentityDictionary new.
       
   715     ].
       
   716     MethodMemoryUsage isNil ifTrue:[
       
   717 	MethodMemoryUsage := IdentityDictionary new.
       
   718     ].
       
   719 
       
   720     MethodCounts at:aMethod put:0.
       
   721     MethodMemoryUsage at:aMethod put:0.
       
   722 
       
   723     ^ self wrapMethod:aMethod
       
   724 	 onEntry:[:con |
       
   725 			oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority).
       
   726 			oldNewUsed := ObjectMemory newSpaceUsed.
       
   727 			oldScavengeCount := ObjectMemory scavengeCount.
       
   728 		 ]
       
   729 	 onExit:[:con :retVal |
       
   730 	     |cnt memUse scavenges|
       
   731 
       
   732 	     memUse := ObjectMemory newSpaceUsed - oldNewUsed.
       
   733 	     scavenges := ObjectMemory scavengeCount - oldScavengeCount.
       
   734 	     scavenges ~= 0 ifTrue:[
       
   735 		memUse := memUse + (ObjectMemory newSpaceSize * scavenges)
       
   736 	     ].
       
   737 
       
   738 	     MethodCounts notNil ifTrue:[
       
   739 		 cnt := MethodCounts at:aMethod ifAbsent:0.
       
   740 		 MethodCounts at:aMethod put:(cnt + 1).
       
   741 	     ].
       
   742 	     MethodMemoryUsage notNil ifTrue:[
       
   743 		 cnt := MethodMemoryUsage at:aMethod ifAbsent:0.
       
   744 		 MethodMemoryUsage at:aMethod put:(cnt + memUse).
       
   745 	     ].
       
   746 	     Processor activeProcess priority:oldPriority                
       
   747 	 ]
       
   748 	 onUnwind:[
       
   749 	     oldPriority notNil ifTrue:[
       
   750 		 Processor activeProcess priority:oldPriority
       
   751 	     ]
       
   752 	 ]
       
   753 
       
   754     "
       
   755      MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial).
       
   756      3 factorial.
       
   757      (MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorial)) printNL. 
       
   758      MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial) 
       
   759     "
       
   760 
       
   761     "Created: 18.12.1995 / 15:41:27 / stefan"
       
   762     "Modified: 18.12.1995 / 21:46:48 / stefan"
       
   763 !
       
   764 
       
   765 isCountingMemoryUsage:aMethod
       
   766     "return true if aMethod is counting memoryUsage"
       
   767 
       
   768     MethodMemoryUsage isNil ifTrue:[^ false].
       
   769     (MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true].
       
   770     aMethod isWrapped ifTrue:[
       
   771 	^ MethodMemoryUsage includesKey:aMethod originalMethod
       
   772     ].
       
   773     ^ false
       
   774 
       
   775     "Created: 18.12.1995 / 15:51:49 / stefan"
       
   776 !
       
   777 
       
   778 memoryUsageOfMethod:aMethod
       
   779     "return the current count"
       
   780 
       
   781     |count memUse|
       
   782 
       
   783     (MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0].
       
   784     aMethod isWrapped ifTrue:[
       
   785 	count := MethodCounts at:aMethod originalMethod ifAbsent:nil.
       
   786 	memUse := MethodMemoryUsage at:aMethod originalMethod ifAbsent:nil.
       
   787     ].
       
   788     memUse isNil ifTrue:[
       
   789 	count := MethodCounts at:aMethod ifAbsent:0.
       
   790 	memUse := MethodMemoryUsage at:aMethod ifAbsent:0.
       
   791     ].
       
   792     count = 0 ifTrue:[^ 0].
       
   793     ^ memUse//count
       
   794 
       
   795     "Modified: 18.12.1995 / 16:25:51 / stefan"
       
   796 !
       
   797 
       
   798 stopCountingMemoryUsageOfMethod:aMethod
       
   799     "remove counting memory of aMethod"
       
   800 
       
   801     ^ self unwrapMethod:aMethod
       
   802 
       
   803     "Modified: 18.12.1995 / 21:54:36 / stefan"
       
   804 ! !
       
   805 
       
   806 !MessageTracer class methodsFor:'method timing'!
       
   807 
   683 executionTimesOfMethod:aMethod
   808 executionTimesOfMethod:aMethod
   684     "return the current times"
   809     "return the current times"
   685 
   810 
   686     |count info min max avg ret|
   811     |count info min max avg ret|
   687 
   812 
   707 
   832 
   708     "Created: 17.6.1996 / 17:07:30 / cg"
   833     "Created: 17.6.1996 / 17:07:30 / cg"
   709     "Modified: 17.6.1996 / 17:08:24 / cg"
   834     "Modified: 17.6.1996 / 17:08:24 / cg"
   710 !
   835 !
   711 
   836 
   712 isCounting:aMethod
       
   713     "return true if aMethod is counted"
       
   714 
       
   715     MethodCounts isNil ifTrue:[^ false].
       
   716     (MethodCounts includesKey:aMethod) ifTrue:[^ true].
       
   717     aMethod isWrapped ifTrue:[
       
   718 	^ MethodCounts includesKey:aMethod originalMethod
       
   719     ].
       
   720     ^ false
       
   721 
       
   722     "Created: 15.12.1995 / 11:07:58 / cg"
       
   723     "Modified: 15.12.1995 / 15:42:10 / cg"
       
   724 !
       
   725 
       
   726 isTiming:aMethod
   837 isTiming:aMethod
   727     "return true if aMethod is timed"
   838     "return true if aMethod is timed"
   728 
   839 
   729     MethodTiming isNil ifTrue:[^ false].
   840     MethodTiming isNil ifTrue:[^ false].
   730     (MethodTiming includesKey:aMethod) ifTrue:[^ true].
   841     (MethodTiming includesKey:aMethod) ifTrue:[^ true].
   733     ].
   844     ].
   734     ^ false
   845     ^ false
   735 
   846 
   736     "Modified: 15.12.1995 / 15:42:10 / cg"
   847     "Modified: 15.12.1995 / 15:42:10 / cg"
   737     "Created: 17.6.1996 / 17:04:29 / cg"
   848     "Created: 17.6.1996 / 17:04:29 / cg"
   738 !
       
   739 
       
   740 stopCountingMethod:aMethod
       
   741     "remove counting of aMethod"
       
   742 
       
   743     ^ self unwrapMethod:aMethod
       
   744 
       
   745     "Modified: 15.12.1995 / 15:43:53 / cg"
       
   746 !
   849 !
   747 
   850 
   748 stopTimingMethod:aMethod
   851 stopTimingMethod:aMethod
   749     "remove timing of aMethod"
   852     "remove timing of aMethod"
   750 
   853 
   805      MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) 
   908      MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) 
   806     "
   909     "
   807 
   910 
   808     "Created: 17.6.1996 / 17:03:50 / cg"
   911     "Created: 17.6.1996 / 17:03:50 / cg"
   809     "Modified: 17.6.1996 / 17:10:43 / cg"
   912     "Modified: 17.6.1996 / 17:10:43 / cg"
   810 ! !
       
   811 
       
   812 !MessageTracer class methodsFor:'method memory usage'!
       
   813 
       
   814 countMemoryUsageOfMethod:aMethod
       
   815     "arrange for aMethods memory usage to be counted.
       
   816      Use unwrapMethod to remove this."
       
   817 
       
   818     |lvl inside oldPriority oldScavengeCount oldNewUsed|
       
   819 
       
   820     MethodCounts isNil ifTrue:[
       
   821 	MethodCounts := IdentityDictionary new.
       
   822     ].
       
   823     MethodMemoryUsage isNil ifTrue:[
       
   824 	MethodMemoryUsage := IdentityDictionary new.
       
   825     ].
       
   826 
       
   827     MethodCounts at:aMethod put:0.
       
   828     MethodMemoryUsage at:aMethod put:0.
       
   829 
       
   830     ^ self wrapMethod:aMethod
       
   831 	 onEntry:[:con |
       
   832 			oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority).
       
   833 			oldNewUsed := ObjectMemory newSpaceUsed.
       
   834 			oldScavengeCount := ObjectMemory scavengeCount.
       
   835 		 ]
       
   836 	 onExit:[:con :retVal |
       
   837 	     |cnt memUse scavenges|
       
   838 
       
   839 	     memUse := ObjectMemory newSpaceUsed - oldNewUsed.
       
   840 	     scavenges := ObjectMemory scavengeCount - oldScavengeCount.
       
   841 	     scavenges ~= 0 ifTrue:[
       
   842 		memUse := memUse + (ObjectMemory newSpaceSize * scavenges)
       
   843 	     ].
       
   844 
       
   845 	     MethodCounts notNil ifTrue:[
       
   846 		 cnt := MethodCounts at:aMethod ifAbsent:0.
       
   847 		 MethodCounts at:aMethod put:(cnt + 1).
       
   848 	     ].
       
   849 	     MethodMemoryUsage notNil ifTrue:[
       
   850 		 cnt := MethodMemoryUsage at:aMethod ifAbsent:0.
       
   851 		 MethodMemoryUsage at:aMethod put:(cnt + memUse).
       
   852 	     ].
       
   853 	     Processor activeProcess priority:oldPriority                
       
   854 	 ]
       
   855 	 onUnwind:[
       
   856 	     oldPriority notNil ifTrue:[
       
   857 		 Processor activeProcess priority:oldPriority
       
   858 	     ]
       
   859 	 ]
       
   860 
       
   861     "
       
   862      MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial).
       
   863      3 factorial.
       
   864      (MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorial)) printNL. 
       
   865      MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial) 
       
   866     "
       
   867 
       
   868     "Created: 18.12.1995 / 15:41:27 / stefan"
       
   869     "Modified: 18.12.1995 / 21:46:48 / stefan"
       
   870 !
       
   871 
       
   872 isCountingMemoryUsage:aMethod
       
   873     "return true if aMethod is counting memoryUsage"
       
   874 
       
   875     MethodMemoryUsage isNil ifTrue:[^ false].
       
   876     (MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true].
       
   877     aMethod isWrapped ifTrue:[
       
   878 	^ MethodMemoryUsage includesKey:aMethod originalMethod
       
   879     ].
       
   880     ^ false
       
   881 
       
   882     "Created: 18.12.1995 / 15:51:49 / stefan"
       
   883 !
       
   884 
       
   885 memoryUsageOfMethod:aMethod
       
   886     "return the current count"
       
   887 
       
   888     |count memUse|
       
   889 
       
   890     (MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0].
       
   891     aMethod isWrapped ifTrue:[
       
   892 	count := MethodCounts at:aMethod originalMethod ifAbsent:nil.
       
   893 	memUse := MethodMemoryUsage at:aMethod originalMethod ifAbsent:nil.
       
   894     ].
       
   895     memUse isNil ifTrue:[
       
   896 	count := MethodCounts at:aMethod ifAbsent:0.
       
   897 	memUse := MethodMemoryUsage at:aMethod ifAbsent:0.
       
   898     ].
       
   899     count = 0 ifTrue:[^ 0].
       
   900     ^ memUse//count
       
   901 
       
   902     "Modified: 18.12.1995 / 16:25:51 / stefan"
       
   903 !
       
   904 
       
   905 stopCountingMemoryUsageOfMethod:aMethod
       
   906     "remove counting memory of aMethod"
       
   907 
       
   908     ^ self unwrapMethod:aMethod
       
   909 
       
   910     "Modified: 18.12.1995 / 21:54:36 / stefan"
       
   911 ! !
   913 ! !
   912 
   914 
   913 !MessageTracer class methodsFor:'method tracing'!
   915 !MessageTracer class methodsFor:'method tracing'!
   914 
   916 
   915 traceMethod:aMethod
   917 traceMethod:aMethod
  1037             MethodMemoryUsage removeKey:aMethod originalMethod ifAbsent:nil.
  1039             MethodMemoryUsage removeKey:aMethod originalMethod ifAbsent:nil.
  1038         ].
  1040         ].
  1039         MethodMemoryUsage removeKey:aMethod ifAbsent:nil.
  1041         MethodMemoryUsage removeKey:aMethod ifAbsent:nil.
  1040         MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil].
  1042         MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil].
  1041     ].
  1043     ].
       
  1044     MethodTiming notNil ifTrue:[
       
  1045         aMethod isWrapped ifTrue:[
       
  1046             MethodTiming removeKey:aMethod originalMethod ifAbsent:nil.
       
  1047         ].
       
  1048         MethodTiming removeKey:aMethod ifAbsent:nil.
       
  1049         MethodTiming isEmpty ifTrue:[MethodTiming := nil].
       
  1050     ].
  1042 
  1051 
  1043     CallingLevel := 0.
  1052     CallingLevel := 0.
  1044 
  1053 
  1045     (aMethod isNil or:[aMethod isWrapped not]) ifTrue:[
  1054     (aMethod isNil or:[aMethod isWrapped not]) ifTrue:[
  1046         ^ aMethod
  1055         ^ aMethod
  1073     ].
  1082     ].
  1074 
  1083 
  1075     ObjectMemory flushCaches.
  1084     ObjectMemory flushCaches.
  1076     ^ originalMethod
  1085     ^ originalMethod
  1077 
  1086 
  1078     "Modified: 20.5.1996 / 10:32:53 / cg"
       
  1079     "Modified: 5.6.1996 / 14:08:08 / stefan"
  1087     "Modified: 5.6.1996 / 14:08:08 / stefan"
       
  1088     "Modified: 17.6.1996 / 17:20:43 / cg"
  1080 !
  1089 !
  1081 
  1090 
  1082 wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock
  1091 wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock
  1083     ^ self wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:nil
  1092     ^ self wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:nil
  1084 
  1093 
  1835 ! !
  1844 ! !
  1836 
  1845 
  1837 !MessageTracer class methodsFor:'documentation'!
  1846 !MessageTracer class methodsFor:'documentation'!
  1838 
  1847 
  1839 version
  1848 version
  1840     ^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.40 1996-06-17 15:19:09 cg Exp $'
  1849     ^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.41 1996-06-17 15:21:20 cg Exp $'
  1841 ! !
  1850 ! !
  1842 MessageTracer initialize!
  1851 MessageTracer initialize!