@@ -81,19 +81,29 @@ class NvmAdmissionPolicy {
8181 return decision;
8282 }
8383
84- // The method that exposes stats.
84+ // Deprecated. Please use getCounters(visitor)
8585 virtual std::unordered_map<std::string, double > getCounters () final {
86- auto ctrs = getCountersImpl ();
87- ctrs[" ap.called" ] = overallCount_.get ();
88- ctrs[" ap.accepted" ] = accepted_.get ();
89- ctrs[" ap.rejected" ] = rejected_.get ();
86+ std::unordered_map<std::string, double > ctrs;
87+ util::CounterVisitor visitor = [&ctrs](folly::StringPiece k, double v) {
88+ auto keyStr = k.str ();
89+ ctrs.insert ({std::move (keyStr), v});
90+ };
91+ getCounters (visitor);
92+ return ctrs;
93+ }
9094
91- auto visitorUs = [&ctrs](folly::StringPiece name, double count) {
92- ctrs[name.toString ()] = count / 1000 ;
95+ // The method that exposes stats.
96+ virtual void getCounters (const util::CounterVisitor& visitor) final {
97+ getCountersImpl (visitor);
98+ visitor (" ap.called" , overallCount_.get ());
99+ visitor (" ap.accepted" , accepted_.get ());
100+ visitor (" ap.rejected" , rejected_.get ());
101+
102+ auto visitorUs = [&visitor](folly::StringPiece name, double count) {
103+ visitor (name.toString (), count / 1000 );
93104 };
94105 overallLatency_.visitQuantileEstimator (visitorUs, " ap.latency_us" );
95- ctrs[" ap.ttlRejected" ] = ttlRejected_.get ();
96- return ctrs;
106+ visitor (" ap.ttlRejected" , ttlRejected_.get ());
97107 }
98108
99109 // Track access for an item.
@@ -130,9 +140,7 @@ class NvmAdmissionPolicy {
130140 // Implementation specific statistics.
131141 // Please include a prefix/postfix with the name of implementation to avoid
132142 // collision with base level stats.
133- virtual std::unordered_map<std::string, double > getCountersImpl () {
134- return {};
135- }
143+ virtual void getCountersImpl (const util::CounterVisitor&) {}
136144
137145 private:
138146 util::PercentileStats overallLatency_;
@@ -184,13 +192,11 @@ class RejectFirstAP final : public NvmAdmissionPolicy<Cache> {
184192 return trackAndCheckIfSeenBefore (key);
185193 }
186194
187- std::unordered_map<std::string, double > getCountersImpl () final override {
188- std::unordered_map<std::string, double > ctrs;
189- ctrs[" ap.reject_first_keys_tracked" ] = tracker_.numKeysTracked ();
190- ctrs[" ap.reject_first_tracking_window_secs" ] =
191- tracker_.trackingWindowDurationSecs ();
192- ctrs[" ap.reject_first_admits_by_dram_hit" ] = admitsByDramHits_.get ();
193- return ctrs;
195+ void getCountersImpl (const util::CounterVisitor& visitor) final override {
196+ visitor (" ap.reject_first_keys_tracked" , tracker_.numKeysTracked ());
197+ visitor (" ap.reject_first_tracking_window_secs" ,
198+ tracker_.trackingWindowDurationSecs ());
199+ visitor (" ap.reject_first_admits_by_dram_hit" , admitsByDramHits_.get ());
194200 }
195201
196202 private:
0 commit comments