Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm_trace/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void Stats::reset()

void Stats::increment(const std::string& key, uint64_t value)
{
std::lock_guard lock(stats_mutex);
stats[key] += value;
}

Expand All @@ -33,6 +34,8 @@ void Stats::time(const std::string& key, std::function<void()> f)

std::string Stats::to_string() const
{
std::lock_guard lock(stats_mutex);

std::vector<std::string> result;
result.reserve(stats.size());
for (const auto& [key, value] : stats) {
Expand All @@ -48,6 +51,8 @@ std::string Stats::to_string() const

std::string Stats::aggregate_to_string(const std::string& key_prefix) const
{
std::lock_guard lock(stats_mutex);

uint64_t result = 0;
for (const auto& [key, value] : stats) {
if (key.starts_with(key_prefix)) {
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm_trace/stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <functional>
#include <mutex>
#include <string>
#include <unordered_map>

Expand Down Expand Up @@ -32,6 +33,7 @@ class Stats {
Stats() = default;

std::unordered_map<std::string, uint64_t> stats;
mutable std::mutex stats_mutex;
};

} // namespace bb::avm_trace