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]. |
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 |