899 * 900 * { 901 * PerfTraceTime ptt(my_time_counter); 902 * // perform the operation you want to measure 903 * } 904 * 905 * Note: use of this class does not need to occur within a guarded 906 * block. The UsePerfData guard is used with the implementation 907 * of this class. 908 */ 909 class PerfTraceTime : public StackObj { 910 911 protected: 912 elapsedTimer _t; 913 PerfLongCounter* _timerp; 914 // pointer to thread-local or global recursion counter variable 915 int* _recursion_counter; 916 917 public: 918 inline PerfTraceTime(PerfLongCounter* timerp) : _timerp(timerp), _recursion_counter(NULL) { 919 if (!UsePerfData) return; 920 _t.start(); 921 } 922 923 inline PerfTraceTime(PerfLongCounter* timerp, int* recursion_counter) : _timerp(timerp), _recursion_counter(recursion_counter) { 924 if (!UsePerfData || (_recursion_counter != NULL && 925 (*_recursion_counter)++ > 0)) return; 926 _t.start(); 927 } 928 929 inline void suspend() { if (!UsePerfData) return; _t.stop(); } 930 inline void resume() { if (!UsePerfData) return; _t.start(); } 931 932 inline ~PerfTraceTime() { 933 if (!UsePerfData || (_recursion_counter != NULL && 934 --(*_recursion_counter) > 0)) return; 935 _t.stop(); 936 _timerp->inc(_t.ticks()); 937 } 938 }; 939 940 /* The PerfTraceTimedEvent class is responsible for counting the 941 * occurrence of some event and measuring the the elapsed time of 942 * the event in two separate PerfCounter instances. 943 * 944 * Example: 945 * 946 * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, CHECK); 947 * static PerfCounter* my_event_counter = PerfDataManager::create_counter("my.event.counter", PerfData::U_Events, CHECK); 948 * 949 * { 950 * PerfTraceTimedEvent ptte(my_time_counter, my_event_counter); 951 * // perform the operation you want to count and measure 952 * } 953 * 954 * Note: use of this class does not need to occur within a guarded 955 * block. The UsePerfData guard is used with the implementation 956 * of this class. 957 * 958 */ 959 class PerfTraceTimedEvent : public PerfTraceTime { 960 961 protected: 962 PerfLongCounter* _eventp; 963 964 public: 965 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp): PerfTraceTime(timerp), _eventp(eventp) { 966 if (!UsePerfData) return; 967 _eventp->inc(); 968 } 969 970 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp, int* recursion_counter): PerfTraceTime(timerp, recursion_counter), _eventp(eventp) { 971 if (!UsePerfData) return; 972 _eventp->inc(); 973 } 974 }; 975 976 #endif // SHARE_VM_RUNTIME_PERFDATA_HPP | 899 * 900 * { 901 * PerfTraceTime ptt(my_time_counter); 902 * // perform the operation you want to measure 903 * } 904 * 905 * Note: use of this class does not need to occur within a guarded 906 * block. The UsePerfData guard is used with the implementation 907 * of this class. 908 */ 909 class PerfTraceTime : public StackObj { 910 911 protected: 912 elapsedTimer _t; 913 PerfLongCounter* _timerp; 914 // pointer to thread-local or global recursion counter variable 915 int* _recursion_counter; 916 917 public: 918 inline PerfTraceTime(PerfLongCounter* timerp) : _timerp(timerp), _recursion_counter(NULL) { 919 if (!UsePerfData || (_timerp == NULL)) return; 920 _t.start(); 921 } 922 923 inline PerfTraceTime(PerfLongCounter* timerp, int* recursion_counter) : _timerp(timerp), _recursion_counter(recursion_counter) { 924 if (!UsePerfData || (_timerp == NULL) || 925 (_recursion_counter != NULL && (*_recursion_counter)++ > 0)) return; 926 _t.start(); 927 } 928 929 inline void suspend() { if (!UsePerfData || (_timerp == NULL)) return; _t.stop(); } 930 inline void resume() { if (!UsePerfData || (_timerp == NULL)) return; _t.start(); } 931 932 inline ~PerfTraceTime() { 933 if (!UsePerfData || (_timerp == NULL) || 934 (_recursion_counter != NULL && --(*_recursion_counter) > 0)) return; 935 _t.stop(); 936 _timerp->inc(_t.ticks()); 937 } 938 }; 939 940 /* The PerfTraceTimedEvent class is responsible for counting the 941 * occurrence of some event and measuring the the elapsed time of 942 * the event in two separate PerfCounter instances. 943 * 944 * Example: 945 * 946 * static PerfCounter* my_time_counter = PerfDataManager::create_counter("my.time.counter", PerfData::U_Ticks, CHECK); 947 * static PerfCounter* my_event_counter = PerfDataManager::create_counter("my.event.counter", PerfData::U_Events, CHECK); 948 * 949 * { 950 * PerfTraceTimedEvent ptte(my_time_counter, my_event_counter); 951 * // perform the operation you want to count and measure 952 * } 953 * 954 * Note: use of this class does not need to occur within a guarded 955 * block. The UsePerfData guard is used with the implementation 956 * of this class. 957 * 958 */ 959 class PerfTraceTimedEvent : public PerfTraceTime { 960 961 protected: 962 PerfLongCounter* _eventp; 963 964 public: 965 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp): PerfTraceTime(timerp), _eventp(eventp) { 966 if (!UsePerfData || (timerp == NULL)) return; 967 _eventp->inc(); 968 } 969 970 inline PerfTraceTimedEvent(PerfLongCounter* timerp, PerfLongCounter* eventp, int* recursion_counter): PerfTraceTime(timerp, recursion_counter), _eventp(eventp) { 971 if (!UsePerfData || (timerp == NULL)) return; 972 _eventp->inc(); 973 } 974 }; 975 976 #endif // SHARE_VM_RUNTIME_PERFDATA_HPP |