Skip to content

Commit

Permalink
REMOVE STAT OBSERVERS
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 10, 2024
1 parent 47aa75e commit 564f6a7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
8 changes: 1 addition & 7 deletions nano/lib/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void nano::stats::update (key key_a, uint64_t value)
// Counters
auto old (entry->counter.get_value ());
entry->counter.add (value, has_sampling ()); // Only update timestamp when sampling is enabled as this has a performance impact
entry->count_observers.notify (old, entry->counter.get_value ());

if (has_interval_counter () || has_sampling ())
{
auto now = std::chrono::steady_clock::now (); // Only sample clock if necessary as this impacts node performance due to frequent usage
Expand Down Expand Up @@ -461,12 +461,6 @@ void nano::stats::update (key key_a, uint64_t value)
entry->samples.push_back (entry->sample_current);
entry->sample_current.set_value (0);

if (!entry->sample_observers.empty ())
{
auto snapshot (entry->samples);
entry->sample_observers.notify (snapshot);
}

// Log sink
duration = now - log_last_sample_writeout;
if (config.log_interval_samples > 0 && duration.count () > config.log_interval_samples)
Expand Down
32 changes: 0 additions & 32 deletions nano/lib/stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ class stat_entry final

/** Optional histogram for this entry */
std::unique_ptr<stat_histogram> histogram;

/** Zero or more observers for samples. Called at the end of the sample interval. */
nano::observer_set<boost::circular_buffer<stat_datapoint> &> sample_observers;

/** Observers for count. Called on each update. */
nano::observer_set<uint64_t, uint64_t> count_observers;
};

/** Log sink interface */
Expand Down Expand Up @@ -316,32 +310,6 @@ class stats final
*/
void add (stat::type type, stat::detail detail, stat::dir dir, uint64_t value);

/**
* Add a sampling observer for a given counter.
* The observer receives a snapshot of the current sampling. Accessing the sample buffer is thus thread safe.
* To avoid recursion, the observer callback must only use the received data point snapshop, not query the stat object.
* @param observer The observer receives a snapshot of the current samples.
*/
void observe_sample (stat::type type, stat::detail detail, stat::dir dir, std::function<void (boost::circular_buffer<stat_datapoint> &)> observer)
{
get_entry (key{ type, detail, dir })->sample_observers.add (observer);
}

void observe_sample (stat::type type, stat::dir dir, std::function<void (boost::circular_buffer<stat_datapoint> &)> observer)
{
observe_sample (type, stat::detail::all, dir, observer);
}

/**
* Add count observer for a given type, detail and direction combination. The observer receives old and new value.
* To avoid recursion, the observer callback must only use the received counts, not query the stat object.
* @param observer The observer receives the old and the new count.
*/
void observe_count (stat::type type, stat::detail detail, stat::dir dir, std::function<void (uint64_t, uint64_t)> observer)
{
get_entry (key{ type, detail, dir })->count_observers.add (observer);
}

/** Returns a potentially empty list of the last N samples, where N is determined by the 'capacity' configuration */
boost::circular_buffer<stat_datapoint> * samples (stat::type type, stat::detail detail, stat::dir dir)
{
Expand Down

0 comments on commit 564f6a7

Please sign in to comment.