32 enum ctype { ALLOC = 0, EQUIV = 1 };
39 typedef std::map<PHV::Type, std::pair<unsigned long, unsigned long>> ContainerMetricsMap;
40 ContainerMetricsMap alloc_containers;
41 ContainerMetricsMap equiv_containers;
44 std::chrono::time_point<std::chrono::steady_clock> start_time;
45 std::chrono::time_point<std::chrono::steady_clock> stop_time;
50 cstring get_name()
const {
return name; };
53 void update_container_equivalence_metrics(
const PHV::Container &c) {
54 ++equiv_containers[c.type()].first;
58 void update_containers_metrics(
const PHV::Container &c,
bool succ =
false) {
59 ++alloc_containers[c.type()].first;
60 if (succ) ++alloc_containers[c.type()].second;
63 unsigned long get_containers(
const ctype ct = ALLOC,
const PHV::Kind *kind =
nullptr,
64 const PHV::Size *size =
nullptr,
bool succ =
false)
const {
65 unsigned long containers = 0;
67 const ContainerMetricsMap *cmap =
nullptr;
69 cmap = &alloc_containers;
71 cmap = &equiv_containers;
75 for (
auto ct : *cmap) {
76 if (kind && (ct.first.kind() != *kind))
continue;
77 if (size && (ct.first.size() != *size))
continue;
79 containers += ct.second.second;
81 containers += ct.second.first;
87 void start_clock() { start_time = std::chrono::steady_clock::now(); }
89 void stop_clock() { stop_time = std::chrono::steady_clock::now(); }
91 std::string get_duration()
const {
93 const auto duration = stop_time - start_time;
94 const auto hrs = std::chrono::duration_cast<std::chrono::hours>(duration);
95 const auto mins = std::chrono::duration_cast<std::chrono::minutes>(duration - hrs);
96 const auto secs = std::chrono::duration_cast<std::chrono::seconds>(duration - hrs - mins);
98 std::chrono::duration_cast<std::chrono::milliseconds>(duration - hrs - mins - secs);
100 ss << hrs.count() <<
"h " << mins.count() <<
"m " << secs.count() <<
"s " << msecs.count()
101 <<
"ms " << std::endl;
106 alloc_containers.clear();
107 equiv_containers.clear();