Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
stats.cpp
Go to the documentation of this file.
2
3#include <chrono>
4#include <cstdint>
5#include <string>
6#include <vector>
7
8namespace bb::avm2 {
9
11{
12 static Stats stats;
13 return stats;
14}
15
17{
18 stats.clear();
19}
20
21void Stats::increment(const std::string& key, uint64_t value)
22{
23 std::lock_guard lock(stats_mutex);
24 stats[key] += value;
25}
26
27void Stats::time(const std::string& key, const std::function<void()>& f)
28{
29 auto start = std::chrono::system_clock::now();
30 f();
31 auto elapsed = std::chrono::system_clock::now() - start;
32 increment(key + "_ms",
33 static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count()));
34}
35
36std::string Stats::to_string(int depth) const
37{
38 std::lock_guard lock(stats_mutex);
39
40 std::vector<std::string> result;
41 result.reserve(stats.size());
42 for (const auto& [key, value] : stats) {
43 if (std::count(key.begin(), key.end(), '/') < depth) {
44 result.push_back(key + ": " + std::to_string(value));
45 }
46 }
47 std::sort(result.begin(), result.end());
48 std::string joined;
49 for (auto& s : result) {
50 joined += std::move(s) + "\n";
51 }
52 return joined;
53}
54
55} // namespace bb::avm2
void increment(const std::string &key, uint64_t value)
Definition stats.cpp:21
std::string to_string(int depth=2) const
Definition stats.cpp:36
static Stats & get()
Definition stats.cpp:10
std::unordered_map< std::string, uint64_t > stats
Definition stats.hpp:53
void time(const std::string &key, const std::function< void()> &f)
Definition stats.cpp:27
void reset()
Definition stats.cpp:16
std::mutex stats_mutex
Definition stats.hpp:54
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)