@@ -183,6 +183,31 @@ void PerfCounters::inc(int idx, uint64_t amt)
183183 }
184184}
185185
186+ void PerfCounters::inc_with_max (int idx, uint64_t amt)
187+ {
188+ #ifndef WITH_CRIMSON
189+ if (!m_cct->_conf ->perf )
190+ return ;
191+ #endif
192+
193+ ceph_assert (idx > m_lower_bound);
194+ ceph_assert (idx < m_upper_bound);
195+ perf_counter_data_any_d& data (m_data[idx - m_lower_bound - 1 ]);
196+ if (!(data.type & PERFCOUNTER_U64))
197+ return ;
198+ if (data.type & PERFCOUNTER_LONGRUNAVG) {
199+ data.avgcount ++;
200+ data.u64 += amt;
201+ uint64_t m;
202+ do {
203+ m = data.max_u64_inc .load ();
204+ } while (amt > m && !data.max_u64_inc .compare_exchange_weak (m, amt));
205+ data.avgcount2 ++;
206+ } else {
207+ data.u64 += amt;
208+ }
209+ }
210+
186211void PerfCounters::dec (int idx, uint64_t amt)
187212{
188213#ifndef WITH_CRIMSON
@@ -259,6 +284,32 @@ void PerfCounters::tinc(int idx, utime_t amt)
259284 }
260285}
261286
287+ void PerfCounters::tinc_with_max (int idx, utime_t amt)
288+ {
289+ #ifndef WITH_CRIMSON
290+ if (!m_cct->_conf ->perf )
291+ return ;
292+ #endif
293+
294+ ceph_assert (idx > m_lower_bound);
295+ ceph_assert (idx < m_upper_bound);
296+ perf_counter_data_any_d& data (m_data[idx - m_lower_bound - 1 ]);
297+ if (!(data.type & PERFCOUNTER_TIME))
298+ return ;
299+ if (data.type & PERFCOUNTER_LONGRUNAVG) {
300+ uint64_t new_m = amt.to_nsec ();
301+ data.avgcount ++;
302+ data.u64 += new_m;
303+ uint64_t m;
304+ do {
305+ m = data.max_u64_inc .load ();
306+ } while (new_m > m && !data.max_u64_inc .compare_exchange_weak (m, new_m));
307+ data.avgcount2 ++;
308+ } else {
309+ data.u64 += amt.to_nsec ();
310+ }
311+ }
312+
262313void PerfCounters::tinc (int idx, ceph::timespan amt)
263314{
264315#ifndef WITH_CRIMSON
@@ -280,6 +331,32 @@ void PerfCounters::tinc(int idx, ceph::timespan amt)
280331 }
281332}
282333
334+ void PerfCounters::tinc_with_max (int idx, ceph::timespan amt)
335+ {
336+ #ifndef WITH_CRIMSON
337+ if (!m_cct->_conf ->perf )
338+ return ;
339+ #endif
340+
341+ ceph_assert (idx > m_lower_bound);
342+ ceph_assert (idx < m_upper_bound);
343+ perf_counter_data_any_d& data (m_data[idx - m_lower_bound - 1 ]);
344+ if (!(data.type & PERFCOUNTER_TIME))
345+ return ;
346+ if (data.type & PERFCOUNTER_LONGRUNAVG) {
347+ uint64_t new_m = amt.count ();
348+ data.avgcount ++;
349+ data.u64 += new_m;
350+ uint64_t m;
351+ do {
352+ m = data.max_u64_inc .load ();
353+ } while (new_m > m && !data.max_u64_inc .compare_exchange_weak (m, new_m));
354+ data.avgcount2 ++;
355+ } else {
356+ data.u64 += amt.count ();
357+ }
358+ }
359+
283360void PerfCounters::tset (int idx, utime_t amt)
284361{
285362#ifndef WITH_CRIMSON
@@ -361,8 +438,7 @@ pair<uint64_t, uint64_t> PerfCounters::get_tavg_ns(int idx) const
361438 return make_pair (0 , 0 );
362439 if (!(data.type & PERFCOUNTER_LONGRUNAVG))
363440 return make_pair (0 , 0 );
364- pair<uint64_t ,uint64_t > a = data.read_avg ();
365- return make_pair (a.second , a.first );
441+ return data.read_avg ();
366442}
367443
368444void PerfCounters::reset ()
@@ -479,17 +555,27 @@ void PerfCounters::dump_formatted_generic(Formatter *f, bool schema,
479555 } else {
480556 if (d->type & PERFCOUNTER_LONGRUNAVG) {
481557 Formatter::ObjectSection longrunavg_section{*f, d->name };
482- pair <uint64_t ,uint64_t > a = d->read_avg ();
558+ std::tuple <uint64_t ,uint64_t , uint64_t > a = d->read_avg_ex ();
483559 if (d->type & PERFCOUNTER_U64) {
484- f->dump_unsigned (" avgcount" , a.second );
485- f->dump_unsigned (" sum" , a.first );
560+ f->dump_unsigned (" sum" , std::get<0 >(a));
561+ f->dump_unsigned (" avgcount" , std::get<1 >(a));
562+ uint64_t max = std::get<2 >(a);
563+ if (max != 0 ) {
564+ f->dump_unsigned (" max_inc" , std::get<2 >(a));
565+ }
486566 } else if (d->type & PERFCOUNTER_TIME) {
487- f->dump_unsigned (" avgcount" , a.second );
567+ uint64_t sum_ns = std::get<0 >(a);
568+ uint64_t count = std::get<1 >(a);
569+ f->dump_unsigned (" avgcount" , count);
488570 f->dump_format_unquoted (" sum" , " %" PRId64 " .%09" PRId64,
489- a.first / 1000000000ull ,
490- a.first % 1000000000ull );
491- uint64_t count = a.second ;
492- uint64_t sum_ns = a.first ;
571+ sum_ns / 1000000000ull ,
572+ sum_ns % 1000000000ull );
573+ uint64_t max_ns = std::get<2 >(a);
574+ if (max_ns != 0 ) {
575+ f->dump_format_unquoted (" max_inc" , " %" PRId64 " .%09" PRId64,
576+ max_ns / 1000000000ull ,
577+ max_ns % 1000000000ull );
578+ }
493579 if (count) {
494580 uint64_t avg_ns = sum_ns / count;
495581 f->dump_format_unquoted (" avgtime" , " %" PRId64 " .%09" PRId64,
0 commit comments