755 // Stat timer
756 //
757 THREAD_LOCAL uint32_t ZStatTimerDisable::_active = 0;
758
759 //
760 // Stat sample/inc
761 //
762 void ZStatSample(const ZStatSampler& sampler, uint64_t value) {
763 ZStatSamplerData* const cpu_data = sampler.get();
764 Atomic::add(&cpu_data->_nsamples, 1u);
765 Atomic::add(&cpu_data->_sum, value);
766
767 uint64_t max = cpu_data->_max;
768 for (;;) {
769 if (max >= value) {
770 // Not max
771 break;
772 }
773
774 const uint64_t new_max = value;
775 const uint64_t prev_max = Atomic::cmpxchg(new_max, &cpu_data->_max, max);
776 if (prev_max == max) {
777 // Success
778 break;
779 }
780
781 // Retry
782 max = prev_max;
783 }
784
785 ZTracer::tracer()->report_stat_sampler(sampler, value);
786 }
787
788 void ZStatInc(const ZStatCounter& counter, uint64_t increment) {
789 ZStatCounterData* const cpu_data = counter.get();
790 const uint64_t value = Atomic::add(&cpu_data->_counter, increment);
791
792 ZTracer::tracer()->report_stat_counter(counter, increment, value);
793 }
794
795 void ZStatInc(const ZStatUnsampledCounter& counter, uint64_t increment) {
|
755 // Stat timer
756 //
757 THREAD_LOCAL uint32_t ZStatTimerDisable::_active = 0;
758
759 //
760 // Stat sample/inc
761 //
762 void ZStatSample(const ZStatSampler& sampler, uint64_t value) {
763 ZStatSamplerData* const cpu_data = sampler.get();
764 Atomic::add(&cpu_data->_nsamples, 1u);
765 Atomic::add(&cpu_data->_sum, value);
766
767 uint64_t max = cpu_data->_max;
768 for (;;) {
769 if (max >= value) {
770 // Not max
771 break;
772 }
773
774 const uint64_t new_max = value;
775 const uint64_t prev_max = Atomic::cmpxchg(&cpu_data->_max, max, new_max);
776 if (prev_max == max) {
777 // Success
778 break;
779 }
780
781 // Retry
782 max = prev_max;
783 }
784
785 ZTracer::tracer()->report_stat_sampler(sampler, value);
786 }
787
788 void ZStatInc(const ZStatCounter& counter, uint64_t increment) {
789 ZStatCounterData* const cpu_data = counter.get();
790 const uint64_t value = Atomic::add(&cpu_data->_counter, increment);
791
792 ZTracer::tracer()->report_stat_counter(counter, increment, value);
793 }
794
795 void ZStatInc(const ZStatUnsampledCounter& counter, uint64_t increment) {
|